Stop Double Monitoring: NGINX Plus API Helping BIG-IP
Published Nov 14, 2019
Version 1.0Was this article helpful?
an example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import urllib2
import json
def get_nginxapi(url):
ct_headers = {'Content-type':'application/json'}
request = urllib2.Request(url,headers=ct_headers)
response = urllib2.urlopen(request)
html = response.read()
return html
api = sys.argv[3]
try:
data = get_nginxapi(api)
data = json.loads(data)
except:
data = ''
m = 0
lowwater = int(sys.argv[4])
try:
for peer in data['peers']:
state = peer['state']
if state == 'up':
m = m + 1
except:
m = 0
#print data['peers'][]['state']
#print m
if m >= lowwater:
print 'UP'