Send notification in case of scheduled downtime

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
rubbens16
Posts: 4
Joined: Mon Jul 11, 2016 9:34 am

Send notification in case of scheduled downtime

Post by rubbens16 »

How can I send a notification such as "We are planning a scheduled downtime from 2016-07-14 20:00:00 till 2016-07-14 22:00:00" (given the current time 2016-07-14 15:30)?

I've wrote a macro that can be called as such

Code: Select all

$USER1$/event_handler_customer_mail.sh "$SERVICEDESC$" $SERVICESTATE$ "$NOTIFICATIONCOMMENT$" $CONTACTEMAIL$
But I have several issues with this macro:

* The notification is not sent when it is created in the Nagios Core website, but is only triggered when the scheduled downtime starts (so in my example the notification is sent at 2016-07-14 20:00:00 and not at 15:30)
* The notification is sent when the downtime starts, but also when the downtime ends. How can I make sure that is only sent once?
* In my macro I cannot find a way to use the strings for the scheduled start and end.

This is currently my macro:

Code: Select all

#!/bin/bash

DATE=$(date)
SERVICEDESC="$1"
SERVICESTATETYPE=$2
NOTIFICATIONCOMMENT="$3"
EMAIL=$4

if [[ "$SERVICESTATE" == "CRITICAL"  ]]; then
	/usr/bin/printf "%b" "Dear client:\n\nWe regret to inform you that our website $SERVICEDESC is currently not available due to an unplanned issue. We're aware of this unavailability and are doing our utmost to bring our service back as soon as possible.\n\nWe will send you an update as soon as our website is working as normal again.\n\nDate/Time: $DATE\n" | /usr/bin/mail -s "WARNING: $SERVICEDESC is currently not available" $EMAIL	
	exit 0
elif [[ "$SERVICESTATE" == "OK"  ]]; then
	/usr/bin/printf "%b" "Dear client:\n\nWe are glad to inform you that our website $SERVICEDESC is behaving normally again.\n\nDate/Time: $DATE\n" | /usr/bin/mail -s "SOLVED: $SERVICEDESC is available" $EMAIL	
	exit 0
elif [[ ! -z "$NOTIFICATIONCOMMENT" ]]; then
	/usr/bin/printf "%b" "Dear client:\n\nWe are a scheduling an update of our website $SERVICEDESC.\n\n$NOTIFICATIONCOMMENT\n\nDate/Time: $DATE\n" | /usr/bin/mail -s "WARNING: Scheduled maintenance for $SERVICEDESC" $EMAIL	
	exit 0
else
	exit 0
fi
Tx

-- Ivan
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Send notification in case of scheduled downtime

Post by eloyd »

To my knowledge, there is no "hook" to take action when someone schedules the downtime, only when it activates. You could solve this procedurally by creating a "middleware" web page that people enter host, service, and downtime parameters, and then the back end of this web page sends notifications and then uses the nagios API or nagios.cmd file to schedule the downtime for you. This way, you have complete control over authentication, authorization, and ensuring that downtime isn't scheduled at the wrong time of day (for instance). You can also use the API/nagios.cmd file to automate downtime if you have some sort of downtime calendar that you can pull events from.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Send notification in case of scheduled downtime

Post by bwallace »

Thanks eloyd. OP, let us know if any other questions....
Be sure to check out the Knowledgebase for helpful articles and solutions!
Locked