Page 1 of 1

external command update is failing

Posted: Fri Feb 03, 2017 12:28 pm
by kendallchenoweth
I have the following code which should put all of a host's services in downtime, but I'm getting an error. Can you please help?

Code: Select all

#! /usr/local/bin/python2.7
import time

host = "myhost.mathworks.com"
CommandFile = "/usr/local/nagios/var/rw/nagios.cmd"

with open(CommandFile,"a") as nagiosCmd:
	now = int(time.time())
	later = now + 7200
	commandString = "[" + str(now) + "] SCHEDULE_HOST_SVC_DOWNTIME;" + host + ";" + str(now) + ";" + str(later) + ";1;0;
0;nagiosadmin;Host being retired\n"
	print (commandString)
	nagiosCmd.write(commandString)
This produces an error in nagios.log when it runs.

[1486142396] Error: External command failed -> SCHEDULE_HOST_SVC_DOWNTIME;myhost.mathworks.com;1486142396;1486149596;1;0;0;nagiosadmin;Host being retired
[1486142396] External command error: Command failed

Re: external command update is failing

Posted: Fri Feb 03, 2017 2:11 pm
by mcapra
Which version of Nagios XI are you using? I can't reproduce this with 5.4.1. All my services go into downtime correctly according to nagios.log:

Code: Select all

[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;Swap Usage;STARTED; Service has entered a period of scheduled downtime
[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;SSH;STARTED; Service has entered a period of scheduled downtime
[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;SNMP Traps;STARTED; Service has entered a period of scheduled downtime
[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;Ping;STARTED; Service has entered a period of scheduled downtime
[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;Memory Usage;STARTED; Service has entered a period of scheduled downtime
[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;CPU Usage;STARTED; Service has entered a period of scheduled downtime
[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;Apache;STARTED; Service has entered a period of scheduled downtime
[1486148992] SERVICE DOWNTIME ALERT: 192.168.67.105;/ Disk Usage;STARTED; Service has entered a period of scheduled downtime
Can you also share the output of:

Code: Select all

ls -al /usr/local/nagios/var/rw/

Re: external command update is failing

Posted: Fri Feb 03, 2017 3:09 pm
by kendallchenoweth
$ ls -al /usr/local/nagios/var/rw
total 8
drwxrwsr-x 2 nagios nagcmd 4096 Jan 31 16:41 .
drwxrwxr-x 7 nagios nagios 4096 Feb 3 15:08 ..
prw-rw---- 1 nagios nagcmd 0 Feb 3 12:19 nagios.cmd
srw-rw---- 1 nagios nagcmd 0 Jan 31 16:41 nagios.qh

Nagios XI 2014R2.0

Re: external command update is failing

Posted: Mon Feb 06, 2017 11:34 am
by mcapra
Hmm, i'm also unable to replicate this on my 2014r2.0 machine. Are you certain the host with the name "myhost.mathworks.com" exists on this system, or are you using this script generically with different hosts passed as arguments? Can you tell me how you're running this command? I copied your script and ran it as the root user like so:

Code: Select all

python script.py
Can you PM me a system profile? From the Nagios XI GUI, you can gather a profile via Admin -> System Profile -> Download Profile.