summaryrefslogtreecommitdiffstats
path: root/plugins/check_remote_host.py.in
diff options
context:
space:
mode:
authorShubhendu Tripathi <shtripat@redhat.com>2014-03-21 13:53:46 +0530
committerBala.FA <barumuga@redhat.com>2014-04-29 10:21:37 +0530
commit26b98e7239222704bb7438bcc47793fc6be60f2c (patch)
treeb2f62a1188a44cd5337c711e1d8b5a04b98e3b90 /plugins/check_remote_host.py.in
parent81cc690fbe74f15e73c30079ea4bff1c37fefa3f (diff)
nagios-server-addons: Test case for host event handler
Added unit test cases for host event handler with minor code fixes Change-Id: Id9516303aaa1e4f14e781a06d4f73158bfcdebf4 Signed-off-by: Shubhendu Tripathi <shtripat@redhat.com> Reviewed-on: https://code.engineering.redhat.com/gerrit/21669 Reviewed-by: Darshan Narayana Murthy <dnarayan@redhat.com> Reviewed-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins/check_remote_host.py.in')
-rwxr-xr-xplugins/check_remote_host.py.in108
1 files changed, 108 insertions, 0 deletions
diff --git a/plugins/check_remote_host.py.in b/plugins/check_remote_host.py.in
new file mode 100755
index 0000000..0ef101e
--- /dev/null
+++ b/plugins/check_remote_host.py.in
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+#
+# check_remote_host.py -- nagios plugin uses Mklivestatus to get the overall
+# status
+# of a host. The services considered by default for the status of the host
+# are -
+# 1. LV/Inode Service status
+# 2. CPU Utilization
+# 3. Memory Utilization
+# 4. Network Utilization
+# 5. Swap Utilization
+#
+# Copyright (C) 2014 Red Hat Inc
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
+#
+
+import os
+import sys
+import getopt
+import json
+
+import livestatus
+from glusternagios import utils
+
+
+# Method to execute livestatus
+def checkLiveStatus(hostAddr, srvc):
+ cmd = "GET services\nColumns: state\nFilter: " \
+ "description = %s\n" \
+ "Filter: host_address = %s" % (srvc, hostAddr)
+
+ table = livestatus.readLiveStatus(cmd)
+
+ if len(table) > 0 and len(table[0]) > 0:
+ return int(table[0][0])
+ else:
+ return utils.PluginStatusCode.UNKNOWN
+
+
+def _getHostMonitoringSrvcList():
+ srvc_list = []
+ with open("@hostmonitoringserviceslist@") as data_file:
+ srvc_list = json.load(data_file)['serviceList']
+ return srvc_list
+
+
+# Method to show the usage
+def showUsage():
+ usage = "Usage: %s -H <Host Address>\n" % os.path.basename(sys.argv[0])
+ sys.stderr.write(usage)
+
+
+# Main method
+if __name__ == "__main__":
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "hH:", ["help", "host="])
+ except getopt.GetoptError as e:
+ print (str(e))
+ showUsage()
+ sys.exit(utils.PluginStatusCode.CRITICAL)
+
+ hostAddr = ''
+ if len(opts) == 0:
+ showUsage()
+ sys.exit(utils.PluginStatusCode.CRITICAL)
+ else:
+ for opt, arg in opts:
+ if opt in ("-h", "--help"):
+ showUsage()
+ sys.exit()
+ elif opt in ("-H", "--host"):
+ hostAddr = arg
+ else:
+ showUsage()
+ sys.exit(utils.PluginStatusCode.CRITICAL)
+
+ # Calculate the consolidated status for the host based on above
+ # status of individual services
+ finalStatus = utils.PluginStatusCode.OK
+ criticalSrvcs = []
+ for srvc in _getHostMonitoringSrvcList():
+ srvc_status = checkLiveStatus(hostAddr, srvc)
+ finalStatus = finalStatus | srvc_status
+ if srvc_status == utils.PluginStatusCode.CRITICAL:
+ criticalSrvcs.append(str(srvc))
+
+ # Return the status
+ if finalStatus == utils.PluginStatusCode.CRITICAL:
+ print "Host Status %s - Service(s) %s in CRITICAL state" % \
+ (utils.PluginStatus.WARNING, criticalSrvcs)
+ sys.exit(utils.PluginStatusCode.WARNING)
+
+ print "Host Status %s - Services in good health" % \
+ utils.PluginStatus.OK
+ sys.exit(utils.PluginStatusCode.OK)