From 502bff1422e1df71ae2f2be7c291322c2ed9ac6a 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.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) 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)