Allow filtering by domain

This commit is contained in:
Adam Goldsmith 2024-12-19 18:50:50 -05:00
parent e3d9312a1e
commit 307234ecdf

View File

@ -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,