From ce85536112947418fa80d4c2ded5aab5f0bfaed6 Mon Sep 17 00:00:00 2001 From: Blade Doyle Date: Thu, 26 Nov 2020 10:06:34 -0800 Subject: [PATCH] add grin-health --- config.yml | 3 ++- grin_nicehash_defender.py | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/config.yml b/config.yml index 022445e..4182824 100644 --- a/config.yml +++ b/config.yml @@ -17,10 +17,11 @@ VERBOSE: False # Print lots of debugging data - WARNINIG: "True" Prints NiceHash API keys!! ORDER_PRICE_ADD: 0.0005 # BTC - Amount to set order price over the absolute minimum LOOP_INTERVAL: 60 # Seconds - Sleep this long between control loop runs - CHECK_TYPE: "grin51" # Method of detecting an attack: + CHECK_TYPE: "all" # Method of detecting an attack: # "grin51": run the grin51 detection algorithm locally # "grin-health": use the public grin-health score service api # "file": for debugging, check for file called "./attack" + # "all": Use all available methods and alert on any of them # --- Attack Detection Module Configuration diff --git a/grin_nicehash_defender.py b/grin_nicehash_defender.py index 86bf9f1..8cf8cb0 100755 --- a/grin_nicehash_defender.py +++ b/grin_nicehash_defender.py @@ -70,7 +70,7 @@ def getConfig(self): if self.nh_pool_id is None: logger.error("Failed to find pool {} in your NiceHash account".format(self.config["POOL_NAME"])) sys.exit(1) - if self.config["CHECK_TYPE"] == "grin51": + if self.config["CHECK_TYPE"] in ["grin51", "all"]: logger.warning("Loading Grin51 detection module") from grin51 import Grin51 self.grin51 = Grin51(self.config["GRIN51_SCORE_THREASHOLD"], self.config["GRIN51_MIN_HISTORY"], self.config["GRIN51_MAX_HISTORY"]) @@ -79,27 +79,25 @@ def getConfig(self): def checkForAttack(self): attack = False - if self.config["CHECK_TYPE"] == "file": + if self.config["CHECK_TYPE"] in ["file", "all"]: file_stats = {"exists": False} if os.path.exists('attack'): attack = True file_stats["exists"] = True self.attack_stats["file"] = file_stats - elif self.config["CHECK_TYPE"] == "grin51": - attack = self.grin51.under_attack - self.attack_stats = self.grin51.get_stats() - elif self.config["CHECK_TYPE"] == "grin-health": + if self.config["CHECK_TYPE"] in ["grin51", "all"]: + if self.grin51.under_attack: + attack = True + self.attack_stats["grin51"] = self.grin51.get_stats() + if self.config["CHECK_TYPE"] in ["grin-health", "all"]: status_url = self.config["GRINHEALTH_URL"] try: r = requests.get(status_url) - self.attack_stats = r.json() - attack = self.attack_stats["overall_score"] <= int(self.config["GRINHEALTH_SCORE_THREASHOLD"]) + self.attack_stats["grin-health"] = r.json() + if int(self.attack_stats["grin-health"]["overall_score"]) <= int(self.config["GRINHEALTH_SCORE_THREASHOLD"]): + attack = True except Exception as e: - logger.warning("Error: Failed to call grin-heal status api: {}".format(e)) - attack = False - else: - logger.error("Unknown attack detection method: {}".format(self.config["CHECK_TYPE"])) - sys.exit(1) + logger.warning("Error: Failed to call grin-health status api: {}".format(e)) # Set some values for attack state if attack: self.under_attack = True