def data_show(data = {}): global args # Check data to return if args.format == 'json' and args.zabbix != False: print zblib.json_out(data); elif args.format == 'json': show_data_json(data); elif args.format == 'html': show_data_html(data); return True
def main(): # Config arguments parser = argparse.ArgumentParser() parser.add_argument('-z', '--server') parser.add_argument('-p', '--port') parser.add_argument('-s', '--host') parser.add_argument('-u', '--stat-user', dest='stuser', default='none') parser.add_argument('-P', '--stat-pass', dest='stpass', default='none') parser.add_argument('-m', '--metric') parser.add_argument('-S', '--https', action="store_true", default=False) parser.add_argument('-j', '--json', action="store_true", dest="json", default=False, help="show json output, without send to zabbix.") # Parsing arguments args = parser.parse_args() ## Getting arguments if args.host : hostname = args.host else : print ("Hostname not found (-s), please try again. See -h option."); exit(1) if args.server : zabbix_host = args.server else : zabbix_host = '127.0.0.1' if args.port : zabbix_port = args.port else : zabbix_port = 10051 stat_user = args.stuser stat_pass = args.stpass if args.metric : metric = re.match(r'nginx\[(.*)\]', args.metric, re.M | re.I).group(1) or False else : metric = False ## Metric #metric = (len(sys.argv) >= 2) and re.match(r'nginx\[(.*)\]', sys.argv[1], re.M | re.I).group(1) or False # Get data from Stat for each application if args.https : stat_url = "https://" + hostname + "/nginx_stat" else: stat_url = "http://" + hostname + "/nginx_stat" #print stat_url data_to_send = get_stat(hostname, stat_url, stat_user, stat_pass, metric) # Just print metric and quit if args.metric: print data_to_send exit(0); # Just print JSON and quit if args.json : print zblib.json_out(data_to_send); exit(0); log_msg = strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' - ' + hostname + ' - ' #print log_msg return zblib.send_trapper(data_to_send, zabbix_host, zabbix_port, log_msg)