Remote TCP access to external commands - what do you think o


#1

On my Nagios server, I am running:

socat -u TCP-LISTEN:5668,fork EXEC:/usr/local/bin/process_remote_command

(socat is like netcat on steroids, a very useful thing)

process_remote_command is a basic filter that currently drops all lines not containing SCHEDULE_HOST_DOWNTIME. It expects an external command in the proper forward then prints it to the command file.

On a host, I run:
echo “$COMMAND;$HOST;$START;$END;$FIXED;$TRIGGER;$DURATION;$AUTHOR;$COMMENT” | socat -u STDIN TCP:nagiosserver:5668

What this allows me to do is add a downtime remotely. If I have a server that is set to reboot nightly via a cron, I can add commands to that cronjob script to automatically schedule downtime for that host.

Thoughts on this? Is there a better way?


#2

Here is my (very basic) process_remote_command script:

#!/bin/bash

read LINE

if echo $LINE|grep -qv SCHEDULE_HOST_DOWNTIME
then
exit
else

now=date +%s
commandfile="/usr/local/nagios/var/rw/nagios.cmd"

/usr/bin/printf “%lu] $LINE\n” $now > $commandfile

fi


#3

And a sample script to schedule downtime from the host:

#Port Nagios server socat process is listening on
PORT=5668

#Nagios external command to run
COMMAND=SCHEDULE_HOST_DOWNTIME

#DURATION in minutes
DURATION=15

#Duration in seconds
DURATION=$(( $DURATION * 60 ))

AUTHOR=cipriani
COMMENT=“Going down for reboot…get ready to rock n roll”

START="2008-08-08 04:00:0"
END=“2008-08-08 04:30:0”

#HOST=hostname -s
HOST=localhost

#Convert start and end times in seconds since epoch, in UTC local time
START=date --date="$START" +%s
END=date --date="$END" +%s

#Fixed will start and end precisely at the times given if FIXED=1. Otherwise, it starts somewhere BETWEEN start
#and end times and last for DURATION seconds. Nagios will start the timer when it sees the host go down
#and suspend notifications until the DURATION is reached
FIXED=0

#Trigger ID. Nagios will trigger this downtime if another downtime happens (Trigger ID = ID of the other downtime)
TRIGGER=0

echo “$COMMAND;$HOST;$START;$END;$FIXED;$TRIGGER;$DURATION;$AUTHOR;$COMMENT” | socat -u STDIN TCP:nagios:$PORT


#4

hehe, I really like your idea :slight_smile:
(even if I’ll never use it, because of some constraints here :().

Anyway, just a stupid question:
wouldn’t it be easier to use timeperiods in nagios ? :slight_smile:


#5

Can downtimes be scheduled via timeperiods, or are you saying just turn off notifications during a timeperiod?