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): class Entities(nagiosplugin.Resource):
url: str url: str
token: str token: str
domain: str
device_class: str device_class: str
numeric: bool numeric: bool
area: str area: str
@ -149,6 +150,8 @@ class Entities(nagiosplugin.Resource):
def probe(self): def probe(self):
template_filter = "states" template_filter = "states"
if self.domain:
template_filter += f"|selectattr('domain', 'eq', '{ self.domain }')"
if self.device_class: if self.device_class:
template_filter += ( template_filter += (
f"|selectattr('attributes.device_class', 'eq', '{ self.device_class }')" f"|selectattr('attributes.device_class', 'eq', '{ self.device_class }')"
@ -351,6 +354,12 @@ def main():
common_args = shared_parser.add_argument_group( common_args = shared_parser.add_argument_group(
"Common Arguments", "Arguments shared between metric types" "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( common_args.add_argument(
"-d", "-d",
"--device-class", "--device-class",
@ -453,6 +462,7 @@ def main():
args = argp.parse_args() args = argp.parse_args()
parsed_common_args = { parsed_common_args = {
"domain": args.domain,
"device_class": args.device_class, "device_class": args.device_class,
"attribute": args.attribute, "attribute": args.attribute,
"filters": args.filter, "filters": args.filter,