summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-04-29 19:47:33 +0530
committerSahina Bose <sabose@redhat.com>2014-05-02 05:35:24 -0700
commitf56feb494a6139dca9062be1d373a10089b0b7c0 (patch)
tree6c4bcb41cee764bd4316f53c9f94f49d79db57fd /plugins
parentaf661184dd71142ae7bf4f7b36400372ca819c47 (diff)
autoconf: send email notification for auto sync
Sending a cusotm email notification whenever nagios configurations are changed by auto-config service. note: By default, nagios mail notification command 'notify-service-by-email' doesn't include the comments macro. But in auto config, all the changes are sent as comment to the custom notificiation command. Hence nagios command 'notify-service-by-email' should be changed to include the macro '$NOTIFICATIONCOMMENT$' as part of mail template. Change-Id: Ie5dd23578e08fbc757c46a884a79923ff3c403b2 Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com> Reviewed-on: http://review.gluster.org/7626 Reviewed-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/discovery.py44
1 files changed, 33 insertions, 11 deletions
diff --git a/plugins/discovery.py b/plugins/discovery.py
index bd60ae1..69e1d86 100755
--- a/plugins/discovery.py
+++ b/plugins/discovery.py
@@ -18,7 +18,7 @@
#
import argparse
import json
-
+import datetime
import os
import shutil
import sys
@@ -26,6 +26,7 @@ import sys
from glusternagios import utils
from config_generator import GlusterNagiosConfManager
import server_utils
+import submit_external_command
from constants import DEFAULT_AUTO_CONFIG_DIR
from constants import NRPE_PATH
@@ -307,23 +308,32 @@ def cleanConfigDir(dir):
os.mkdir(dir)
-#Preview the changes to cluster config
-def previewChanges(clusterDelta):
- print "Changes :"
+#Create a summary for mail notification. "\n" should be preserved in the
+#string to get the proper format in mail.
+def getSummary(clusterDelta):
+ summary = "\nChanges :"
clusterChangeMode = clusterDelta['changeMode']
- print "Hostgroup %s - %s" % (clusterDelta['hostgroup_name'],
- clusterChangeMode)
+ summary += "\nHostgroup %s - %s" % (clusterDelta['hostgroup_name'],
+ clusterChangeMode)
for host in clusterDelta['_hosts']:
if host.get('changeMode'):
changeMode = host.get('changeMode')
else:
changeMode = clusterChangeMode
- print "Host %s - %s" % (host['host_name'], changeMode)
+ summary += "\nHost %s - %s" % (host['host_name'], changeMode)
for service in host.get('host_services', []):
if service.get('changeMode'):
changeMode = service.get('changeMode')
- print "\t Service - %s -%s " % (service['service_description'],
- changeMode)
+ summary += "\n\t Service - %s -%s " % \
+ (service['service_description'], changeMode)
+ return summary
+
+
+def formatTextForMail(text):
+ output = ""
+ for line in text.splitlines():
+ output += "\\n%s" % line
+ return output
#Configure the gluster node to send passive check results through NSCA
@@ -423,6 +433,15 @@ def getConfirmation(message, default):
if ans == 'NO':
return False
+
+#Send a custom notification about the config changes to admin
+def sendCustomNotification(cluster, summary):
+ now = datetime.datetime.now()
+ cmdStr = "[%s] SEND_CUSTOM_SVC_NOTIFICATION;%s;Cluster Auto Config;0;" \
+ "Nagios Admin;%s\n" % (now, cluster, summary)
+ submit_external_command.submitExternalCommand(cmdStr)
+
+
if __name__ == '__main__':
args = parse_input()
clusterdata = discoverCluster(args.hostip, args.cluster)
@@ -440,7 +459,7 @@ if __name__ == '__main__':
#before writing the config file and before restarting the Nagios
if args.mode == "manual":
print "Cluster configurations changed"
- previewChanges(clusterDelta)
+ print getSummary(clusterDelta)
confirmation = getConfirmation(
"Are you sure, you want to commit the changes?", "Yes")
if confirmation:
@@ -463,8 +482,11 @@ if __name__ == '__main__':
elif args.mode == "auto":
writeDelta(clusterDelta, configManager, args.force,
args.nagiosServerIP, args.mode)
- print "Cluster configurations synced successfully from host %s" % \
+ msg = "Cluster configurations synced successfully from host %s" % \
(args.hostip)
+ print msg
+ msg += formatTextForMail(getSummary(clusterDelta))
+ sendCustomNotification(args.cluster, msg)
if server_utils.isNagiosRunning():
server_utils.restartNagios()
sys.exit(utils.PluginStatusCode.OK)