Skip to content

Instantly share code, notes, and snippets.

@noxious
Forked from jonmcewen/springboot.py
Created March 3, 2017 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noxious/143839d41c8b14f6c25896abd41c48c2 to your computer and use it in GitHub Desktop.
Save noxious/143839d41c8b14f6c25896abd41c48c2 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