Created
July 4, 2018 01:57
-
-
Save wokka1/a40e219ebd2c88392d09e4513c2ea5c9 to your computer and use it in GitHub Desktop.
virus monitor script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import time | |
import json | |
import requests | |
import datetime | |
import logging, sys | |
import smtplib | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEText import MIMEText | |
panels_to_check = "panels.txt" | |
ignore_hostname = "ign_host.txt" | |
localtime = datetime.datetime.now() | |
def l2s(list): | |
result = '' | |
for element in list: | |
result += str(element) | |
return result; | |
def send_email(subject, message): | |
fromaddr = "xxxxxxxxxxxxxxxxxxxxxxx@cryptofarmexperts.com" | |
toaddr = "xxxxxxxxxxxxxxx@cryptofarmexperts.com" | |
msg = MIMEMultipart() | |
msg['From'] = fromaddr | |
msg['To'] = toaddr | |
msg['Subject'] = subject | |
body = message | |
msg.attach(MIMEText(body, 'plain')) | |
server = smtplib.SMTP('mail.ccccccccc.ccc', 587) | |
server.starttls() | |
server.login(fromaddr, "xxxxxxxxx") | |
text = msg.as_string() | |
server.sendmail(fromaddr, toaddr, text) | |
server.quit() | |
return; | |
def ignore_refresh(NAME, DOWN, ethos_hostname, ignore_hostname): | |
if NAME == DOWN : | |
#print ethos_hostname | |
#print NAME | |
numGpus = b["rigs"][NAME]["gpus"] | |
numRunningGpus = b["rigs"][NAME]["miner_instance"] | |
rig_condition = b["rigs"][NAME]["condition"] | |
rig_minersec = b["rigs"][NAME]["miner_secs"] | |
if numGpus == numRunningGpus and rig_minersec > 400 : | |
if rig_condition == "mining" or rig_condition == "autorebooted" : | |
with open(ignore_hostname,"r+") as f: | |
new_f = f.readlines() | |
f.seek(0) | |
for line in new_f: | |
if NAME not in line: | |
f.write(line) | |
f.truncate() | |
f.close() | |
return; | |
def check_panel(NAME, DOWN, ethos_hostname, rig_uptime, rigname, ignore_hostname, localtime): | |
if DOWN != NAME and rig_uptime > 360 : | |
numGpus = b["rigs"][rigname]["gpus"] | |
numRunningGpus = b["rigs"][rigname]["miner_instance"] | |
rig_condition = b["rigs"][NAME]["condition"] | |
if rig_condition == "stuck_miners" or rig_condition == "unreachable" : | |
ign_pan = open(ignore_hostname, "a") | |
ign_pan.write(NAME) | |
ign_pan.write("\n") | |
ign_pan.close() | |
rack_loc = b["rigs"][rigname]["rack_loc"] | |
miner_hashes_str = b["rigs"][rigname]["miner_hashes"] | |
miner_hashes = miner_hashes_str.split() | |
miner_hashes = json.dumps(miner_hashes) | |
miner_core_str = b["rigs"][rigname]["core"] | |
miner_core = miner_core_str.split() | |
miner_core = json.dumps(miner_core) | |
miner_mem_str = b["rigs"][rigname]["mem"] | |
miner_mem = miner_mem_str.split() | |
miner_mem = json.dumps(miner_mem) | |
miner_powertune_str = b["rigs"][rigname]["powertune"] | |
miner_powertune = miner_powertune_str.split() | |
miner_powertune = json.dumps(miner_powertune) | |
miner_temp_str = b["rigs"][rigname]["temp"] | |
miner_temp = miner_temp_str.split() | |
miner_temp = json.dumps(miner_temp) | |
str1 = ethos_hostname + (" ") + rack_loc + (" [") + rigname + ("] ") + ("Down") | |
#print str1 | |
localtime = str(localtime) | |
str2 = localtime + ('\n') + rack_loc + (" [") + rigname + ("]") + ("\nCondition : ") + rig_condition + ("\nHashes : ") + miner_hashes + ("\nCore : ") + miner_core + ("\nMem : ") + miner_mem + ("\nPower : ") + miner_powertune + ("\nTemp : ") + miner_temp | |
send_email(str1, str2) | |
return; | |
while True: | |
with open(panels_to_check) as f: | |
panel = f.read().splitlines() | |
#print panel | |
f.close() | |
with open(ignore_hostname) as f: | |
res_panel = f.read().splitlines() | |
#print res_panel | |
f.close() | |
for ethos_hostname in panel: | |
ethos_hostname=str(ethos_hostname) | |
print ethos_hostname | |
header = {'Content-Type': 'application/json; charset=utf-8'} | |
uri = 'http://' + ethos_hostname + '.ethosdistro.com/?json=yes' | |
resp = requests.get(uri, headers=header) | |
a = json.dumps(resp.json()) | |
b = json.loads(a) # decode JSON format | |
rigs = list(b["rigs"].keys()) | |
for rig_idx, rigname in enumerate(rigs) : | |
rig_uptime = b["rigs"][rigname]["uptime"] | |
down_panel = [down_p for down_p in res_panel if down_p == rigname] | |
DOWN = l2s(down_panel) | |
NAME = l2s(rigname) | |
#print "check_panel" | |
check_panel(NAME, DOWN, ethos_hostname, rig_uptime, rigname, ignore_hostname, localtime) | |
#print "ignore_refresh" | |
ignore_refresh(NAME, DOWN, ethos_hostname, ignore_hostname) | |
time.sleep(10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment