Nagios Plugins
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

check_z_heartbeat 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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
  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_follow'):
  40. sp.send(socket_protocol.SID_READ_REQUEST, DID_FOLLOWS_SETPOINT, data)
  41. sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, DID_FOLLOWS_SETPOINT).get_data()
  42. else:
  43. sys.stderr.write('No action for command called "%s"\n' % sys.argv[0])
  44. sys.exit(100)
  45. nagios.Nagios().exit(**sp_data)