Page 1 of 1

Custom plugin help

Posted: Thu Mar 24, 2016 4:45 am
by steve_boohoo
Hi had a developer send me a plug in to deploy - basically connects to a port and interprets some JSON for a health check - doesn't work do I need to change the localhost URL to be a reference to the host i.e $HOSTADDRESS?

#!/usr/bin/env python

import requests
import sys
import getopt

try:
opts, args = getopt.getopt(sys.argv[1:], "p:", ["port="])
except getopt.GetoptError:
print('springboot.py -p <port>')
sys.exit(2)

for opt, arg in opts:
if opt == '-h':
print('springboot.py -p <port>')
sys.exit()
elif opt in ("-p", "--port"):
PORT = arg

try:
resp = requests.get('http://localhost:{PORT}/health'.format(**locals())).json()
except:
print sys.exc_info()[0]
sys.exit(2)

if resp['status'] == 'UP':
print "OK"
sys.exit(0)
else:
print "FAIL!"
sys.exit(2)

Re: Custom plugin help

Posted: Thu Mar 24, 2016 10:35 am
by rkennedy
The script you posted doesn't seem to take any arguments, you'll need to have them rewrite it so that you can pass a -H for the $HOSTADDRESS$ (which then replaces 'localhost').

Another option is having them write the python script to accept $1 as the host (to replace localhost).

Then, in Nagios, you could pass the $HOSTADDRESS$ variable to the script. For example, $USER1$/yourscript.py $HOSTADDRESS$