Skip to content

Commit

Permalink
add grin-health
Browse files Browse the repository at this point in the history
  • Loading branch information
bladedoyle committed Nov 26, 2020
1 parent cff5b92 commit ce85536
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
3 changes: 2 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 11 additions & 13 deletions grin_nicehash_defender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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
Expand Down

0 comments on commit ce85536

Please sign in to comment.