#!/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_HEATING_SETPOINT, DID_BATTERY_LEVEL, DID_HEARTBEAT 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) 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": "FUN_HEA" # <-- Const, because script is for heat_vlv only } # if sys.argv[0].endswith('check_z_heat_vlv_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_heat_vlv_follow'): sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_HEATING_SETPOINT, data) sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_HEATING_SETPOINT).get_data() elif sys.argv[0].endswith('check_z_heat_vlv_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() else: sys.stderr.write('No action for command called "%s"\n' % sys.argv[0]) sys.exit(100) nagios.Nagios().exit(**sp_data)