Logs in MS SQL

Jack Doyle jdoyle at lewisgaleclinic.com
Mon Jul 12 18:49:35 CEST 2004


Happy to explain...
 
What I mean is I would like to have log information stored in a MS SQL
2000 server.  I've tried eventhandlers, but the script I wrote for some
reason will not run wget.  Here's why I'm running wget...
 
Since I didn't know a better way to get data from Nagios to MS SQL, I
created a web page on my SQL server.  It's just like a form processing
page on a website, except there's no form.  The data submitted to that
page goes into a database that I created to keep nagios info.
 
My event handler, sql_AddRecord, gets the Nagios Macros passed to it.
I'm using it as a global event handler for services and hosts.  It looks
like this:
 
-----
#!/bin/sh

#

# Write Record to SQL server.

#

recordtype=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$1")
timet=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$2")
hostname=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$3")
hostalias=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$4")
hostaddress=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$5")
hoststate=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$6")
statetype=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$7")
attempt=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$8")
plugout=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "$9")
executiontime=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "${10}")
latency=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "${11}")
lastcheck=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "${12}")
laststatechange=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl
"${13}")

# Remove file created last time

rm -rfv /usr/lib/nagios/plugins/eventhandlers/addrecord.asp

# What type of record are we creating?

case "$1" in

HOST)

#echo timet $timet hostname $hostname hostalias $hostalias hostaddress
$hostaddress hoststate $hoststate statetype $statetype attempt $attempt
plugout $plugout executiontime $executiontime latency $latency lastcheck
$lastcheck laststatechange $laststatechange | mail
jdoyle at lewisgaleclinic.com

wget --background --no-clobber --append-output=/tmp/wget.log
--post-data="timet=$timet&recordtype=$recordtype&hostname=$hostname&host
alias=$hostalias&hostaddress=$hostaddress&hoststate=$hoststate&statetype
=$statetype&attempt=$attempt&plugout=$plugout&executiontime=$executionti
me&latency=$latency&lastcheck=$lastcheck&laststatechange=$laststatechang
e" http://sql/nagios/addrecord.asp <http://sql/nagios/addrecord.asp> 

;;

SERVICE)

servicedesc=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "${14}")
servicestate=$(/usr/lib/nagios/plugins/eventhandlers/encode.pl "${15}")

#echo timet $timet hostname $hostname hostalias $hostalias hostaddress
$hostaddress hoststate $hoststate statetype $statetype attempt $attempt
plugout $plugout executiontime $executiontime latency $latency lastcheck
$lastcheck laststatechange $laststatechange servicedesc $servicedesc
servicestate $servicestate | mail jdoyle at lewisgaleclinic.com

wget --background --no-clobber --append-output=/tmp/wget.log
--post-data="timet=$timet&recordtype=$recordtype&hostname=$hostname&host
alias=$hostalias&hostaddress=$hostaddress&hoststate=$hoststate&statetype
=$statetype&attempt=$attempt&plugout=$plugout&executiontime=$executionti
me&latency=$latency&lastcheck=$lastcheck&laststatechange=$laststatechang
e&servicedesc=$servicedesc&servicestate=$servicestate"
http://sql/nagios/addrecord.asp <http://sql/nagios/addrecord.asp> 

;;

esac

exit 0

-----
 
 
encode.pl is a file that will take the string and return a url-encoded
version of the string.  That way it will post properly to my page.
 
Here are my command definitions for my global event handlers:
 
-----
 
define command{
        command_name    log_host_change
        command_line
/usr/lib/nagios/plugins/eventhandlers/sql_AddRecord "HOST" "$TIMET$"
"$HOSTNAME$" "$HOSTALIAS$" "$HOSTADDRESS$" "$HOSTSTATE$" "$STATETYPE$"
"$HOSTATTEMPT$" "$OUTPUT$" "$EXECUTIONTIME$" "$LATENCY$" "$LASTCHECK$"
"$LASTSTATECHANGE$"
        }
 
define command{
        command_name    log_service_change
        command_line
/usr/lib/nagios/plugins/eventhandlers/sql_AddRecord "SERVICE" "$TIMET$"
"$HOSTNAME$" "$HOSTALIAS$" "$HOSTADDRESS$" "$HOSTSTATE$" "$STATETYPE$"
"$SERVICEATTEMPT$" "$OUTPUT$" "$EXECUTIONTIME$" "$LATENCY$"
"$LASTCHECK$" "$LASTSTATECHANGE$" "$SERVICEDESC$" "$SERVICESTATE$"

-----
 
In the main script, you can see where I have commented a line that I
used for testing.  It tested fine, it echoed all of the url-encoded
macros and piped them to my email.
 
If, after the wget line, I add "| mail jdoyle at lewisgaleclinic.com" I get
a blank email when the event handler runs.  wget just doesn't seem to
work.
 
If I run the main script from the command line with some made up data to
fill the variables, it works fine, and adds the data to the sql server.
 
I'm so close, but can't figure out why wget does nothing when run from
the eventhandler.
 
Jack Doyle, LGC Information Systems 	
Systems Operations Specialist 	
540.776.2025 	
 
 
 
 
 
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20040712/b0f45df7/attachment.html>


More information about the Users mailing list