Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
#! /usr/local/bin/python2
import sys
import time
argv = []
if sys.argv.__len__() < 3:
print "host,service,duration must be provided"
exit(0)
host = str(sys.argv[1])
service = str(sys.argv[2])
duration = int(sys.argv[3])
currentTime = int(time.time())
endTime = currentTime + duration
with open("/var/spool/nagios/rw/nagios.cmd", "a") as myfile:
msg = "[%s] SCHEDULE_SVC_DOWNTIME;%s;%s;%s;%s;1;0;%s;Amanda;Backup execution" % (currentTime,host,service,currentTime,endTime,duration)
print msg
myfile.write(msg)
myfile.close()
If I take the output of print msg and echo <msg> >> nagios.cmd it works fine. The command is being run as root. A nearly identical bit of Python does work properly. What am I missing?