Skip to content

Commit

Permalink
Merge pull request #4 from jenskuespert/master
Browse files Browse the repository at this point in the history
port could be configurable
  • Loading branch information
nbuchwitz authored Jun 30, 2021
2 parents fc3e189 + f38d1f4 commit cded7c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions check_opnsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class NagiosState(Enum):

class CheckOPNsense:
VERSION = '0.1.0'
API_URL = 'https://{}/api/{}'
API_URL = 'https://{}:{}/api/{}'

options = {}
perfdata = []
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -178,3 +179,4 @@ def __init__(self):

opnsense = CheckOPNsense()
opnsense.check()

0 comments on commit cded7c2

Please sign in to comment.