Skip to content

Commit

Permalink
Added timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
l13t committed Mar 3, 2019
1 parent 26b75a5 commit 43db396
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# icinga2_check_pihole

Icinga2/Nagios plugin to check Pi-hole status.

```bash
usage: check_pihole.py [-h] [-H HOST] [-t TIMEOUT]

Check for OOM killer events

optional arguments:
-h, --help show this help message and exit
-H HOST, --host HOST PiHole ip address or hostname
-t TIMEOUT, --timeout TIMEOUT
Timeout for request

check_pihole.py: v.0.1.1 by Dmytro Prokhorenkov
```
8 changes: 4 additions & 4 deletions check_pihole.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def parse_args():
argp = argparse.ArgumentParser(add_help=True, description='Check for OOM killer events', epilog='{0}: v.{1} by {2}'.format('check_pihole.py', __version__, __author__))
argp.add_argument('-H', '--host', type=str, help="PiHole ip address or hostname")
argp.add_argument('-t', '--timeout', default=500, type=int, help='Timeout for request')
argp.add_argument('-t', '--timeout', default=10, type=int, help='Timeout for request. Default 10 seconds')
args = argp.parse_args()
if (args.host == None):
argp.print_help()
Expand All @@ -20,15 +20,15 @@ def gtfo(exitcode, message=''):
print(message)
exit(exitcode)

def check_pihole(host, timeout):
def check_pihole(host, _timeout):
status_url = 'http://' + host + '/admin/api.php?summaryRaw'
try:
request = urllib3.PoolManager()
content = request.request('GET', status_url)
content = request.request('GET', status_url, timeout=_timeout)
decoded = json.loads(content.data)
return 0, decoded
except Exception:
return 2, "Problems with accessing API"
return 2, "Problems with accessing API: Check if server is running."

def main():
args = parse_args()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
urllib3

0 comments on commit 43db396

Please sign in to comment.