From 5eb9c522076c6540c0d3753e35c49eb1389cedbb Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 26 Nov 2022 19:40:57 -0500 Subject: [PATCH] Add cli args for specifying performance data min/max --- check_home_assistant_state.conf | 8 ++++++++ check_home_assistant_state.py | 25 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/check_home_assistant_state.conf b/check_home_assistant_state.conf index c79b9f4..a675ce1 100644 --- a/check_home_assistant_state.conf +++ b/check_home_assistant_state.conf @@ -17,5 +17,13 @@ object CheckCommand "home_assistant_state" { value = "$home_assistant_state_critical$" description = "Return critical if battery percentage is outside RANGE" } + "--min" = { + value = "$home_assistant_state_min$" + description = "Min for performance data" + } + "--max" = { + value = "$home_assistant_state_max$" + description = "Max for performance data" + } } } \ No newline at end of file diff --git a/check_home_assistant_state.py b/check_home_assistant_state.py index 6a45dbe..193dfd5 100755 --- a/check_home_assistant_state.py +++ b/check_home_assistant_state.py @@ -16,6 +16,8 @@ _log = logging.getLogger("nagiosplugin") class Entities(nagiosplugin.Resource): url: str token: str + min: float + max: float def hass_get(self, endpoint: str) -> requests.Response: headers = { @@ -47,9 +49,9 @@ class Entities(nagiosplugin.Resource): state["entity_id"], float(state["state"]) if state["state"].isnumeric() else -1, uom=state["attributes"].get("unit_of_measurement"), - min=0, - max=100, context="battery", + min=self.min, + max=self.max, ) @@ -78,12 +80,27 @@ def main(): required=True, help="return critical if battery percentage is outside RANGE", ) + argp.add_argument( + "--min", + type=float, + help="Min for performance data", + ) + argp.add_argument( + "--max", + type=float, + help="Max for performance data", + ) args = argp.parse_args() check = nagiosplugin.Check( - Entities(args.url, args.token), - nagiosplugin.ScalarContext("battery", args.warning, args.critical), + Entities( + args.url, + args.token, + args.min, + args.max, + ), + nagiosplugin.ScalarContext(args.device_class, args.warning, args.critical), ) check.main(args.verbose)