Skip to content

Commit

Permalink
Added option to be critical if pi-hole is disabled
Browse files Browse the repository at this point in the history
* added option to force critical if pi-hole is disabled
* added option to force warning if pi-hole is disabled
* fixed readme and help messages
  • Loading branch information
l13t committed Mar 4, 2019
1 parent 43db396 commit 1392228
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
Icinga2/Nagios plugin to check Pi-hole status.

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

Check for OOM killer events
Check Pi-hole status

optional arguments:
-h, --help show this help message and exit
-H HOST, --host HOST PiHole ip address or hostname
-H HOST, --host HOST Pi-hole ip address or hostname
-C, --status_critical
Forces CRITICAL when Pi-hole is disabled
-W, --status_warning Forces WARNING when Pi-hole is disabled
-t TIMEOUT, --timeout TIMEOUT
Timeout for request
Timeout for request. Default 10 seconds

check_pihole.py: v.0.1.1 by Dmytro Prokhorenkov
```
check_pihole.py: v.0.1.2 by Dmytro Prokhorenkov
```
16 changes: 11 additions & 5 deletions check_pihole.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import sys, urllib3, base64, re, argparse, json

__author__ = 'Dmytro Prokhorenkov'
__version__= '0.1.1'
__version__= '0.1.2'

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 = argparse.ArgumentParser(add_help=True, description='Check Pi-hole status', epilog='{0}: v.{1} by {2}'.format('check_pihole.py', __version__, __author__))
argp.add_argument('-H', '--host', type=str, help="Pi-hole ip address or hostname")
argp.add_argument('-C', '--status_critical', dest='pihole_status', help="Forces CRITICAL when Pi-hole is disabled", action='store_true')
argp.add_argument('-W', '--status_warning', dest='pihole_status', help="Forces WARNING when Pi-hole is disabled", action='store_false')
argp.add_argument('-t', '--timeout', default=10, type=int, help='Timeout for request. Default 10 seconds')
argp.set_defaults(pihole_status=False)
args = argp.parse_args()
if (args.host == None):
argp.print_help()
Expand All @@ -35,8 +38,11 @@ def main():
exitcode, url_output = check_pihole(args.host, args.timeout)
message = "OK: "
if url_output["status"] != "enabled":
message = "WARNING: "
message = message + "PiHole is " + url_output["status"] + ": queries today - " + str(url_output["dns_queries_all_types"]) + ", domains blocked: " + str(url_output["ads_blocked_today"]) + ", percentage blocked: " + str(url_output["ads_percentage_today"])
if args.pihole_status == True:
message = "CRITICAL: "
else:
message = "WARNING: "
message = message + "Pi-hole is " + url_output["status"] + ": queries today - " + str(url_output["dns_queries_all_types"]) + ", domains blocked: " + str(url_output["ads_blocked_today"]) + ", percentage blocked: " + str(url_output["ads_percentage_today"])
gtfo(exitcode, message)

if __name__ == '__main__':
Expand Down

0 comments on commit 1392228

Please sign in to comment.