Log to Database Event Handler

Marc Powell marc at ena.com
Wed Apr 7 22:17:50 CEST 2004


 

________________________________

From: David Barnett [mailto:DavidB at etobin.com] 
Sent: Wednesday, April 07, 2004 2:29 PM
To: nagios-users at lists.sourceforge.net
Subject: [Nagios-users] Log to Database Event Handler



Can someone please post a command that will be an event handler that
logs the date, time, host, service, state, and output to a mysql
database?  

I have tried:

/usr/bin/mysql -D <db_name> --execute 'INSERT into <table_name>
(date,time,host,service,state,output) VALUES($DATE$,$TIME$,$HOSTNAME$,
$SERVICEDESC$,$SERVICESTATE$,$OUTPUT$)'

but that doesn't work and I can't find any error log.  The Nagios event
log says the event handler happened, but nothing gets put into the
table.  Thanks for any help
--------------------------


How is your event handler defined exactly? Is the command command_line
the above command or are you following the documentation and creating an
event handler script that contains the command above? Does the nagios
user have the permissions to connect to the database without a password
to insert the data? Have you tried echoing the command to a text file
instead of trying to insert into the DB to make sure that the
information being passed is correct and in the format you're expecting?
I suspect that at the very least you're going to need to "" the $OUTPUT$
because of spaces and such and is probably the main issue.

The example event handler at
http://nagios.sourceforge.net/docs/1_0/eventhandlers.html is very
straightforward and a good starting point for your script. It would look
something like so --

define command{
	command_name	mysql-insert
	command_line
/usr/local/nagios/libexec/eventhandlers/mysql-insert $DATE$ $TIME$
$HOSTNAME$  '$SERVICEDESC$' $SERVICESTATE$ '$OUTPUT$'
}

/usr/local/nagios/libexec/eventhandlers/mysql-insert:

#!/bin/sh

/usr/bin/mysql -D <db_name> --execute 'INSERT into <table_name>
(date,time,host,service,state,output)
VALUES($DATE$,$TIME$,$HOSTNAME$,"$SERVICEDESC$",$SERVICESTATE$,"$OUTPUT$
")'

exit 0


------

You _might_ be able to get away with making the mysql line from
mysql-insert the command_line for the event handler command definition
but I'm not sure.

--
Marc


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
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