From f16af6711e47ffcea37a59595c4a6a73b7377eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCspert?= Date: Wed, 16 Jun 2021 06:39:46 +0200 Subject: [PATCH 1/3] added option to set port --- check_opnsense.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/check_opnsense.py b/check_opnsense.py index 50792da..2d2cee7 100755 --- a/check_opnsense.py +++ b/check_opnsense.py @@ -51,7 +51,7 @@ class NagiosState(Enum): class CheckOPNsense: VERSION = '0.1.0' - API_URL = 'https://{}/api/{}' + API_URL = 'https://{}:{}/api/{}' options = {} perfdata = [] @@ -74,7 +74,7 @@ def output(self, returnCode, message): sys.exit(returnCode.value) def getURL(self, part): - return self.API_URL.format(self.options.hostname, part) + return self.API_URL.format(self.options.hostname, self.options.port, part) def request(self, url, method='get', **kwargs): response = None @@ -134,6 +134,7 @@ def parseOptions(self): api_opts = p.add_argument_group('API Options') api_opts.add_argument("-H", "--hostname", required=True, help="OPNsense hostname or ip address") + api_opts.add_argument("-p", "--port", required=False, dest='port', help="OPNsense https-api port", default=80) api_opts.add_argument("--api-key", dest='api_key', required=True, help="API key (See OPNsense user manager)") api_opts.add_argument("--api-secret", dest='api_secret', required=True, @@ -178,3 +179,4 @@ def __init__(self): opnsense = CheckOPNsense() opnsense.check() + From 41c4ceea9337d4b6751b123b5ac35a9e067b5397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCspert?= Date: Wed, 16 Jun 2021 06:46:40 +0200 Subject: [PATCH 2/3] added documentation of port-option --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06659ff..cb374d1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ yum install python-enum34 python-requests The ``icinga2`` folder contains the command defintion and service examples for use with Icinga2. ```shell -usage: check_opnsense.py [-h] -H HOSTNAME --api-key API_KEY --api-secret +usage: check_opnsense.py [-h] -H HOSTNAME [-p PORT] --api-key API_KEY --api-secret API_SECRET [-k] -m {updates} [-w TRESHOLD_WARNING] [-c TRESHOLD_CRITICAL] @@ -40,6 +40,8 @@ optional arguments: API Options: -H HOSTNAME, --hostname HOSTNAME OPNsense hostname or ip address + -H PORT, --port PORT OPNsense https-api port + OPNsense hostname or ip address --api-key API_KEY API key (See OPNsense user manager) --api-secret API_SECRET API key (See OPNsense user manager) From f38d1f4326a9c3b346fc260251df6e5094bb8b7f Mon Sep 17 00:00:00 2001 From: Nicolai Date: Tue, 29 Jun 2021 12:57:19 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb374d1..d45d624 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ optional arguments: API Options: -H HOSTNAME, --hostname HOSTNAME OPNsense hostname or ip address - -H PORT, --port PORT OPNsense https-api port + -p PORT, --port PORT OPNsense https-api port OPNsense hostname or ip address --api-key API_KEY API key (See OPNsense user manager) --api-secret API_SECRET