diff --git a/README.md b/README.md index 06659ff..d45d624 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 + -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 API key (See OPNsense user manager) 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() +