Changeset 9a6060c147e3f375f75141efe7884a911021d87e

Show
Ignore:
Timestamp:
03/04/08 18:13:56 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1204654436 +0000
git-parent:

[bffc38f9be526436b3f50da8d06bb6987008a7f1]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1204654436 +0000
Message:

refactor shared code, add module dependency detection and start splitting out libs in configure

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • configure.in

    rbffc38f r9a6060c  
    7171        ] 
    7272) 
    73 AC_CHECK_LIB(pq, PQconnectdb, , 
     73 
     74SAVELIBS="$LIBS" 
     75AC_CHECK_LIB(pq, PQconnectdb, 
     76        [ 
     77                LIBS="$LIBS -lpq" 
     78                PGLIBS="$LIBS" 
     79                AC_SUBST(PGLIBS) 
     80        ], 
    7481        [ 
    7582                AC_MSG_ERROR([libpq required]) 
     
    8188        [ AC_MSG_ERROR([Cannot compile/link against libpq]) ] 
    8289) 
     90LIBS="$SAVELIBS" 
     91 
     92######## 
     93# 
     94# CHECK FOR VARIOUS MODULE CRITERIA 
     95# We don't track the libs themselves, as we'll just explictly link 
     96# against the in the makefile if we enable them to build (by adding 
     97# them to the BUILD_MODULES list). 
     98# 
     99######## 
     100 
     101# Should we build snmp checks? 
     102SAVELIBS="$LIBS" 
     103AC_CHECK_LIB(netsnmp, snmp_sess_open, 
     104        [ 
     105                BUILD_MODULES="$BUILD_MODULES snmp.$MODULEEXT" 
     106        ], 
     107        [ 
     108                AC_MSG_ERROR([No libnetsnmp, skipping snmp module]) 
     109        ] 
     110) 
     111LIBS="$SAVELIBS" 
    83112 
    84113AC_MSG_CHECKING([libxml2 cflags]) 
     
    296325fi 
    297326 
     327AC_SUBST(BUILD_MODULES) 
     328 
    298329docdir="docs" 
    299330mansubdir="man" 
  • src/Makefile.in

    ra7304b5 r9a6060c  
    66RANLIB=@RANLIB@ 
    77LIBS=@LIBS@ 
     8PGLIBS=@PGLIBS@ 
    89INSTALL=@INSTALL@ 
    910 
     
    6263                -Ljlog -ljlog \ 
    6364                -Lnoitedit -lnoitedit \ 
    64                 $(LIBS) 
     65                $(LIBS) $(PGLIBS) 
    6566 
    6667.c.o: 
  • src/modules/Makefile.in

    rc04dcf5 r9a6060c  
    1616top_srcdir=@top_srcdir@ 
    1717 
    18 MODULES=ping_icmp.@MODULEEXT@ http.@MODULEEXT@ snmp.@MODULEEXT
     18MODULES=ping_icmp.@MODULEEXT@ http.@MODULEEXT@ @BUILD_MODULES
    1919 
    2020all:    $(MODULES) 
  • src/modules/http.c

    r73bd686 r9a6060c  
    1818#include "noit_module.h" 
    1919#include "noit_check.h" 
     20#include "noit_check_tools.h" 
    2021#include "utils/noit_log.h" 
    2122#include "utils/noit_hash.h" 
     
    9899static int serf_handler(eventer_t e, int mask, void *closure, 
    99100                        struct timeval *now); 
    100 static int serf_recur_handler(eventer_t e, int mask, void *closure, 
    101                               struct timeval *now); 
    102101static void serf_log_results(noit_module_t *self, noit_check_t *check); 
    103102static void resmon_log_results(noit_module_t *self, noit_check_t *check); 
     
    745744  return 0; 
    746745} 
    747 static int serf_schedule_next(noit_module_t *self, 
    748                               struct timeval *last_check, noit_check_t *check, 
    749                               struct timeval *now) { 
    750   eventer_t newe; 
    751   struct timeval period, earliest; 
    752   serf_closure_t *ccl; 
    753  
    754   if(check->period == 0) return 0; 
    755  
    756   /* If we have an event, we know when we intended it to fire.  This means 
    757    * we should schedule that point + period. 
    758    */ 
    759   if(now) 
    760     memcpy(&earliest, now, sizeof(earliest)); 
    761   else 
    762     gettimeofday(&earliest, NULL); 
    763   period.tv_sec = check->period / 1000; 
    764   period.tv_usec = (check->period % 1000) * 1000; 
    765  
    766   newe = eventer_alloc(); 
    767   memcpy(&newe->whence, last_check, sizeof(*last_check)); 
    768   add_timeval(newe->whence, period, &newe->whence); 
    769   if(compare_timeval(newe->whence, earliest) < 0) 
    770     memcpy(&newe->whence, &earliest, sizeof(earliest)); 
    771   newe->mask = EVENTER_TIMER; 
    772   newe->callback = serf_recur_handler; 
    773   ccl = calloc(1, sizeof(*ccl)); 
    774   ccl->self = self; 
    775   ccl->check = check; 
    776   newe->closure = ccl; 
    777  
    778   eventer_add(newe); 
    779   check->fire_event = newe; 
    780   return 0; 
    781 } 
    782 static int serf_recur_handler(eventer_t e, int mask, void *closure, 
    783                               struct timeval *now) { 
    784   serf_closure_t *cl = (serf_closure_t *)closure; 
    785   serf_schedule_next(cl->self, &e->whence, cl->check, now); 
    786   serf_initiate(cl->self, cl->check); 
    787   free(cl); 
    788   return 0; 
    789 } 
    790746static void serf_cleanup(noit_module_t *self, noit_check_t *check) { 
    791747  serf_check_info_t *sci; 
     
    813769    struct timeval epoch = { 0L, 0L }; 
    814770    noit_check_fake_last_check(check, &epoch, NULL); 
    815     serf_schedule_next(self, &epoch, check, NULL); 
     771    noit_check_schedule_next(self, &epoch, check, NULL, serf_initiate); 
    816772  } 
    817773  return 0; 
     
    828784    struct timeval epoch = { 0L, 0L }; 
    829785    noit_check_fake_last_check(check, &epoch, NULL); 
    830     serf_schedule_next(self, &epoch, check, NULL); 
     786    noit_check_schedule_next(self, &epoch, check, NULL, serf_initiate); 
    831787  } 
    832788  return 0; 
     
    892848  } 
    893849  if(!check->fire_event) 
    894     serf_schedule_next(self, NULL, check, NULL); 
     850    noit_check_schedule_next(self, NULL, check, NULL, serf_initiate); 
    895851  return 0; 
    896852} 
     
    909865  eventer_name_callback("http/serf_handler", serf_handler); 
    910866  eventer_name_callback("http/serf_complete", serf_complete); 
    911   eventer_name_callback("http/serf_recur_handler", serf_recur_handler); 
    912867  return 0; 
    913868} 
  • src/modules/ping_icmp.c

    r7b92762 r9a6060c  
    2222#include "noit_module.h" 
    2323#include "noit_check.h" 
     24#include "noit_check_tools.h" 
    2425#include "utils/noit_log.h" 
    2526 
     
    5051static noit_log_stream_t nlerr = NULL; 
    5152static noit_log_stream_t nldeb = NULL; 
    52 static int ping_icmp_recur_handler(eventer_t e, int mask, void *closure, 
    53                                    struct timeval *now); 
    5453static int in_cksum(u_short *addr, int len); 
    5554 
     
    442441  return 0; 
    443442} 
    444 static int ping_icmp_schedule_next(noit_module_t *self, 
    445                                    struct timeval *last_check, 
    446                                    noit_check_t *check, 
    447                                    struct timeval *now) { 
    448   eventer_t newe; 
    449   struct timeval period, earliest; 
    450   struct ping_closure *pcl; 
    451  
    452   if(check->period == 0) return 0; 
    453   if(NOIT_CHECK_DISABLED(check) || NOIT_CHECK_KILLED(check)) return 0; 
    454  
    455   /* If we have an event, we know when we intended it to fire.  This means 
    456    * we should schedule that point + period. 
    457    */ 
    458   if(now) 
    459     memcpy(&earliest, now, sizeof(earliest)); 
    460   else 
    461     gettimeofday(&earliest, NULL); 
    462   period.tv_sec = check->period / 1000; 
    463   period.tv_usec = (check->period % 1000) * 1000; 
    464  
    465   newe = eventer_alloc(); 
    466   memcpy(&newe->whence, last_check, sizeof(*last_check)); 
    467   add_timeval(newe->whence, period, &newe->whence); 
    468   if(compare_timeval(newe->whence, earliest) < 0) 
    469     memcpy(&newe->whence, &earliest, sizeof(earliest)); 
    470   newe->mask = EVENTER_TIMER; 
    471   newe->callback = ping_icmp_recur_handler; 
    472   pcl = calloc(1, sizeof(*pcl)); 
    473   pcl->self = self; 
    474   pcl->check = check; 
    475   newe->closure = pcl; 
    476  
    477   eventer_add(newe); 
    478   check->fire_event = newe; 
    479   return 0; 
    480 } 
    481 static int ping_icmp_recur_handler(eventer_t e, int mask, void *closure, 
    482                                    struct timeval *now) { 
    483   struct ping_closure *cl = (struct ping_closure *)closure; 
    484   cl->check->fire_event = NULL; 
    485   ping_icmp_schedule_next(cl->self, &e->whence, cl->check, now); 
    486   ping_icmp_send(cl->self, cl->check); 
    487   free(cl); 
    488   return 0; 
    489 } 
    490443static int ping_icmp_initiate_check(noit_module_t *self, noit_check_t *check, 
    491444                                    int once, noit_check_t *cause) { 
     
    498451    struct timeval epoch; 
    499452    noit_check_fake_last_check(check, &epoch, NULL); 
    500     ping_icmp_schedule_next(self, &epoch, check, NULL); 
     453    noit_check_schedule_next(self, &epoch, check, NULL, ping_icmp_send); 
    501454  } 
    502455  return 0; 
     
    549502  if(!nlerr) nlerr = noit_stderr; 
    550503  if(!nldeb) nldeb = noit_debug; 
    551   eventer_name_callback("ping_icmp/recur_handler", ping_icmp_recur_handler); 
    552504  eventer_name_callback("ping_icmp/timeout", ping_icmp_timeout); 
    553505  eventer_name_callback("ping_icmp/handler", ping_icmp_handler); 
  • src/modules/snmp.c

    r4368e68 r9a6060c  
    7575                   NULL, NULL); 
    7676} 
    77  
    78 static int noit_snmp_recur_handler(eventer_t e, int mask, void *closure, 
    79                                    struct timeval *now); 
    8077 
    8178static int noit_snmp_init(noit_module_t *self) { 
     
    449446} 
    450447 
    451 static int noit_snmp_schedule_next(noit_module_t *self, 
    452                                    struct timeval *last_check, 
    453                                    noit_check_t *check, 
    454                                    struct timeval *now) { 
    455   eventer_t newe; 
    456   struct timeval period, earliest; 
    457   struct snmp_check_closure *scc; 
    458  
    459   if(check->period == 0) return 0; 
    460   if(NOIT_CHECK_DISABLED(check) || NOIT_CHECK_KILLED(check)) return 0; 
    461  
    462   /* If we have an event, we know when we intended it to fire.  This means 
    463    * we should schedule that point + period. 
    464    */ 
    465   if(now) 
    466     memcpy(&earliest, now, sizeof(earliest)); 
    467   else 
    468     gettimeofday(&earliest, NULL); 
    469   period.tv_sec = check->period / 1000; 
    470   period.tv_usec = (check->period % 1000) * 1000; 
    471  
    472   newe = eventer_alloc(); 
    473   memcpy(&newe->whence, last_check, sizeof(*last_check)); 
    474   add_timeval(newe->whence, period, &newe->whence); 
    475   if(compare_timeval(newe->whence, earliest) < 0) 
    476     memcpy(&newe->whence, &earliest, sizeof(earliest)); 
    477   newe->mask = EVENTER_TIMER; 
    478   newe->callback = noit_snmp_recur_handler; 
    479   scc = calloc(1, sizeof(*scc)); 
    480   scc->self = self; 
    481   scc->check = check; 
    482   newe->closure = scc; 
    483  
    484   eventer_add(newe); 
    485   check->fire_event = newe; 
    486   return 0; 
    487 } 
    488  
    489 static int noit_snmp_recur_handler(eventer_t e, int mask, void *closure, 
    490                                    struct timeval *now) { 
    491   struct snmp_check_closure *cl = closure; 
    492   cl->check->fire_event = NULL; 
    493   noit_snmp_schedule_next(cl->self, &e->whence, cl->check, now); 
    494   noit_snmp_send(cl->self, cl->check); 
    495   free(cl); 
    496   return 0; 
    497 } 
    498  
    499448static int noit_snmp_initiate_check(noit_module_t *self, noit_check_t *check, 
    500449                                    int once, noit_check_t *cause) { 
     
    507456    struct timeval epoch; 
    508457    noit_check_fake_last_check(check, &epoch, NULL); 
    509     noit_snmp_schedule_next(self, &epoch, check, NULL); 
     458    noit_check_schedule_next(self, &epoch, check, NULL, noit_snmp_send); 
    510459  } 
    511460  return 0; 
     
    520469  if(!nlerr) nlerr = noit_stderr; 
    521470  if(!nldeb) nldeb = noit_debug; 
    522   eventer_name_callback("noit_snmp/recur_handler", noit_snmp_recur_handler); 
    523471  eventer_name_callback("noit_snmp/check_timeout", noit_snmp_check_timeout); 
    524472  eventer_name_callback("noit_snmp/session_timeout", noit_snmp_session_timeout); 
  • src/noit_check_tools.c

    rce72dc2 r9a6060c  
    66#include "noit_defines.h" 
    77#include "noit_check_tools.h" 
     8 
     9#include <assert.h> 
     10 
     11typedef struct { 
     12  noit_module_t *self; 
     13  noit_check_t *check; 
     14  dispatch_func_t dispatch; 
     15} recur_closure_t; 
    816 
    917int 
     
    5563} 
    5664 
     65static int 
     66noit_check_recur_handler(eventer_t e, int mask, void *closure, 
     67                              struct timeval *now) { 
     68  recur_closure_t *rcl = closure; 
     69  rcl->check->fire_event = NULL; /* This is us, we get free post-return */ 
     70  noit_check_schedule_next(rcl->self, &e->whence, rcl->check, now, 
     71                           rcl->dispatch); 
     72  rcl->dispatch(rcl->self, rcl->check); 
     73  free(rcl); 
     74  return 0; 
     75} 
     76 
     77int 
     78noit_check_schedule_next(noit_module_t *self, 
     79                         struct timeval *last_check, noit_check_t *check, 
     80                         struct timeval *now, dispatch_func_t dispatch) { 
     81  eventer_t newe; 
     82  struct timeval period, earliest; 
     83  recur_closure_t *rcl; 
     84 
     85  assert(check->fire_event == NULL); 
     86  if(check->period == 0) return 0; 
     87  if(NOIT_CHECK_DISABLED(check) || NOIT_CHECK_KILLED(check)) return 0; 
     88 
     89  /* If we have an event, we know when we intended it to fire.  This means 
     90   * we should schedule that point + period. 
     91   */ 
     92  if(now) 
     93    memcpy(&earliest, now, sizeof(earliest)); 
     94  else 
     95    gettimeofday(&earliest, NULL); 
     96  period.tv_sec = check->period / 1000; 
     97  period.tv_usec = (check->period % 1000) * 1000; 
     98 
     99  newe = eventer_alloc(); 
     100  memcpy(&newe->whence, last_check, sizeof(*last_check)); 
     101  add_timeval(newe->whence, period, &newe->whence); 
     102  if(compare_timeval(newe->whence, earliest) < 0) 
     103    memcpy(&newe->whence, &earliest, sizeof(earliest)); 
     104  newe->mask = EVENTER_TIMER; 
     105  newe->callback = noit_check_recur_handler; 
     106  rcl = calloc(1, sizeof(*rcl)); 
     107  rcl->self = self; 
     108  rcl->check = check; 
     109  rcl->dispatch = dispatch; 
     110  newe->closure = rcl; 
     111 
     112  eventer_add(newe); 
     113  check->fire_event = newe; 
     114  return 0; 
     115} 
     116 
  • src/noit_check_tools.h

    rce72dc2 r9a6060c  
    88 
    99#include "noit_defines.h" 
     10#include "eventer/eventer.h" 
     11#include "noit_module.h" 
     12#include "noit_check.h" 
    1013#include "utils/noit_hash.h" 
     14 
     15typedef int (*dispatch_func_t)(noit_module_t *, noit_check_t *); 
    1116 
    1217API_EXPORT(int) 
     
    1520                         noit_hash_table *config); 
    1621 
     22API_EXPORT(int) 
     23  noit_check_schedule_next(noit_module_t *self, 
     24                           struct timeval *last_check, noit_check_t *check, 
     25                           struct timeval *now, dispatch_func_t recur); 
     26 
    1727#endif 
    1828