#!/bin/python3 # import argparse import nagios import time from z_server import config from z_server import tcp_socket from z_server.z_protocol import server as client_prot from z_server.z_protocol import DID_FOLLOWS_SETPOINT, DID_BATTERY_LEVEL, DID_HEARTBEAT, DID_LINKQUALITY from z_server import socket_protocol import sys if __name__ == '__main__': parser = argparse.ArgumentParser( prog='ProgramName', description='What the program does', epilog='Text at the bottom of help') parser.add_argument('-s', '--stg', required=True) parser.add_argument('-l', '--loc', required=True) parser.add_argument('-r', '--roo', required=True) parser.add_argument('-f', '--fun', required=True) args = parser.parse_args() # c = tcp_socket.tcp_client_stp('127.0.0.1', config.SOCK_PROT_PORT) sp = client_prot(c, channel_name='example_client') # data = { "stg": args.stg, "loc": args.loc, "roo": args.roo, "fun": args.fun } # if sys.argv[0].endswith('check_z_heartbeat'): sp.send(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, data) sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_HEARTBEAT).get_data() elif sys.argv[0].endswith('check_z_battery'): sp.send(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, data) sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_BATTERY_LEVEL).get_data() elif sys.argv[0].endswith('check_z_linkquality'): sp.send(socket_protocol.SID_READ_REQUEST, DID_LINKQUALITY, data) sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_LINKQUALITY).get_data() elif sys.argv[0].endswith('check_z_follow'): sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, data) sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_SETPOINT).get_data() else: sys.stderr.write('No action for command called "%s"\n' % sys.argv[0]) sys.exit(100) nagios.Nagios().exit(**sp_data)