Compare commits
2 Commits
307234ecdf
...
9035396156
Author | SHA1 | Date | |
---|---|---|---|
9035396156 | |||
d83831620a |
@ -66,6 +66,7 @@ class AttributeFilter:
|
||||
class Entities(nagiosplugin.Resource):
|
||||
url: str
|
||||
token: str
|
||||
domain: str
|
||||
device_class: str
|
||||
numeric: bool
|
||||
area: str
|
||||
@ -142,13 +143,19 @@ class Entities(nagiosplugin.Resource):
|
||||
name,
|
||||
value,
|
||||
uom,
|
||||
context=self.device_class,
|
||||
context="scalar_entities" if self.numeric else "text_entities",
|
||||
min=self.min,
|
||||
max=self.max,
|
||||
)
|
||||
|
||||
def probe(self):
|
||||
template_filter = f"states|selectattr('attributes.device_class', 'eq', '{ self.device_class }')"
|
||||
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 }')"
|
||||
)
|
||||
for f in self.filters:
|
||||
op = "ne" if f.negated else "eq"
|
||||
template_filter += (
|
||||
@ -347,11 +354,17 @@ 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",
|
||||
type=str,
|
||||
required=True,
|
||||
required=False,
|
||||
help="device class of entities to monitor",
|
||||
)
|
||||
common_args.add_argument(
|
||||
@ -449,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,
|
||||
@ -469,7 +483,7 @@ def main():
|
||||
max=args.max,
|
||||
**parsed_common_args,
|
||||
),
|
||||
ScalarOrUnknownContext(args.device_class, args.warning, args.critical),
|
||||
ScalarOrUnknownContext("scalar_entities", args.warning, args.critical),
|
||||
)
|
||||
elif args.subparser_name == "text":
|
||||
check = nagiosplugin.Check(
|
||||
@ -479,7 +493,7 @@ def main():
|
||||
numeric=False,
|
||||
**parsed_common_args,
|
||||
),
|
||||
RegexContext(args.device_class, args.ok, args.warning, args.critical),
|
||||
RegexContext("text_entities", args.ok, args.warning, args.critical),
|
||||
)
|
||||
|
||||
check.main(args.verbose)
|
||||
|
Loading…
Reference in New Issue
Block a user