Skip to content

Commit

Permalink
Merge pull request #2 from l13t/bug/exitcode-unreachable
Browse files Browse the repository at this point in the history
Bug/exitcode unreachable
  • Loading branch information
l13t authored May 24, 2020
2 parents f27a4da + 851e6b6 commit f430772
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ optional arguments:
-t TIMEOUT, --timeout TIMEOUT
Timeout for request. Default 10 seconds

check_pihole.py: v.0.2.0 by Dmytro Prokhorenkov
check_pihole.py: v.0.2.1 by Dmytro Prokhorenkov
```
34 changes: 22 additions & 12 deletions check_pihole.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
import urllib3

__author__ = 'Dmytro Prokhorenkov'
__version__ = '0.2.0'
__version__ = '0.2.1'

EXIT_STATUS = {
0: "OK",
1: "WARNING",
2: "CRITICAL",
3: "UNKNOWN"
}


def parse_args():
Expand All @@ -27,7 +34,7 @@ def parse_args():

def gtfo(exitcode, message=''):
if message:
print(message)
print(''.join([EXIT_STATUS[exitcode], ":", " ", message]))
exit(exitcode)


Expand All @@ -45,16 +52,19 @@ def check_pihole(host, port, _timeout):
def main():
args = parse_args()
exitcode, url_output = check_pihole(args.host, args.port, args.timeout)
message = "OK: "
if url_output["status"] != "enabled":
if args.pihole_status:
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"]) + \
"|queries=" + str(url_output["dns_queries_all_types"]) + " blocked=" + str(url_output["ads_blocked_today"])
message = ""
if exitcode == 2:
message = url_output
else:
if url_output["status"] != "enabled":
if args.pihole_status:
exitcode = 2
else:
exitcode = 1
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"]) + \
"|queries=" + str(url_output["dns_queries_all_types"]) + " blocked=" + str(url_output["ads_blocked_today"])
gtfo(exitcode, message)


Expand Down

0 comments on commit f430772

Please sign in to comment.