global event handler in nagios 2.0

Dan Hopkins dan.hopkins at uk.easynet.net
Thu Jan 27 12:55:55 CET 2005


> -----Original Message-----
> From: Robert Bilbrey [mailto:rbilbrey at cymark.com]
> Sent: 26 January 2005 23:14
> To: Nagios-users at lists.sourceforge.net
> Subject: [Nagios-users] global event handler in nagios 2.0
> 
> 
> Somewhere along the way I remember someone speaking to using a global 
> event handler to be able to capture status changes and write 
> them to a 
> database for reporting. I have a client that wishes to have 
> status and 
> availability data written to MSSQL. I can handle the php code 
> to write 
> the data. Does anyone have a good starting point or an example how to 
> use the event handler that I could work  from. 
> Thanks, Bob

Bob,
First off - don't let me confuse you, I haven't used Nag2.0 yet, so my
advice comes traight from 1.2 (if anyone else replies with 2.0 specific
info, disregard me) But from a quick glance at the docs, it doesn't seem to
change in principle from 1.2 to 2.0

- in your nagios.cfg, define host and service global event handler:

global_host_event_handler=write-db-host-eventlog
global_service_event_handler=write-db-service-eventlog

- in your command.cfg (or any included config file), define your global
event handlers (here's an example for mysql, I don't know what command line
tools you'd use for MS-SQL, but I'm sure you get the idea):

define command {
        command_name        write-db-host-eventlog
        command_line        /usr/bin/printf "%b" "insert into nagiosevents
(event_time, host_name, address, service_description, status, plugin_output,
last_check, execution_time) values (from_unixtime($TIMET$), '$HOSTNAME$',
'$HOSTADDRESS$', 'HOST', '$HOSTSTATE$', '$OUTPUT$',
from_unixtime($LASTCHECK$), $EXECUTIONTIME$)" | /usr/local/bin/mysql
--host=yourdbhost --user=yourdbuser --database=yournagDB --password=pass
}

define command {
    command_name    write-db-service-eventlog
    command_line    /usr/bin/printf "%b" "insert into nagiosevents
(event_time, host_name, address, service_description, status, plugin_output,
last_check, execution_time, latency) values (from_unixtime($TIMET$),
'$HOSTNAME$', '$HOSTADDRESS$', '$SERVICEDESC$', '$SERVICESTATE$',
'$OUTPUT$', from_unixtime($LASTCHECK$), $EXECUTIONTIME$,  $LATENCY$)" |
/usr/local/bin/mysql --host=yourdbhost --user=yourdbuser
--database=yournagDB --password=pass
}

Check for the full list of available macros in the nagios docs and tune to
your own preference.

However, be warned, this only partially works in Nagios 1.2. We found, after
several weeks, that Nagios drops random results. The global event handlers
just don't fire as often as they should (I've sent log extracts to the list
before). In the end we just tail the nagios log ourselves and insert events
from there. Kludgy, but it works. Of course, this may all be fixed in 2.0
...

Good luck,
Dan


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
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