Advertisement
Guest User

pool-health-check.py

a guest
Mar 23rd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. #!/usr/bin/python
  2. import json
  3. import pycurl
  4. import pprint
  5. import socket
  6. from StringIO import StringIO
  7. import paramiko
  8. import time
  9. response_buffer = StringIO()
  10.  
  11. ethos_distro_handle = pycurl.Curl()
  12. ethos_distro_handle.setopt(ethos_distro_handle.URL,'http://<Change>.ethosdistro.com/?json=yes')
  13. ethos_distro_handle.setopt(ethos_distro_handle.WRITEFUNCTION, response_buffer.write)
  14. ethos_distro_handle.perform()
  15. ethos_distro_handle.close()
  16. ethos_distro_json = json.loads(response_buffer.getvalue())
  17. for rig in ethos_distro_json['rigs']:
  18. if ethos_distro_json['rigs'][rig]['condition'] == 'unreachable':
  19. print('Rig %s (%s) is Unreachable\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  20. try:
  21. rig_ssh_connection = paramiko.SSHClient()
  22. rig_ssh_connection.load_system_host_keys()
  23. rig_ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  24. rig_ssh_connection.connect(ethos_distro_json['rigs'][rig]['ip'],22,'ethos','live',timeout=5)
  25. rig_ssh_connection.exec_command('r')
  26. rig_ssh_connection.close()
  27. except:
  28. print('Could not SSH to rig %s (%s)\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  29. elif ethos_distro_json['rigs'][rig]['condition'] == 'stuck_miners':
  30. print('Rig %s (%s) has stuck miners. Will reboot between 22:00 and 06:00 ET.\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  31. if int(time.strftime("%H")) > 20 or int(time.strftime("%H")) < 7:
  32. try:
  33. rig_ssh_connection = paramiko.SSHClient()
  34. rig_ssh_connection.load_system_host_keys()
  35. rig_ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  36. rig_ssh_connection.connect(ethos_distro_json['rigs'][rig]['ip'],22,'ethos','live',timeout=5)
  37. rig_ssh_connection.exec_command('r')
  38. rig_ssh_connection.close()
  39. except:
  40. print('Could not SSH to rig %s (%s)\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  41. elif ethos_distro_json['rigs'][rig]['condition'] == 'overheat' or ethos_distro_json['rigs'][rig]['condition'] == 'throttle':
  42. print('Rig %s (%s) overheated or throttled. Will clear thermals between 22:00 and 06:00 ET.' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  43. if int(time.strftime("%H")) > 20 or int(time.strftime("%H")) < 7:
  44. try:
  45. rig_ssh_connection = paramiko.SSHClient()
  46. rig_ssh_connection.load_system_host_keys()
  47. rig_ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  48. rig_ssh_connection.connect(ethos_distro_json['rigs'][rig]['ip'],22,'ethos','live',timeout=5)
  49. rig_ssh_connection.exec_command('clear-thermals && update')
  50. rig_ssh_connection.close()
  51. except:
  52. print('Could not SSH to rig %s (%s)\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  53. elif ethos_distro_json['rigs'][rig]['condition'] == 'adl_error':
  54. print('Rig %s (%s) is reporting ADL error. Clearing flag.\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  55. try:
  56. rig_ssh_connection = paramiko.SSHClient()
  57. rig_ssh_connection.load_system_host_keys()
  58. rig_ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  59. rig_ssh_connection.connect(ethos_distro_json['rigs'][rig]['ip'],22,'ethos','live',timeout=5)
  60. rig_ssh_connection.exec_command('echo "" > /var/run/adl_error.file')
  61. rig_ssh_connection.close()
  62. except:
  63. print('Could not SSH to rig %s (%s)\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  64. elif ethos_distro_json['rigs'][rig]['condition'] == 'no_hash':
  65. print('Rig %s (%s) is Not Mining, Restarting Proxy\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  66. try:
  67. rig_ssh_connection = paramiko.SSHClient()
  68. rig_ssh_connection.load_system_host_keys()
  69. rig_ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  70. rig_ssh_connection.connect(ethos_distro_json['rigs'][rig]['ip'],22,'ethos','live',timeout=5)
  71. rig_ssh_connection.exec_command('restart-proxy')
  72. rig_ssh_connection.close()
  73. except:
  74. print('Could not SSH to rig %s (%s)\n' % (rig, ethos_distro_json['rigs'][rig]['ip']))
  75. else:
  76. print('Rig %s is OK' % (rig))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement