summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShubhendu Tripathi <shtripat@redhat.com>2014-05-29 12:49:52 +0530
committerTimothy Asir <tim.gluster@gmail.com>2014-05-30 01:18:08 -0700
commit870e96472f2b3f8a258b781210c25cb365980067 (patch)
treed810e4a2b7f4cf1a85b4e39f083c8af8c5d2630d
parent45502497df037e8a145ae8dc92c0b4ef378c537c (diff)
nagios-server-addons: Check hosts status using NRPE
Enabled to execute check_nrpe for a given host to check its status. Change-Id: I938b78fcbf52cd46f4f493e2c2b8b927614834eb Bug-URL: https://bugzilla.redhat.com/show_bug.cgi?id=1102506 Signed-off-by: Shubhendu Tripathi <shtripat@redhat.com> Reviewed-on: http://review.gluster.org/7923 Reviewed-by: Ramesh N <rnachimu@redhat.com> Reviewed-by: Kanagaraj M <kmayilsa@redhat.com> Reviewed-by: Timothy Asir <tim.gluster@gmail.com>
-rw-r--r--config/gluster-commands.cfg5
-rw-r--r--config/gluster-templates.cfg1
-rw-r--r--config/host-monitoring-services.in2
-rwxr-xr-xplugins/check_remote_host.py.in99
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/test_check_remote_host.py46
6 files changed, 29 insertions, 125 deletions
diff --git a/config/gluster-commands.cfg b/config/gluster-commands.cfg
index d2ebdce..ac61fc5 100644
--- a/config/gluster-commands.cfg
+++ b/config/gluster-commands.cfg
@@ -25,6 +25,11 @@ define command {
}
define command {
+ command_name check_remote_host
+ command_line $USER1$/gluster/check_remote_host.py -H $HOSTADDRESS$
+}
+
+define command {
command_name host_service_handler
command_line $USER1$/gluster/gluster_host_service_handler.py -s $SERVICESTATE$ -t $SERVICESTATETYPE$ -a $SERVICEATTEMPT$ -l $HOSTADDRESS$ -n "$SERVICEDESC$"
}
diff --git a/config/gluster-templates.cfg b/config/gluster-templates.cfg
index b8b47bc..6f968ca 100644
--- a/config/gluster-templates.cfg
+++ b/config/gluster-templates.cfg
@@ -12,6 +12,7 @@ define host{
define host {
name gluster-host
use gluster-generic-host
+ check_command check_remote_host
register 0
_gluster_entity Host
}
diff --git a/config/host-monitoring-services.in b/config/host-monitoring-services.in
index 788e9e7..1ccbcb7 100644
--- a/config/host-monitoring-services.in
+++ b/config/host-monitoring-services.in
@@ -1 +1 @@
-{"serviceList":["Cpu Utilization", "Disk Utilization", "Memory Utilization", "Network Utilization", "Swap Utilization", "Gluster Management", "Quota", "NFS", "Self-Heal", "SMB", "CTDB"]}
+{"serviceList":[]}
diff --git a/plugins/check_remote_host.py.in b/plugins/check_remote_host.py.in
index 0e7508c..320ea6b 100755
--- a/plugins/check_remote_host.py.in
+++ b/plugins/check_remote_host.py.in
@@ -1,14 +1,7 @@
#!/usr/bin/python
#
-# check_remote_host.py -- nagios plugin uses Mklivestatus to get the overall
+# check_remote_host.py -- nagios plugin uses check_nrpe to check the host
# 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
#
@@ -27,80 +20,32 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
#
-import os
+import argparse
import sys
-import getopt
-import json
-import livestatus
+import server_utils
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)
+ parser = argparse.ArgumentParser(description="Check Host Status Tool")
+ parser.add_argument('-H', '--hostip', action='store', dest='hostip',
+ type=str, required=True, help='Host IP')
+ args = parser.parse_args()
+
+ # Check if the NRPE call goes through to the host
+ rc, out, err = utils.execCmd(
+ [
+ server_utils.nrpeCmdPath.cmd,
+ '-H',
+ args.hostip
+ ]
+ )
+
+ if rc == utils.PluginStatusCode.OK:
+ print "OK: Host is UP"
+ sys.exit(utils.PluginStatusCode.OK)
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
- criticalSrvcs = []
- for srvc in _getHostMonitoringSrvcList():
- srvc_status = checkLiveStatus(hostAddr, srvc)
- if srvc_status == utils.PluginStatusCode.CRITICAL:
- criticalSrvcs.append(str(srvc))
-
- # Return the status
- if len(criticalSrvcs) > 0:
- 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)
+ print "CRITICAL: NRPE service on the host is down or not responding"
+ sys.exit(utils.PluginStatusCode.CRITICAL)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7527b23..8616007 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,6 @@
test_modules = \
test_check_cluster_volusage.py \
- test_check_remote_host.py \
test_notify_ovirt_engine_handler.py \
test_config_generator.py \
test_discovery.py \
diff --git a/tests/test_check_remote_host.py b/tests/test_check_remote_host.py
deleted file mode 100644
index 824df63..0000000
--- a/tests/test_check_remote_host.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# Copyright 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
-#
-# Refer to the README and COPYING files for full details of the license
-#
-
-import mock
-import socket
-
-import plugins
-from testrunner import PluginsTestCase as TestCaseBase
-
-
-class TestCheckRemoteHost(TestCaseBase):
- # Method to test the checkLiveStatus() method
- @mock.patch('plugins.check_remote_host.livestatus.socket.socket')
- def testCheckLiveStatus(self, mock_socket):
- reference = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- self.assertTrue(mock_socket, "called")
- reference.recv.return_value = "0\n"
- plugins.check_remote_host.checkLiveStatus("dummy host", "dummy srvc")
- reference.connect.assert_called_with("/var/"
- "spool/nagios/cmd/live")
- reference.send.assert_called_with("GET services\nColumns: state\n"
- "Filter: description = dummy srvc\n"
- "Filter: host_address = "
- "dummy host\n"
- "Separators: 10 124 44 59\n")
- self.assertEquals(0,
- plugins.
- check_remote_host.
- checkLiveStatus("dummy host", "dummy srvc"))