Hi All,
Is there any simpler way to receive SNMP Traps by Nagios server
and create and alert/event? Please provide the steps(exact) as I am new
to Nagios.
Thanks in Advance,
Pankaj
________________________________
From: Pankaj Dhali (WT01 - INNOVATION GROUP)
Sent: Tuesday, September 25, 2007 8:09 PM
To: 'nagios-users@lists.sourceforge.net'
Subject: FW: Nagios: Error while writing to pipe
Hi All,
I am new to Nagios, I am trying to receive SNMP Trap from
Windows client machine. I am using Python script to see how Nagios can
create an event/alert
by checking Passive Service Check Result submitted by this script.
I have attached the Python script which is used write "Passive
Service check Result" to Nagios external command file
for creating an alert/event. But when I run this script
--------------------------------------------------
[EMAIL PROTECTED] eventhandlers]# pwd
/usr/local/nagios/libexec/eventhandlers
[EMAIL PROTECTED] eventhandlers]# python snmptraphandling.py 10.207.40.203
CRITICAL 12
2
[EMAIL PROTECTED] eventhandlers]#
---------------------------------------------
I get following error:
[EMAIL PROTECTED] rw]# tail -f nagios.cmd
[1190731734]
PROCESS_SERVICE_CHECK_RESULT;10.207.40.203;snmp_trap_handling_critical;2
;" 12"
tail: nagios.cmd: file truncated
tail: nagios.cmd: cannot seek to offset 0: Illegal seek
[EMAIL PROTECTED] rw]#
--------------------------------------------------
nagios.cmd is a pipe:
[EMAIL PROTECTED] rw]# ls -l
total 0
prw-rw---- 1 nagios nagcmd 0 Sep 25 20:18 nagios.cmd
[EMAIL PROTECTED] rw]#
[EMAIL PROTECTED] rw]# pwd
/usr/local/nagios/var/rw
why I am getting Illegal seek error. I have tried to use this script to
a normal read write file and it works fine, but while writing to a pipe
it is
showing error. If the problem is due to the script then it could be here
output = open('/usr/local/nagios/var/rw/nagios.cmd', 'w')
print return_code
results = "[" + mytime + "] " + "PROCESS_SERVICE_CHECK_RESULT;"
\
+ host + ";" + "snmp_trap_handling_" + service_suffix + ";" \
+ return_code + ";" + mondata_res + "\n"
output.write(results)
It could be file(pipe) permission problem, I have no idea.
I have followed below link to give permission to nagios.cmd
http://nagios.sourceforge.net/docs/2_0/commandfile.html
Thanks & Regards,
Pankaj
#Listing 1 snmptraphandling.py
#!/usr/bin/python -u
"""
Written by Francois Meehan (Cedval Info) First release 2004/09/15
This script receives input from sec.pl concerning translated snmptraps
*** Important note: sec must send DATA within quotes
Ex: ./services.py $1 $2 $3
"""
import commands, string, os, sys, time
global return_code
def check_arg():
try:
host = sys.argv[1]
except:
print "usage: services.py <HOST> <SEVERITY> <DATA>"
sys.exit()
try:
severity = sys.argv[2]
except:
print "usage: services.py <HOST> <SEVERITY> <DATA>"
sys.exit()
try:
mondata_res = sys.argv[3]
except:
print "usage: services.py <HOST> <SEVERITY> <DATA>"
sys.exit()
return (host, severity, mondata_res) def post_results(host,
mondata_res, return_code, service_suffix):
mytime = time.time()
mytime = str(mytime)
mytime = mytime[:-3]
mondata_res = '" ' + mondata_res + '" '
#print mondata_res
#output = open('/var/nagios/rw/nagios.cmd', 'w')
output = open('/usr/local/nagios/var/rw/nagios.cmd', 'w')
print return_code
results = "[" + mytime + "] " + "PROCESS_SERVICE_CHECK_RESULT;" \
+ host + ";" + "snmp_trap_handling_" + service_suffix + ";" \
+ return_code + ";" + mondata_res + "\n"
output.write(results)
def get_return_code():
if severity == "INFORMATIONAL":
return_code = "0"
service_suffix = "ok"
elif severity == "Normal":
return_code = "0"
service_suffix = "ok"
elif severity == "SEVERE":
return_code = "2"
service_suffix = "critical"
elif severity == "MAJOR":
return_code = "2"
service_suffix = "critical"
elif severity == "CRITICAL":
return_code = "2"
service_suffix = "critical"
elif severity == "WARNING":
return_code = "1"
service_suffix = "warning"
elif severity == "MINOR":
return_code = "1"
service_suffix = "warning"
return return_code, service_suffix
#Validating parameters
# Main routine...
if __name__ == '__main__':
(host, severity, mondata_res) = check_arg()
return_code, service_suffix = get_return_code()
post_results(host, mondata_res, return_code, service_suffix)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Nagios-users mailing list
Nagios-users@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