Updated Stats monitoring in check_mk_agent (markdown)

Steve Berg 2016-07-04 12:53:30 -05:00
parent 6cb06408b9
commit e31a0fa036
1 changed files with 16 additions and 7 deletions

@ -1,6 +1,6 @@
I've written this extremely simple local check for the check_mk_agent. If you've installed the agent on your Pi-Hole place this into an executable file wherever your check_mk_agent expects to find local plugins. Alternatively this could be installed on any system that has access to the Pi-Hole console, I decided to put it on the Pi-Hole directly. I named mine "mk_pihole_stats.py" but as long as it's in the correct subdirectory and the agent script can execute it it should work just fine.
After you reinventory the client where you installed this you should have two new local checks. PiHole_Ads and PiHole_Percent.
After you reinventory the client where you installed this you should have three new local checks. PiHole_Ads, PiHole_Percent and PiHole_Queries.
#!/usr/bin/python
# Simple (always OK) check_mk local check to track # of ads blocked today.
@ -9,6 +9,7 @@ After you reinventory the client where you installed this you should have two ne
import urllib2
import json
import re
# Define your Pi-Hole console address
console = "http://192.168.1.2/admin/"
@ -17,15 +18,23 @@ After you reinventory the client where you installed this you should have two ne
url = console + "api.php"
result = urllib2.urlopen(url, timeout = 5).read()
json = json.loads(result)
count = json['ads_blocked_today']
print "0 PiHole_Ads blocked=" + count + " OK " + count + " ads blocked today."
count2 = re.sub(',', '', count)
print "0 PiHole_Ads ads_blocked=" + count2 + " OK - " + count + " ads blocked today."
pct = json['ads_percentage_today']
print "0 PiHole_Percent percent=" + pct + " OK " + pct + "%."
print "0 PiHole_Percent ads_percent=" + pct + " OK - " + pct + "% of dns requests were for ad domains."
queries = json['dns_queries_today']
queries2 = re.sub(',', '', queries)
print "0 PiHole_DNS queries=" + queries2 + " OK " + queries + " DNS queries today."
except:
print "3 PiHole_Ads Unknown"
After the logs rotated for the first time since I started using this check the ads_blocked_today perf data zero'd out. I'm not quite sure why yet though, check_mk should still see previous values even if current values are zero.
I'll probably let it run for a few more days without modifying anything to see if it was a temporary glitch or if I've done something wrong here. Added: After the next log rotation the stats behaved as I expected them to. Once I get a week of stats I'll post the performance graphs that pnp4nagios generates.
After the logs rotated for the first time since I started using this check the ads_blocked_today perf data zero'd out. I'm not quite sure why yet though, check_mk should still see previous values even if current values are zero.
Found the problem. The script was returning ads_blocked and queries values with commas "," in them. Check_mk doesn't like that. So I've stripped the comma out of each returned number and it looks much better now.