Nagios Plugins
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

check_z_heartbeat 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/python3
  2. #
  3. import argparse
  4. import nagios
  5. import os
  6. import time
  7. from z_server import config
  8. from z_server import tcp_socket
  9. from z_server.z_protocol import server as client_prot
  10. from z_server.z_protocol import DIDS
  11. from z_server import socket_protocol
  12. import sys
  13. if __name__ == '__main__':
  14. parser = argparse.ArgumentParser(
  15. prog='ProgramName',
  16. description='What the program does',
  17. epilog='Text at the bottom of help')
  18. parser.add_argument('-s', '--stg', required=True)
  19. parser.add_argument('-l', '--loc', required=True)
  20. parser.add_argument('-r', '--roo', required=True)
  21. parser.add_argument('-f', '--fun', required=True)
  22. args = parser.parse_args()
  23. #
  24. c = tcp_socket.tcp_client_stp('127.0.0.1', config.SOCK_PROT_PORT)
  25. sp = client_prot(c, channel_name='example_client')
  26. #
  27. data = {
  28. "stg": args.stg,
  29. "loc": args.loc,
  30. "roo": args.roo,
  31. "fun": args.fun
  32. }
  33. #
  34. did = os.path.basename(sys.argv[0])[8:]
  35. #
  36. if did not in DIDS:
  37. print("Unknown data id %s. You might add it in z_server.z_protocol." % did)
  38. sys.exit(100)
  39. else:
  40. sp.send(socket_protocol.SID_READ_REQUEST, did, data)
  41. sp_data = sp.receive(socket_protocol.SID_READ_RESPONSE, did).get_data() or {
  42. "status": 101, "msg": "No answer from device for \"%s\". You might want to add it in z_server.devices" % did}
  43. nagios.Nagios().exit(**sp_data)