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 /plugins/check_vol_utilization_server.py | |
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>
Diffstat (limited to 'plugins/check_vol_utilization_server.py')
-rwxr-xr-x | plugins/check_vol_utilization_server.py | 81 |
1 files changed, 81 insertions, 0 deletions
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 |