From: Ethan G. <ega...@us...> - 2005-08-02 23:58:36
|
Update of /cvsroot/nagios/nagios/module In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22275/module Modified Files: helloworld.c Log Message: Bug fixes, sample module update, beta 4 prep Index: helloworld.c =================================================================== RCS file: /cvsroot/nagios/nagios/module/helloworld.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** helloworld.c 6 Nov 2004 05:44:13 -0000 1.3 --- helloworld.c 2 Aug 2005 23:58:26 -0000 1.4 *************** *** 3,15 **** * HELLOWORLD.C - Example of a simple NEB module * ! * Copyright (c) 2003-2004 Ethan Galstad (na...@na...) * ! * Last Modified: 11-05-2004 * * Description: * * This is an example of a very basic module. It does nothing useful other ! * than printing a message when it is initialized (loaded) and closed ! * (unloaded). I would not call that useful... * * Instructions: --- 3,17 ---- * HELLOWORLD.C - Example of a simple NEB module * ! * Copyright (c) 2003-2005 Ethan Galstad (http://www.nagios.org) * ! * Last Modified: 08-02-2005 * * Description: * * This is an example of a very basic module. It does nothing useful other ! * than logging some messages to the main Nagios log file when it is initialized ! * (loaded), when it is closed (unloaded), and when aggregated status updates ! * occur. I would not call that too useful, but hopefully it will serve as a ! * very basic example of how to write a NEB module... * * Instructions: *************** *** 25,28 **** --- 27,34 ---- #include "../include/nebcallbacks.h" + /* include other event broker header files that we need for our work */ + #include "../include/nebstructs.h" + #include "../include/broker.h" + /* include some Nagios stuff as well */ #include "../include/config.h" *************** *** 33,37 **** NEB_API_VERSION(CURRENT_NEB_API_VERSION); ! void reminder_message(char *); --- 39,47 ---- NEB_API_VERSION(CURRENT_NEB_API_VERSION); ! ! void *helloworld_module_handle=NULL; ! ! void helloworld_reminder_message(char *); ! int helloworld_handle_data(int,void *); *************** *** 42,47 **** unsigned long interval; /* log module info to the Nagios log file */ ! write_to_all_logs("helloworld: Copyright (c) 2003 Ethan Galstad (na...@na...)",NSLOG_INFO_MESSAGE); /* log a message to the Nagios log file */ --- 52,60 ---- unsigned long interval; + /* save our handle */ + helloworld_module_handle=handle; + /* log module info to the Nagios log file */ ! write_to_all_logs("helloworld: Copyright (c) 2003-2005 Ethan Galstad (na...@na...)",NSLOG_INFO_MESSAGE); /* log a message to the Nagios log file */ *************** *** 53,57 **** time(¤t_time); interval=900; ! schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+interval,TRUE,interval,NULL,TRUE,reminder_message,"How about you?"); return 0; --- 66,73 ---- time(¤t_time); interval=900; ! schedule_new_event(EVENT_USER_FUNCTION,TRUE,current_time+interval,TRUE,interval,NULL,TRUE,helloworld_reminder_message,"How about you?"); ! ! /* register to be notified of certain events... */ ! neb_register_callback(NEBCALLBACK_AGGREGATED_STATUS_DATA,helloworld_module_handle,0,helloworld_handle_data); return 0; *************** *** 62,66 **** int nebmodule_deinit(int flags, int reason){ char temp_buffer[1024]; ! /* log a message to the Nagios log file */ snprintf(temp_buffer,sizeof(temp_buffer)-1,"helloworld: Goodbye world!\n"); --- 78,85 ---- int nebmodule_deinit(int flags, int reason){ char temp_buffer[1024]; ! ! /* deregister for all events we previously registered for... */ ! neb_deregister_callback(NEBCALLBACK_AGGREGATED_STATUS_DATA,helloworld_handle_data); ! /* log a message to the Nagios log file */ snprintf(temp_buffer,sizeof(temp_buffer)-1,"helloworld: Goodbye world!\n"); *************** *** 73,77 **** /* gets called every X minutes by an event in the scheduling queue */ ! void reminder_message(char *message){ char temp_buffer[1024]; --- 92,96 ---- /* gets called every X minutes by an event in the scheduling queue */ ! void helloworld_reminder_message(char *message){ char temp_buffer[1024]; *************** *** 84,85 **** --- 103,133 ---- } + + /* handle data from Nagios daemon */ + int helloworld_handle_data(int event_type, void *data){ + nebstruct_aggregated_status_data *agsdata=NULL; + char temp_buffer[1024]; + + /* what type of event/data do we have? */ + switch(event_type){ + + case NEBCALLBACK_AGGREGATED_STATUS_DATA: + + /* an aggregated status data dump just started or ended... */ + if((agsdata=(nebstruct_aggregated_status_data *)data)){ + + /* log a message to the Nagios log file */ + snprintf(temp_buffer,sizeof(temp_buffer)-1,"helloworld: An aggregated status update just %s.",(agsdata->type==NEBTYPE_AGGREGATEDSTATUS_STARTDUMP)?"started":"finished"); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_all_logs(temp_buffer,NSLOG_INFO_MESSAGE); + } + + break; + + default: + break; + } + + return 0; + } + |