From 16c0f33b9ea22a80c273fc46b009a7b7e60a2573 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 01:22:51 +0200 Subject: [PATCH 01/10] doc: Add NRPE example Signed-off-by: Julien Riou --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 75cca6b..2718a0f 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ sudo apt-get install python3-nagiosplugin python3-requests ./check_trex --help ``` +# Examples + +Nagios NRPE: + +``` +command[check_trex]=/opt/check_trex/check_trex.py --hashrate-warning 60000000 --hashrate-critical 50000000 --uptime-critical 300 --uptime-warning 600 +``` + # Contributing ``` From 49434421358864a8607f233ba054052fb12c66dc Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 01:29:54 +0200 Subject: [PATCH 02/10] feat: Add memory temperature checks Signed-off-by: Julien Riou --- .pre-commit-config.yaml | 4 ---- check_trex.py | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 28f0166..e010821 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,3 @@ repos: rev: 22.3.0 hooks: - id: black - - repo: https://github.com/pycqa/isort - rev: 5.10.1 - hooks: - - id: isort diff --git a/check_trex.py b/check_trex.py index de8bb5f..1c2d38a 100755 --- a/check_trex.py +++ b/check_trex.py @@ -5,8 +5,15 @@ import logging import sys import requests -from nagiosplugin import (Check, Context, Metric, Performance, Resource, - ScalarContext, Summary) +from nagiosplugin import ( + Check, + Context, + Metric, + Performance, + Resource, + ScalarContext, + Summary, +) from nagiosplugin.state import Critical, Ok, Unknown, Warn logger = logging.getLogger(__name__) @@ -289,6 +296,11 @@ def main(): warning=args.temperature_warning, critical=args.temperature_critical, ), + ScalarContext( + "memory_temperature", + warning=args.memory_temperature_warning, + critical=args.memory_temperature_critical, + ), TrexSummary(), ) check.main() From 7c5a19787242547d4755ba309f388ee8acbebf11 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 01:30:48 +0200 Subject: [PATCH 03/10] chore: Bump to 1.0.1 Signed-off-by: Julien Riou --- check_trex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_trex.py b/check_trex.py index 1c2d38a..913fc0a 100755 --- a/check_trex.py +++ b/check_trex.py @@ -135,7 +135,7 @@ def setup_logging(args): def show_version(): - print("1.0.0") + print("1.0.1") class BelowThresholdContext(Context): From 04446c932996d1a63d0fe7ca110018b7f217da72 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 09:43:48 +0200 Subject: [PATCH 04/10] doc: Fix typo in usage Signed-off-by: Julien Riou --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2718a0f..fbd2a55 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ sudo apt-get install python3-nagiosplugin python3-requests # Usage ``` -./check_trex --help +./check_trex.py --help ``` # Examples From 98483e327965891862dd810766c0aa6d9c698c2f Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 11:26:19 +0200 Subject: [PATCH 05/10] fix: Typo in memory temperature management (#1) Signed-off-by: Julien Riou --- check_trex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_trex.py b/check_trex.py index 913fc0a..0836358 100755 --- a/check_trex.py +++ b/check_trex.py @@ -239,7 +239,7 @@ class Trex(Resource): ) if "memory_temperature" in gpu: - temperature = gpu["memory_temperature"] + memory_temperature = gpu["memory_temperature"] logger.debug( f"Memory temperature of {name} ({id}) is {memory_temperature}C" ) From 6f0930187950a442508e1f276550bcf0e487ecba Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 11:30:39 +0200 Subject: [PATCH 06/10] feat: Add GPU ID to temperatures Signed-off-by: Julien Riou --- check_trex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_trex.py b/check_trex.py index 0836358..f3b5733 100755 --- a/check_trex.py +++ b/check_trex.py @@ -235,7 +235,7 @@ class Trex(Resource): temperature = gpu["temperature"] logger.debug(f"Temperature of {name} ({id}) is {temperature}C") metrics.append( - Metric("temperature", temperature, context="temperature") + Metric(f"temperature_{id}", temperature, context="temperature") ) if "memory_temperature" in gpu: @@ -245,7 +245,7 @@ class Trex(Resource): ) metrics.append( Metric( - "memory_temperature", + f"memory_temperature_{id}", memory_temperature, context="memory_temperature", ) From 9af285c49d7d68c4f67980eac4c03774bcbe05be Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 11:32:03 +0200 Subject: [PATCH 07/10] chore: Bump version to 1.0.2 Signed-off-by: Julien Riou --- check_trex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_trex.py b/check_trex.py index f3b5733..babf15e 100755 --- a/check_trex.py +++ b/check_trex.py @@ -135,7 +135,7 @@ def setup_logging(args): def show_version(): - print("1.0.1") + print("1.0.2") class BelowThresholdContext(Context): From 15f3746f2eb29a982d601a94fe1cd9d043bfa79d Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 11:46:15 +0200 Subject: [PATCH 08/10] chore: Move logging to info level - Extracted values are set to info level - Full API response is still set to debug level Signed-off-by: Julien Riou --- check_trex.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/check_trex.py b/check_trex.py index babf15e..c3bb868 100755 --- a/check_trex.py +++ b/check_trex.py @@ -202,29 +202,29 @@ class Trex(Resource): if "hashrate" in data: hashrate = data["hashrate"] - logger.debug(f"Hashrate is {hashrate}") + logger.info(f"Hashrate is {hashrate}") metrics.append(Metric("hashrate", hashrate, context="hashrate")) if "success" in data: success = bool(data["success"]) if success: - logger.debug("T-Rex is successfully started") + logger.info("T-Rex is successfully started") else: - logger.debug("T-Rex is not successfully started") + logger.info("T-Rex is not successfully started") metrics.append(Metric("success", success, context="success")) if "paused" in data: paused = bool(data["paused"]) if paused: - logger.debug("T-Rex is paused") + logger.info("T-Rex is paused") else: - logger.debug("T-Rex is not paused") + logger.info("T-Rex is not paused") metrics.append(Metric("paused", paused, context="paused")) if "uptime" in data: uptime = data["uptime"] seconds = "seconds" if uptime > 1 else "second" - logger.debug(f"Uptime is {uptime} {seconds}") + logger.info(f"Uptime is {uptime} {seconds}") metrics.append(Metric("uptime", uptime, context="uptime")) for gpu in data.get("gpus"): @@ -233,15 +233,15 @@ class Trex(Resource): if "temperature" in gpu: temperature = gpu["temperature"] - logger.debug(f"Temperature of {name} ({id}) is {temperature}C") + logger.info(f"GPU {id} ({name}): temperature is {temperature}C") metrics.append( Metric(f"temperature_{id}", temperature, context="temperature") ) if "memory_temperature" in gpu: memory_temperature = gpu["memory_temperature"] - logger.debug( - f"Memory temperature of {name} ({id}) is {memory_temperature}C" + logger.info( + f"GPU {id} ({name}): memory temperature is {memory_temperature}C" ) metrics.append( Metric( From 2c78fccd1ef97b05b48e3ba8837807d70adb8b28 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 11:47:12 +0200 Subject: [PATCH 09/10] doc: Add T-Rex API security Signed-off-by: Julien Riou --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index fbd2a55..34e4440 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,22 @@ Nagios check for [T-Rex miner](https://github.com/trexminer/T-Rex). +# Security + +T-Rex API must be opened in a secured way: +* `--api-read-only`: accessible only in read-only, no modification +* `--api-bind-http 127.0.0.1:4067`: (default) accessible only to local connections + +If the check is executed **remotely**, you should add a **firewall rule** to allow only the host running the check to +access the T-Rex API port. + +**HTTPS** should be used: +* `--api-https` +* `--api-webserver-cert` +* `--api-webserver-pkey` + +See full [list of options](https://github.com/trexminer/T-Rex#usage). + # Installation Using pip: From f62623af386989db571fb65c79a105ea25cf5849 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Sat, 14 May 2022 11:49:20 +0200 Subject: [PATCH 10/10] chore: Bump version to 1.0.3 Signed-off-by: Julien Riou --- check_trex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_trex.py b/check_trex.py index c3bb868..2a5bbea 100755 --- a/check_trex.py +++ b/check_trex.py @@ -135,7 +135,7 @@ def setup_logging(args): def show_version(): - print("1.0.2") + print("1.0.3") class BelowThresholdContext(Context):