Nagios Plugins
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

check_z_heartbeat 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/python3
  2. #
  3. import argparse
  4. import nagios
  5. import time
  6. from z_server import config
  7. from z_server import tcp_socket
  8. from z_server.z_protocol import server as client_prot
  9. from z_server.z_protocol import DID_FOLLOWS_SETPOINT, DID_BATTERY_LEVEL, DID_HEARTBEAT, DID_LINKQUALITY
  10. from z_server import socket_protocol
  11. import sys
  12. if __name__ == '__main__':
  13. parser = argparse.ArgumentParser(
  14. prog='ProgramName',
  15. description='What the program does',
  16. epilog='Text at the bottom of help')
  17. parser.add_argument('-s', '--stg', required=True)
  18. parser.add_argument('-l', '--loc', required=True)
  19. parser.add_argument('-r', '--roo', required=True)
  20. parser.add_argument('-f', '--fun', required=True)
  21. args = parser.parse_args()
  22. #
  23. c = tcp_socket.tcp_client_stp('127.0.0.1', config.SOCK_PROT_PORT)
  24. sp = client_prot(c, channel_name='example_client')
  25. #
  26. data = {
  27. "stg": args.stg,
  28. "loc": args.loc,
  29. "roo": args.roo,
  30. "fun": args.fun
  31. }
  32. #
  33. if sys.argv[0].endswith('check_z_heartbeat'):
  34. sp.send(socket_protocol.SID_READ_REQUEST, DID_HEARTBEAT, data)
  35. sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_HEARTBEAT).get_data()
  36. elif sys.argv[0].endswith('check_z_battery'):
  37. sp.send(socket_protocol.SID_READ_REQUEST, DID_BATTERY_LEVEL, data)
  38. sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_BATTERY_LEVEL).get_data()
  39. elif sys.argv[0].endswith('check_z_linkquality'):
  40. sp.send(socket_protocol.SID_READ_REQUEST, DID_LINKQUALITY, data)
  41. sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_LINKQUALITY).get_data()
  42. elif sys.argv[0].endswith('check_z_follow'):
  43. sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, data)
  44. sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_SETPOINT).get_data()
  45. else:
  46. sys.stderr.write('No action for command called "%s"\n' % sys.argv[0])
  47. sys.exit(100)
  48. nagios.Nagios().exit(**sp_data)