From 307234ecdf3ea0ec171befb030142802f713260c Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 19 Dec 2024 18:50:50 -0500 Subject: [PATCH] Allow filtering by domain --- check_home_assistant_state.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/check_home_assistant_state.py b/check_home_assistant_state.py index 11a69dc..a75ecfc 100755 --- a/check_home_assistant_state.py +++ b/check_home_assistant_state.py @@ -66,6 +66,7 @@ class AttributeFilter: class Entities(nagiosplugin.Resource): url: str token: str + domain: str device_class: str numeric: bool area: str @@ -149,6 +150,8 @@ class Entities(nagiosplugin.Resource): def probe(self): template_filter = "states" + if self.domain: + template_filter += f"|selectattr('domain', 'eq', '{ self.domain }')" if self.device_class: template_filter += ( f"|selectattr('attributes.device_class', 'eq', '{ self.device_class }')" @@ -351,6 +354,12 @@ def main(): common_args = shared_parser.add_argument_group( "Common Arguments", "Arguments shared between metric types" ) + common_args.add_argument( + "--domain", + type=str, + required=False, + help="domain of entities to monitor", + ) common_args.add_argument( "-d", "--device-class", @@ -453,6 +462,7 @@ def main(): args = argp.parse_args() parsed_common_args = { + "domain": args.domain, "device_class": args.device_class, "attribute": args.attribute, "filters": args.filter,