Add cli args for specifying performance data min/max

This commit is contained in:
Adam Goldsmith 2022-11-26 19:40:57 -05:00
parent 1c183fb6b4
commit 502bff1422

View File

@ -16,6 +16,8 @@ _log = logging.getLogger("nagiosplugin")
class Entities(nagiosplugin.Resource):
url: str
token: str
min: float
max: float
def hass_get(self, endpoint: str) -> requests.Response:
headers = {
@ -47,9 +49,9 @@ class Entities(nagiosplugin.Resource):
state["entity_id"],
float(state["state"]) if state["state"].isnumeric() else -1,
uom=state["attributes"].get("unit_of_measurement"),
min=0,
max=100,
context="battery",
min=self.min,
max=self.max,
)
@ -78,12 +80,27 @@ def main():
required=True,
help="return critical if battery percentage is outside RANGE",
)
argp.add_argument(
"--min",
type=float,
help="Min for performance data",
)
argp.add_argument(
"--max",
type=float,
help="Max for performance data",
)
args = argp.parse_args()
check = nagiosplugin.Check(
Entities(args.url, args.token),
nagiosplugin.ScalarContext("battery", args.warning, args.critical),
Entities(
args.url,
args.token,
args.min,
args.max,
),
nagiosplugin.ScalarContext(args.device_class, args.warning, args.critical),
)
check.main(args.verbose)