Skip to content

Instantly share code, notes, and snippets.

@jonmcewen
Created September 25, 2015 08:51
Show Gist options
  • Save jonmcewen/50c57c4753224735f9dd to your computer and use it in GitHub Desktop.
Save jonmcewen/50c57c4753224735f9dd to your computer and use it in GitHub Desktop.
nagios plugin for spring-boot app status
#!/usr/bin/env python
import requests, sys, 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment