Nagios Check NRPE : Check OpenStack RabbitMQ Aliveness

Prerequisites: OpenStack Cloud + a Nagios server already setup and Nagios-NRPE-server installed on your OpenStack cluster +pynagios installed.

 

This nagios check will test rabbitmq availability

This script has to be set in your Controller node, then called by your Nagios Server remotely using NRPE.

 

Let’s set it up in your nrpe.cfg file ( usually in /etc/nagios/nrpe.cfg )

[do not forget to replace “xxxxxx” with your amqp admin password ]

1
2
# RABBIT Connection to localhost
command[check_rabbitmq_conn_localhost]=/usr/local/nagios/libexec/check_rabbit_aliveness.py -H localhost --password xxxxxx

 

And the check itself to place inĀ /usr/lib/nagios/plugins/check_rabbit_aliveness.py

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env /usr/bin/python
import check_rabbit_aliveness
from pynagios import make_option, Response, WARNING, CRITICAL, OK
from base_rabbit_check import BaseRabbitCheck

class RabbitAlivenessCheck(BaseRabbitCheck):
"""
performs a nagios compliant check on a single queue and
attempts to catch all errors. expected usage is with a critical threshold of 0
"""


vhost = make_option("--vhost", dest="vhost", help="RabbitMQ vhost", type="string", default='%2F')

def makeUrl(self):
"""
forms self.url, a correct url to polling a rabbit queue
"""

try:
if self.options.use_ssl is True:
self.url = "https://%s:%s/api/aliveness-test/%s" % (self.options.hostname, self.options.port, self.options.vhost)
else:
self.url = "http://%s:%s/api/aliveness-test/%s" % (self.options.hostname, self.options.port, self.options.vhost)
return True
except Exception, e:
self.rabbit_error = 3
self.rabbit_note = "problem forming api url:", e
return False

def testOptions(self):
"""
returns false if necessary options aren't present
"""

if not self.options.vhost:
return False
return True

def setPerformanceData(self, data, result):
result.set_perf_data("rabbit_error", self.rabbit_error)
return result

def parseResult(self, data):
if data['status'] == 'ok':
return Response(OK, "Response status was ok")
return Response(CRITICAL, data['status'])

if __name__ == "__main__":
obj = RabbitAlivenessCheck()
obj.check().exit()

 

Which will produce for example :

 

1
2
# /usr/lib/nagios/plugins/check_rabbit_aliveness.py -H localhost --password xxxxxx
OK: Response status was ok|rabbit_error=0;;;;