diff options
author | Nishanth Thomas <nthomas@redhat.com> | 2014-03-20 13:08:42 +0530 |
---|---|---|
committer | Bala.FA <barumuga@redhat.com> | 2014-04-29 10:21:36 +0530 |
commit | 3b7cc051a97dfb57454bf71e0aca68acdfc95e4e (patch) | |
tree | 37786eeedf44eb8cf4f6dc52eeeacc74a705dd55 | |
parent | 522783ba9afebcd82869c57090feb8258e52915b (diff) |
Added files for volume Utilization - Nagios server side
Change-Id: Idaa995d504e2278fb5a2b67ca4bcbc157307b7d7
Signed-off-by: Nishanth Thomas <nthomas@redhat.com>
Reviewed-on: https://cuckoo.blr.redhat.com:8443/50
Reviewed-by: Sahina Bose <sabose@redhat.com>
Tested-by: Sahina Bose <sabose@redhat.com>
-rw-r--r-- | plugins/Makefile.am | 1 | ||||
-rwxr-xr-x | plugins/check_vol_utilization_server.py | 81 | ||||
-rw-r--r-- | plugins/livestatus.py | 17 |
3 files changed, 99 insertions, 0 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 9c943f7..b7917ec 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -5,6 +5,7 @@ dist_glusternagiosplugins_PYTHON = \ gluster_host_service_handler.py \ livestatus.py \ notify_ovirt_engine_handler.py \ + check_vol_utilization_server.py \ $(NULL) EXTRA_DIST = \ diff --git a/plugins/check_vol_utilization_server.py b/plugins/check_vol_utilization_server.py new file mode 100755 index 0000000..8b08f21 --- /dev/null +++ b/plugins/check_vol_utilization_server.py @@ -0,0 +1,81 @@ +#!/usr/bin/python +import sys +import commands +import random +import argparse +import livestatus + +_NRPEPath = "/usr/lib64/nagios/plugins/check_nrpe" + + +def excecNRPECommand(host): + #Get the address of the host + answer = livestatus.checkLiveStatus("GET hosts\nColumns: address\n" + "Filter: display_name = " + + host + "\n") + command = _NRPEPath + " -H " + answer.rstrip() + " -c " \ + "check_vol_utilization -a " + args.volume + " " + \ + str(args.warning) + " " + str(args.critical) + status = commands.getoutput(command) + return status + + +def showVolumeUtilization(args): + table = livestatus.readLiveStatus("GET hostgroups\nColumns: members name\n" + "Filter: name = " + + args.hostgroup + "\n") + tab1 = table[0] + list_hosts = tab1[0].split(";") + #First take a random host from the group and send the request + host = random.choice(list_hosts) + status = excecNRPECommand(host) + #if success return from here + if "Volume Utilization" in status: + return status + #radom host is not able to execute the command + #Now try to iterate through the list of hosts + #in the host group and send the command until + #the command is successful + for host in list_hosts: + status = excecNRPECommand(host) + #if success return from here + if "Volume Utilization" in status: + return status + break + return status + + +def parse_input(): + parser = argparse.ArgumentParser( + usage='%(prog)s [-h] <hostgroup> <volume> -w <Warning> -c <Critical>') + parser.add_argument( + "hostgroup", + help="Name of the hostgroup in which the volume belongs to") + parser.add_argument( + "volume", + help="Name of the volume to get the Utilization") + parser.add_argument( + "-w", + "--warning", + action="store", + type=int, + help="Warning Threshold in percentage") + parser.add_argument( + "-c", + "--critical", + action="store", + type=int, + help="Critical Threshold in percentage") + args = parser.parse_args() + if not args.critical or not args.warning: + print "UNKNOWN:Missing critical/warning threshold value." + sys.exit(3) + if args.critical <= args.warning: + print "UNKNOWN:Critical must be greater than Warning." + sys.exit(3) + return args + +if __name__ == '__main__': + args = parse_input() + status = showVolumeUtilization(args) + print status diff --git a/plugins/livestatus.py b/plugins/livestatus.py index ce546ce..e2f4f03 100644 --- a/plugins/livestatus.py +++ b/plugins/livestatus.py @@ -46,3 +46,20 @@ def readLiveStatus(cmd): table = [line.split('|') for line in answer.split('\n')[:-1]] return table + + +def checkLiveStatus(cmd): + s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + s.connect(_socketPath) + + # Write command to socket + s.send(cmd) + + # Close socket + s.shutdown(socket.SHUT_WR) + + # Read the answer + answer = s.recv(1000000) + + # return the result + return answer |