mirror of
https://github.com/shouptech/nagios-plugin-check-rabbitmq.git
synced 2026-02-03 14:49:41 +00:00
Added sockets in use alarm
This commit is contained in:
parent
bf11f88281
commit
3b32216e9c
1 changed files with 48 additions and 15 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import urllib2
|
import urllib2
|
||||||
import base64
|
import base64
|
||||||
|
import math
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
|
|
@ -32,24 +33,46 @@ class RabbitAPIChecker(object):
|
||||||
self.password = password
|
self.password = password
|
||||||
self.port = port
|
self.port = port
|
||||||
|
|
||||||
def mem_alarm(self, args):
|
def check_triggered_alarm(self, args):
|
||||||
"""Calls the API and checks if a high memory alarm has been
|
"""Checks the node for a triggered alarm"""
|
||||||
triggerred."""
|
|
||||||
node = args[0]
|
alarm = args[0]
|
||||||
|
node = args[1]
|
||||||
|
|
||||||
url = "http://%s:%s/api/nodes/%s" % (self.hostname, self.port, node)
|
url = "http://%s:%s/api/nodes/%s" % (self.hostname, self.port, node)
|
||||||
result = self.fetch_from_api(url)
|
result = self.fetch_from_api(url)
|
||||||
|
|
||||||
if 'mem_alarm' in result:
|
try:
|
||||||
if result['mem_alarm']:
|
if result[alarm]:
|
||||||
print "CRITICAL - Memory alarm triggered for %s" % node
|
print "CRITICAL - %s triggered for %s" % (alarm, node)
|
||||||
return self.STATE_CRITICAL
|
return self.STATE_CRITICAL
|
||||||
else:
|
else:
|
||||||
print "OK - Memory alarm not triggered for %s" % node
|
print "OK - %s is not triggered for %s" % (alarm, node)
|
||||||
return self.STATE_OK
|
return self.STATE_OK
|
||||||
else:
|
except KeyError:
|
||||||
print "UNKNOWN - mem_alarm not found in results from API"
|
print "UNKNOWN - %s is not a valid alarm for %s" % (alarm, node)
|
||||||
return self.STATE_UNKNOWN
|
return self.STATE_UNKNOWN
|
||||||
|
|
||||||
|
def check_sockets(self, args, critical=90, warning=80):
|
||||||
|
"""Checks the percentage of sockets used"""
|
||||||
|
|
||||||
|
node = args[1]
|
||||||
|
url = "http://%s:%s/api/nodes/%s" % (self.hostname, self.port, node)
|
||||||
|
result = self.fetch_from_api(url)
|
||||||
|
|
||||||
|
per_sockets_used = math.ceil(
|
||||||
|
100 * float(result['sockets_used']) / result['sockets_total'])
|
||||||
|
|
||||||
|
if per_sockets_used >= critical:
|
||||||
|
print "CRITICAL - %d%% sockets in use" % per_sockets_used
|
||||||
|
return self.STATE_CRITICAL
|
||||||
|
elif per_sockets_used >= warning:
|
||||||
|
print "WARNING - %d%% sockets in use" % per_sockets_used
|
||||||
|
return self.STATE_WARNING
|
||||||
|
|
||||||
|
print "OK - %d%% sockets in use" % per_sockets_used
|
||||||
|
return self.STATE_OK
|
||||||
|
|
||||||
def fetch_from_api(self, url):
|
def fetch_from_api(self, url):
|
||||||
"""Calls the API and processes the JSON result."""
|
"""Calls the API and processes the JSON result."""
|
||||||
request = urllib2.Request(url)
|
request = urllib2.Request(url)
|
||||||
|
|
@ -76,6 +99,10 @@ def main():
|
||||||
help="Port to run the API checks against")
|
help="Port to run the API checks against")
|
||||||
parser.add_option("-H", "--hostname",
|
parser.add_option("-H", "--hostname",
|
||||||
help="Host to check")
|
help="Host to check")
|
||||||
|
parser.add_option("-c", "--critical", type="int",
|
||||||
|
help="Critical level")
|
||||||
|
parser.add_option("-w", "--warning", type="int",
|
||||||
|
help="Warning level")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
# Check for required arguments
|
# Check for required arguments
|
||||||
|
|
@ -87,20 +114,26 @@ def main():
|
||||||
options.password, options.port)
|
options.password, options.port)
|
||||||
|
|
||||||
# Define actions available, will be found in args[0]
|
# Define actions available, will be found in args[0]
|
||||||
actions = {'mem_alarm': checker.mem_alarm}
|
actions = {'mem_alarm': checker.check_triggered_alarm,
|
||||||
|
'disk_free_alarm': checker.check_triggered_alarm,
|
||||||
|
'sockets_used': checker.check_sockets}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(args) > 1:
|
if options.critical and options.warning:
|
||||||
return actions[args[0]](args[1:])
|
actions[args[0]](args[0:], options.critical, options.warning)
|
||||||
|
elif options.critical:
|
||||||
|
actions[args[0]](args[0:], options.critical)
|
||||||
|
elif options.warning:
|
||||||
|
actions[args[0]](args[0:], warning=options.warning)
|
||||||
else:
|
else:
|
||||||
return actions[args[0]]()
|
actions[args[0]](args[0:])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print "UNKNOWN - %s is not a valid action" % args[0]
|
print "UNKNOWN - %s is not a valid action" % args[0]
|
||||||
return RabbitAPIChecker.STATE_UNKNOWN
|
return RabbitAPIChecker.STATE_UNKNOWN
|
||||||
except urllib2.HTTPError, exception:
|
except urllib2.HTTPError, exception:
|
||||||
print "UNKNOWN - %s" % exception
|
print "UNKNOWN - %s" % exception
|
||||||
return RabbitAPIChecker.STATE_UNKNOWN
|
return RabbitAPIChecker.STATE_UNKNOWN
|
||||||
except TypeError:
|
except IndexError:
|
||||||
print "UNKNOWN - %s requires one or more options" % args[0]
|
print "UNKNOWN - %s requires one or more options" % args[0]
|
||||||
return RabbitAPIChecker.STATE_UNKNOWN
|
return RabbitAPIChecker.STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue