Make device-class not required
This commit is contained in:
parent
75da5babd0
commit
d83831620a
@ -142,13 +142,17 @@ 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.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 += (
|
||||
@ -351,7 +355,7 @@ def main():
|
||||
"-d",
|
||||
"--device-class",
|
||||
type=str,
|
||||
required=True,
|
||||
required=False,
|
||||
help="device class of entities to monitor",
|
||||
)
|
||||
common_args.add_argument(
|
||||
@ -469,7 +473,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 +483,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