Custom plugin help

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
steve_boohoo
Posts: 3
Joined: Thu Oct 08, 2015 12:07 pm

Custom plugin help

Post 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)
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Custom plugin help

Post 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$
Former Nagios Employee
Locked