AW: NEB Changing Message Text

Mohr James james.mohr at elaxy.com
Mon Oct 24 16:16:46 CEST 2005


Sorry, but your answer does not appear to answer the question, at least not as far as I can tell. Forgive me if I am interpreting your answer wrong, but what I see is that you are simply telling me to compare my code to the helloworld.c example. Since the helloworld.c example is extremely simple and it does not appear to mention anything about why the message would be processed three times. In fact, as far as I can tell, the helloworld.c example does not mention the fact that (per Andreas Ericsson) "All results of all checks are passed through the modules. Once before the plugin is executed and once after." Am I missing something? It this fact in the helloworld.c code and I am missing it.

There is a single callback function registered for NEBCALLBACK_SERVICE_STATUS_DATA ("EVENT: 20"). Based on what Andreas said, the message *should* only be processed twice. So why is it getting processed three times. Sorry, but I cannot see where the helloworld.c example leads me any further.

Regards,

Jim Mohr

/*****************************************************************************
 *
 * elaxy_logger.c -
 *
 * Based on 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:
 *
 * Compile with the following command:
 *
 *     gcc -shared -o elaxy_logger.o elaxy_logger.c
 *
 *****************************************************************************/

/* include (minimum required) event broker header files */
#define NSCORE
#include "../include/nebmodules.h"
#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"
#include "../include/common.h"
#include "../include/nagios.h"
#include "../include/objects.h"


/* specify event broker API version (required) */
NEB_API_VERSION(CURRENT_NEB_API_VERSION);


void *elaxy_logger_module_handle=NULL;

void elaxy_logger_reminder_message(char *);
int elaxy_logger_handle_data(int,void *);
int elaxy_logger_handle_status(int,void *);

/* this function gets called when the module is loaded by the event broker */
int nebmodule_init(int flags, char *args, nebmodule *handle){
        char temp_buffer[1024];
        time_t current_time;
        unsigned long interval;

        /* save our handle */
        elaxy_logger_module_handle=handle;

        /* log module info to the Nagios log file */
        write_to_all_logs("elaxy_logger: Copyright (c) 2003-2005 Elaxy GmbH",NSLOG_INFO_MESSAGE);

        /* log a message to the Nagios log file */
        snprintf(temp_buffer,sizeof(temp_buffer)-1,"elaxy_logger: Hello world!\n");
        temp_buffer[sizeof(temp_buffer)-1]='\x0';
        write_to_all_logs(temp_buffer,NSLOG_INFO_MESSAGE);

        /* register to be notified of certain events... */
        neb_register_callback(NEBCALLBACK_SERVICE_STATUS_DATA,elaxy_logger_module_handle,0,elaxy_logger_handle_status);

        return 0;
        }

        }


/* this function gets called when the module is unloaded by the event broker */
int nebmodule_deinit(int flags, int reason){
        char temp_buffer[1024];

        /* deregister for all events we previously registered for... */
        neb_deregister_callback(NEBCALLBACK_SERVICE_STATUS_DATA,elaxy_logger_handle_status);

        /* log a message to the Nagios log file */
        snprintf(temp_buffer,sizeof(temp_buffer)-1,"elaxy_logger: Goodbye world!\n");
        temp_buffer[sizeof(temp_buffer)-1]='\x0';
        write_to_all_logs(temp_buffer,NSLOG_INFO_MESSAGE);

        return 0;
        }


/* gets called every X minutes by an event in the scheduling queue */
void elaxy_logger_reminder_message(char *message){
        char temp_buffer[1024];

        /* log a message to the Nagios log file */
        snprintf(temp_buffer,sizeof(temp_buffer)-1,"elaxy_logger: I'm still here! %s",message);
        temp_buffer[sizeof(temp_buffer)-1]='\x0';
        write_to_all_logs(temp_buffer,NSLOG_INFO_MESSAGE);

        return;
        }

int elaxy_logger_handle_status(int event_type, void *data){
char temp_buffer[1024];
service * tmp_service;

nebstruct_service_status_data * service_status_data;

if( (service_status_data=(nebstruct_service_status_data *)data) ){
  tmp_service = (service *) service_status_data->object_ptr;

snprintf(temp_buffer,sizeof(temp_buffer)-1,"EVENT: %d MESSAGE: %s",event_type,tmp_service->plugin_output);
}
write_to_all_logs(temp_buffer,NSLOG_INFO_MESSAGE);
/* write_to_all_logs("inside: elaxy_logger_handle_status",NSLOG_INFO_MESSAGE); */
sprintf(temp_buffer,"CHANGED MESSAGE: %s",tmp_service->plugin_output); */
strcpy(tmp_service->plugin_output,temp_buffer); */

}

>> -----Ursprüngliche Nachricht-----
>> Von: Hendrik Baecker [mailto:b00mer at gmx.net] 
>> Gesendet: Montag, 24. Oktober 2005 15:32
>> An: Mohr James
>> Cc: Nagios-users at lists.sourceforge.net
>> Betreff: Re: [Nagios-users] NEB Changing Message Text
>> 
>> Hi James,
>> 
>> you have to check what kind of event type your neb is 
>> getting by the nagios core.
>> 
>> See broker.h for more details and get some ideas out of 
>> Ethan's "helloworld.c" line 120.
>> 
>> Mohr James schrieb:
>> 
>> >Hi All!
>> >
>> >One of my goals in using the NEB is to change the message 
>> text. In my 
>> >tests I simply do it like this:
>> >
>> >sprintf(temp_buffer,"CHANGED MESSAGE: 
>> %s",tmp_service->plugin_output); 
>> >strcpy(tmp_service->plugin_output,temp_buffer);
>> >
>> >This works, but each message is acutally getting processed 
>> three times, 
>> >so I end up with a message that looks like this:
>> >
>> >CHANGED MESSAGE: CHANGED MESSAGE: CHANGED MESSAGE: HTTP ok: 
>> HTTP/1.1 
>> >200 OK - 2.322 second response time
>> >
>> >If I start the check manually ("Re-schedule the next check of this
>> >service") it looks like this: 
>> >
>> >CHANGED MESSAGE: CHANGED MESSAGE: HTTP ok: HTTP/1.1 200 OK - 2.322 
>> >second response time
>> >
>> >After a while it seems that I get the "CHANGED MESSAGE:" 
>> three times, 
>> >then back again. However, I am not 100% sure what is going on.
>> >Somethings the text is there three times, sometimes twice.
>> >
>> >I have a single callback function for 
>> NEBCALLBACK_SERVICE_STATUS_DATA 
>> >events. In the nagios.log, I only see two entries:
>> >
>> >[1130552871] EVENT: 20 MESSAGE: HTTP ok: HTTP/1.1 200 OK -   0.301
>> >second response time
>> >[1130552871] EVENT: 20 MESSAGE: CHANGED MESSAGE: HTTP ok: 
>> HTTP/1.1 200
>> >OK -   0.301 second response time
>> >
>> >Regards,
>> >
>> >Jim Mohr
>> >
>> >
>> >-------------------------------------------------------
>> >This SF.Net email is sponsored by the JBoss Inc.
>> >Get Certified Today * Register for a JBoss Training Course Free 
>> >Certification Exam for All Training Attendees Through End 
>> of 2005 Visit 
>> >http://www.jboss.com/services/certification for more information 
>> >_______________________________________________
>> >Nagios-users mailing list
>> >Nagios-users at lists.sourceforge.net
>> >https://lists.sourceforge.net/lists/listinfo/nagios-users
>> >::: Please include Nagios version, plugin version (-v) and 
>> OS when reporting any issue. 
>> >::: Messages without supporting info will risk being sent 
>> to /dev/null
>> >
>> >
>> >  
>> >
>> 
>> 


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list