Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: handle changed opnsense api since 22.7.x #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions check_opnsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

# ------------------------------------------------------------------------------
# check_opnsense.py - A check plugin for monitoring OPNsense firewalls.
# Copyright (C) 2018 Nicolai Buchwitz <[email protected]>
# Copyright (C) 2018 - 2024 Nicolai Buchwitz <[email protected]>
#
# Version: 0.1.0
# Version: 0.2.0
#
# ------------------------------------------------------------------------------
# This program is free software; you can redistribute it and/or
Expand Down Expand Up @@ -55,7 +55,7 @@ class CheckState(Enum):
class CheckOPNsense:
"""Check command for OPNsense."""

VERSION = "0.1.0"
VERSION = "0.2.0"
API_URL = "https://{host}:{port}/api/{uri}"

def check_output(self) -> None:
Expand Down Expand Up @@ -211,15 +211,19 @@ def check_updates(self) -> None:
url = self.get_url("core/firmware/status")
data = self.request(url)

if data["status"] == "ok" and data["status_upgrade_action"] == "all":
count = data["updates"]
if data["status"] == "none":
# no update information available -> trigger check
data = self.request(url, method="post")

has_update = data["status"] in ("update", "upgrade")
needs_reboot = data["status_reboot"] == "1"

if has_update:
self.check_result = CheckState.WARNING
self.check_message = "{} pending updates".format(count)
self.check_message = data["status_msg"]

if data["upgrade_needs_reboot"]:
if needs_reboot:
self.check_result = CheckState.CRITICAL
self.check_message = "{}. Subsequent reboot required.".format(self.check_message)
else:
self.check_message = "System up to date"

Expand Down