+ options = vars(args)
+ keyword = options['keyword']
+ url = options['url']
+ agent = options['agent']
+ if keyword is None or url is None:
+ message = "Keywork: {0} url: {1}".format(keyword, url)
+ status = 3
+ log.fatal(message)
+ else:
+ try:
+ if not testing:
+ req_headers = {
+ 'User-Agent': agent
+ }
+ http = urllib.PoolManager()
+ response = http.request(
+ 'GET', url, headers = req_headers
+ )
+ data = response.data.decode('utf-8').replace("\\"," ")
+ else:
+ data = DOWN_RESPONSE.replace("\\"," ")
+ data = json.loads(data)
+ if 'status' in data and data['status'] == keyword:
+ message = "UP"
+ status = 2
+ else:
+ message = gather_message(data)
+ status = 0
+ except Exception as e:
+ print(e)
+ message = "DOWN"
+ status = 2
+
+ gtfo(status, message)
+
+def gather_message(json_data):
+ """ Assemble error messages """
+ msg = None
+ try:
+ if 'components' in json_data:
+ components = json_data['components']
+ for component in components:
+ items = components[component]
+ if 'components' in items:
+ for item in items['components']:
+ if 'status' in items['components'][item] and items['components'][item]['status'].upper() == 'DOWN':
+ if msg is not None:
+ msg += "\n{0}: {1}".format(item, items['components'][item]['details']['error'])
+ else:
+ msg = "{0}: {1}".format(item, items['components'][item]['details']['error'])
+ else:
+ if 'status' in items and items['status'].upper() == 'DOWN':
+ if msg is not None:
+ if 'details' in items and 'error' in items['details']:
+ error = items['details']['error']
+ else:
+ error = "No error message"
+ if msg is not None:
+ msg += "\n{0}: {1}".format(component, error)
+ else:
+ msg = "{0}: {1}".format(component, error)
+ else:
+ sys.exit(3)
+ except:
+ sys.exit(3)
+ return msg
+