Nagios Module for Scheduled Downtime

449 views
Skip to first unread message

Robert Parker

unread,
Jul 28, 2014, 10:56:08 AM7/28/14
to salt-...@googlegroups.com
So far as I can tell the salt Nagios module only allows passive polling of monitoring data from local plugins.  I'm interested in functionality similar to what Ansible offers for Nagios, namely a way to put certain minions in scheduled downtime or silence alerts by interacting with the Nagios server itself:


I'd like something on the order of this to disable monitoring of all services on a host :

salt 'minion1' nagios.downtime minutes=60 service=*

And this one would disable all alerts for httpd and nfs until changed:

salt 'minion1' nagios.disable_alerts service=httpd,nfs

There would need to be a pillar or grain to config where the Nagios server is.  I'd prefer it not need a third party REST API plus cached credentials/keys on the Nagios server but rather use a minion installed on the Nagios server to run these commands locally on the Nagios master to achieve same.  A state version would need to be available as well.

Do we have anything like that in development yet?

Robert

Dan Garthwaite

unread,
Jul 29, 2014, 9:53:01 AM7/29/14
to salt-...@googlegroups.com
AFAIK, this would have to be implemented via nagios external commands ON THE MINION running nagios.


Here is the doc's example:

#!/bin/sh
# This is a sample shell script showing how you can submit the SCHEDULE_HOST_DOWNTIME command
# to Nagios.  Adjust variables to fit your environment as necessary.

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

/bin/printf "[%lu] SCHEDULE_HOST_DOWNTIME;host1;1110741500;1110748700;0;0;7200;Some One;Some Downtime Comment\n" $now > $commandfile


Description: Schedules downtime for a specified host. If the "fixed" argument is set to one (1), downtime will start and end at the times specified by the "start" and "end" arguments. Otherwise, downtime will begin between the "start" and "end" times and last for "duration" seconds. The "start" and "end" arguments are specified in time_t format (seconds since the UNIX epoch). The specified host downtime can be triggered by another downtime entry if the "trigger_id" is set to the ID of another scheduled downtime entry. Set the "trigger_id" argument to zero (0) if the downtime for the specified host should not be triggered by another downtime entryf

sale events would be a great way to generalize triggering this - but events can only be responded to by the master.  So a reaction sls file needs to be set up to respond to each type of action (sched downtime, cancel downtime) that file.appends [maybe?] text to /usr/local/nagios/var/rw/nagios.cmd on the nagios/icinga server.  Assuming you have external_commands enabled in nagios.

An interesting project.  Keep us posted.

Robert Parker

unread,
Jul 29, 2014, 10:32:25 AM7/29/14
to salt-...@googlegroups.com
Here's a python script that appears to do the same thing:


#!/usr/bin/python
 
from time import time
 
# Nagios command file
command_file
="/var/nagios/rw/nagios.cmd"
 
# Time details in Unix format
now
=int(time())
start_time
=int(time()+1500)
end_time
=int(time()+2700)
 
# Open the command file in write mode
fo
= open(command_file, 'w')
 
# Nagios command for scheduling downtime
# SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
cmd
='SCHEDULE_HOST_DOWNTIME'
str_args
='servername;%s;%s;1;0;1200;nagiosadmin;Schdeuled Downtime' % ( start_time, end_time)
 
try:
 
print >> fo, "[%lu] %s;%s" % ( now, cmd, str_args)
except:
 
raise
 
# Close the file handle
fo
.close()

Unfortunately it seems that this needs to run on the minion running the Nagios server service itself.  I need a way to target a minion that is not a nagios server but rather a client that is being monitored by nagios and place it it downtime.  Is it possible to push downtime from the client side in nagios?

Dan Garthwaite

unread,
Jul 29, 2014, 10:50:27 AM7/29/14
to salt-...@googlegroups.com
Right.  That is why I recommended the Reactor system.  You can fire an event from any minion, capture that event on the master, and the master can run a script on the nagios server.


--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/eqRtO8Mse7A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Warren Turkal

unread,
Jul 29, 2014, 2:27:55 PM7/29/14
to salt-...@googlegroups.com

Dan Garthwaite

unread,
Jul 29, 2014, 3:26:40 PM7/29/14
to salt-...@googlegroups.com
It would, but it always dissappoints.

Paul Reinking

unread,
Jul 30, 2014, 4:57:28 AM7/30/14
to salt-...@googlegroups.com
Could anyone tell me of within Salt it would be possible to refer to
part of a string.
For instance if the minion id would be 'first-last' would I be able to
split this in two separate strings 'first' and 'last'.

Thanks!

Dmitry Golubenko

unread,
Jul 30, 2014, 6:55:54 AM7/30/14
to salt-...@googlegroups.com
В Срд, 30/07/2014 в 10:57 +0200, Paul Reinking пишет:
try something like {{ grains.id.split("-") }}

>
> Thanks!
>



Paul Reinking

unread,
Jul 30, 2014, 8:25:32 AM7/30/14
to salt-...@googlegroups.com
Hi Dmitry,

You sure made my day, works like a charm after I placed these lines at
the beginning of my sls file

{% set prefix = grains.id.split ("-")[0] -%}
{% set name = grains.id.split ("-")[1] -%}

Thanks
Reply all
Reply to author
Forward
0 new messages