def __init__(self): measure_time_start = time.time() list_of_alive_panels = redis_store.lrange( 'sidebar_info:list_of_alive_panels', 0, -1) num_of_gpus = redis_store.get('main_dashboard:num_of_gpus') if num_of_gpus: self.num_of_gpus = int(num_of_gpus) num_of_alive_gpus = redis_store.get('main_dashboard:num_of_alive_gpus') if num_of_alive_gpus: self.num_of_alive_gpus = int(num_of_alive_gpus) measure_time_end = time.time() self.execution_time = round((measure_time_end - measure_time_start), 2) self.panels_info = {} for panel_name in list_of_alive_panels: self.panels_info[panel_name] = {} list_of_pool_info_packed = redis_store.get( "admin_main_dashboard:{}:unique_poll_info_list".format( str(panel_name))) if list_of_pool_info_packed: self.panels_info[panel_name]["list_of_pool_info"] = json.loads( list_of_pool_info_packed) else: self.panels_info[panel_name]["list_of_pool_info"] = [] self.panels_info[panel_name][ 'dual_miners_list'] = redis_store.lrange( "admin_main_dashboard:{}:dual_miners_list".format( str(panel_name)), 0, -1)
def voice_offline_rigs(): # Start our TwiML response resp = VoiceResponse() # Read a message aloud to the caller resp.say("Server is calling you.", voice='alice') try: num_of_rigs = redis_store.get('main_dashboard:num_of_rigs') if num_of_rigs: num_of_rigs = int(num_of_rigs) num_of_alive_rigs = redis_store.get('main_dashboard:num_of_alive_rigs') if num_of_alive_rigs: num_of_alive_rigs = int(num_of_alive_rigs) if num_of_rigs > 0: num_of_offline_rigs = num_of_rigs - num_of_alive_rigs else: num_of_offline_rigs = 0 except Exception as e: num_of_offline_rigs = 0 print(e) print("Failed to receive num of offline rigs") if num_of_offline_rigs > 0: resp.say("You have {} machines offline.".format(num_of_offline_rigs), voice='alice', loop=10) resp.hangup() elif num_of_offline_rigs == 0: resp.say("You have no machines offline. Problem is solved.", voice='alice', loop=10) resp.hangup() return str(resp)
def __init__(self, bios_name): measure_time_start = time.time() self.dict_of_bioses = redis_store.hgetall( "technical_information:dict_of_bioses") num_of_gpus = redis_store.get('main_dashboard:num_of_gpus') if num_of_gpus: self.num_of_gpus = int(num_of_gpus) num_of_rigs = redis_store.get('main_dashboard:num_of_rigs') if num_of_rigs: self.num_of_rigs = int(num_of_rigs) num_of_alive_gpus = redis_store.get('main_dashboard:num_of_alive_gpus') if num_of_alive_gpus: self.num_of_alive_gpus = int(num_of_alive_gpus) dict_of_rigs_packed = redis_store.get( "technical_information:{}:dict_of_rigs_bioses".format( str(bios_name))) if dict_of_rigs_packed: self.dict_of_rigs = json.loads(dict_of_rigs_packed) else: self.dict_of_rigs = {} measure_time_end = time.time() self.execution_time = round((measure_time_end - measure_time_start), 2)
def voice_attack(): """Respond to incoming phone calls with attack message""" # Start our TwiML response resp = VoiceResponse() # Read a message aloud to the caller resp.say("Server is calling you.", voice='alice') num_of_rigs_under_attack = redis_store.get( "main_dashboard:num_of_rigs_under_attack") if num_of_rigs_under_attack is None: resp.say( "Attack has been detected, but now all rigs are working normally.", voice='alice', loop=10) resp.hangup() elif int(num_of_rigs_under_attack) == 0: resp.say( "Attack has been detected, but now all rigs are working normally.", voice='alice', loop=10) resp.hangup() elif int(num_of_rigs_under_attack) > 0: resp.say( "Attack has been detected, you have {} machines under attack.". format(num_of_rigs_under_attack), voice='alice', loop=10) resp.hangup() return str(resp)
def __init__(self): measure_time_start = time.time() self.dict_of_ip_info_panels = {} self.dict_of_bioses = redis_store.hgetall( "technical_information:dict_of_bioses") self.dict_of_mobo = redis_store.hgetall( "technical_information:dict_of_mobo") self.dict_of_drive_names = redis_store.hgetall( "technical_information:dict_of_drive_names") num_of_rigs = redis_store.get('main_dashboard:num_of_rigs') if num_of_rigs: self.num_of_rigs = int(num_of_rigs) num_of_gpus = redis_store.get('main_dashboard:num_of_gpus') if num_of_gpus: self.num_of_gpus = int(num_of_gpus) num_of_alive_gpus = redis_store.get('main_dashboard:num_of_alive_gpus') if num_of_alive_gpus: self.num_of_alive_gpus = int(num_of_alive_gpus) dict_of_ip_info_all_packed = redis_store.get( "technical_information:dict_of_ip_info_all") if dict_of_ip_info_all_packed: self.dict_of_ip_info_all = json.loads(dict_of_ip_info_all_packed) else: self.dict_of_ip_info_all = {} list_of_alive_panels = redis_store.lrange( 'sidebar_info:list_of_alive_panels', 0, -1) for panel_name in list_of_alive_panels: dict_of_ip_info_packed = redis_store.get( "technical_information:{}:dict_of_ip_info".format( str(panel_name))) if dict_of_ip_info_packed: self.dict_of_ip_info_panels[panel_name] = json.loads( dict_of_ip_info_packed) else: self.dict_of_ip_info_panels[panel_name] = {} measure_time_end = time.time() self.execution_time = round((measure_time_end - measure_time_start), 2)
def voice_crashed_gpus(): # Start our TwiML response resp = VoiceResponse() # Read a message aloud to the caller resp.say("Server is calling you.", voice='alice') num_of_crashed_gpus = redis_store.get("main_dashboard:num_of_crashed_gpus") if num_of_crashed_gpus is None: resp.say("Problem Occurred", voice='alice', loop=10) resp.hangup() elif int(num_of_crashed_gpus) == 0: resp.say("All gpus are working normally now.", voice='alice', loop=10) resp.hangup() elif int(num_of_crashed_gpus) > 0: resp.say("You have {} GPUs crashed.".format(num_of_crashed_gpus), voice='alice', loop=5) resp.hangup() return str(resp)
def set_list_of_nanopool_wallets(): list_of_nanopool_wallets_dict = [] list_of_nanopool_wallets = [] list_of_alive_panels = redis_store.lrange( 'sidebar_info:list_of_alive_panels', 0, -1) panels_info = {} for panel_name in list_of_alive_panels: panels_info[panel_name] = {} list_of_pool_info_packed = redis_store.get( "admin_main_dashboard:{}:unique_poll_info_list".format( str(panel_name))) if list_of_pool_info_packed: panels_info[panel_name]["list_of_pool_info"] = json.loads( list_of_pool_info_packed) else: panels_info[panel_name]["list_of_pool_info"] = [] if panels_info: for panel_name in panels_info: if panels_info[panel_name]["list_of_pool_info"]: for pool_info in panels_info[panel_name]["list_of_pool_info"]: if pool_info.get("proxypool1"): if "nanopool" in pool_info.get("proxypool1"): list_of_nanopool_wallets_dict.append(pool_info) if pool_info.get("proxywallet"): list_of_nanopool_wallets.append( pool_info.get("proxywallet")) redis_store.delete("nanopool_dash:list_of_nanopool_wallets_dict") if list_of_nanopool_wallets_dict: json_str = json.dumps(list_of_nanopool_wallets_dict) redis_store.set("nanopool_dash:list_of_nanopool_wallets_dict", json_str) redis_store.delete("nanopool_dash:list_of_nanopool_wallets") if list_of_nanopool_wallets: redis_store.lpush("nanopool_dash:list_of_nanopool_wallets", *list_of_nanopool_wallets)
def call_crashed_gpus(): is_system_calling = redis_store.get("is_system_already_calling") if is_system_calling is None: redis_store.set("is_system_already_calling", 0) is_system_calling = bool(int(redis_store.get("is_system_already_calling"))) num_of_crashed_gpus = redis_store.get("main_dashboard:num_of_crashed_gpus") if num_of_crashed_gpus is None: num_of_crashed_gpus = 0 else: num_of_crashed_gpus = int(num_of_crashed_gpus) try: client_twilio = Client(str(Config.TWILIO_ACCOUNT_SID), str(Config.TWILIO_AUTH_TOKEN)) is_notified = False try_num = 1 url_with_attack_response = "https://powmining.com/twilio_responses/crashed_gpus" if num_of_crashed_gpus > 0 and is_system_calling is False: while try_num <= 10 and bool( int(redis_store.get("is_system_already_calling")) ) is False and is_notified is False: redis_store.set("is_system_already_calling", 1) save_simple_action( "Attempt to notify about crashed gpus. \nTry № {} \nGPUs crashed {}" .format(try_num, num_of_crashed_gpus)) try_num += 1 if Config.TWILIO_PHONE_NUMBER_1: call_num_1 = client_twilio.calls.create( to=str(Config.TWILIO_PHONE_NUMBER_1), from_=str(Config.TWILIO_PHONE_NUMBER_SERVER), url=url_with_attack_response) time.sleep(40) call_num_1 = client_twilio.calls(call_num_1.sid).fetch() if not (call_num_1.status == "busy" or call_num_1.status == "failed"): call_num_1 = client_twilio.calls( call_num_1.sid).update(status="completed") call_num_1 = client_twilio.calls(call_num_1.sid).fetch() save_simple_action( "Call to {} ended with status {}".format( call_num_1.to, call_num_1.status)) if call_num_1.status == "busy" or call_num_1.status == "completed" \ or call_num_1.status == "in-progress": is_notified = True save_simple_action( "{} has been notified about crashed gpus.".format( call_num_1.to)) else: save_simple_action( "Failed to notify {} about crashed gpus.".format( call_num_1.to)) if Config.TWILIO_PHONE_NUMBER_2 and not is_notified: call_num_2 = client_twilio.calls.create( to=str(Config.TWILIO_PHONE_NUMBER_2), from_=str(Config.TWILIO_PHONE_NUMBER_SERVER), url=url_with_attack_response) time.sleep(40) call_num_2 = client_twilio.calls(call_num_2.sid).fetch() if not (call_num_2.status == "busy" or call_num_2.status == "failed"): call_num_2 = client_twilio.calls( call_num_2.sid).update(status="completed") call_num_2 = client_twilio.calls(call_num_2.sid).fetch() save_simple_action( "Call to {} ended with status {}".format( call_num_2.to, call_num_2.status)) if call_num_2.status == "busy" or call_num_2.status == "completed" \ or call_num_2.status == "in-progress": is_notified = True save_simple_action( "{} has been notified about crashed gpus.".format( call_num_2.to)) else: save_simple_action( " Failed to notify {} about crashed gpus.".format( call_num_2.to)) if Config.TWILIO_PHONE_NUMBER_3 and not is_notified: call_num_3 = client_twilio.calls.create( to=str(Config.TWILIO_PHONE_NUMBER_3), from_=str(Config.TWILIO_PHONE_NUMBER_SERVER), url=url_with_attack_response) time.sleep(40) call_num_3 = client_twilio.calls(call_num_3.sid).fetch() if not (call_num_3.status == "busy" or call_num_3.status == "failed"): call_num_3 = client_twilio.calls( call_num_3.sid).update(status="completed") call_num_3 = client_twilio.calls(call_num_3.sid).fetch() save_simple_action( "Call to {} ended with status {}".format( call_num_3.to, call_num_3.status)) if call_num_3.status == "busy" or call_num_3.status == "completed" \ or call_num_3.status == "in-progress": is_notified = True save_simple_action( "{} has been notified about crashed gpus.".format( call_num_3.to)) else: save_simple_action( " Failed to notify {} about crashed gpus.".format( call_num_3.to)) if Config.TWILIO_PHONE_NUMBER_4 and not is_notified: call_num_4 = client_twilio.calls.create( to=str(Config.TWILIO_PHONE_NUMBER_4), from_=str(Config.TWILIO_PHONE_NUMBER_SERVER), url=url_with_attack_response) time.sleep(40) call_num_4 = client_twilio.calls(call_num_4.sid).fetch() if not (call_num_4.status == 'busy' or call_num_4.status == 'failed'): call_num_4 = client_twilio.calls( call_num_4.sid).update(status="completed") call_num_4 = client_twilio.calls(call_num_4.sid).fetch() save_simple_action( "Call to {} ended with status {}".format( call_num_4.to, call_num_4.status)) if call_num_4.status == "busy" or call_num_4.status == "completed" \ or call_num_4.status == "in-progress": is_notified = True save_simple_action( "{} has been notified about crashed gpus.".format( call_num_4.to)) else: save_simple_action( " Failed to notify {} about crashed gpus.".format( call_num_4.to)) if Config.TWILIO_PHONE_NUMBER_5 and not is_notified: call_num_5 = client_twilio.calls.create( to=str(Config.TWILIO_PHONE_NUMBER_5), from_=str(Config.TWILIO_PHONE_NUMBER_SERVER), url=url_with_attack_response) time.sleep(40) call_num_5 = client_twilio.calls(call_num_5.sid).fetch() if not (call_num_5.status == "busy" or call_num_5 == "failed"): call_num_5 = client_twilio.calls( call_num_5.sid).update(status="completed") call_num_5 = client_twilio.calls(call_num_5.sid).fetch() save_simple_action( "Call to {} ended with status {}".format( call_num_5.to, call_num_5.status)) if call_num_5.status == "busy" or call_num_5.status == "completed" \ or call_num_5.status == "in-progress": is_notified = True save_simple_action( "{} has been notified about crashed gpus.".format( call_num_5.to)) else: save_simple_action( " Failed to notify {} about crashed gpus.".format( call_num_5.to)) redis_store.set("is_system_already_calling", 0) else: print("No GPUs crashed.all OK.") except Exception as e: redis_store.set("is_system_already_calling", 0) print(e) print("Exception occurred while trying to notify about crashed gpus.") pass