Fail to revert the basic information on the dashboard page

For the purpose of service monitoring, we set up the dashboard page (IP:Port/index.php) to search for the "Active" word. When our customs script finds the word, it means to us that the service is up and running and whenever it fails to find such a word, it indicates to us that the service is down.

We recently updated the Pi-hole to "Docker Tag 2022.10" and it turned out the dashboard page will always be redirected to the login page, asks for a password and doesn't show the basic information we were looking for.

How can we set up service monitoring now?

Is there a setting or configuration we can apply to so we can see the basic information without typing in our password on the dashboard page or do we simply need to downgrade to the previous version if we want to have the method to monitor the service?

The dashboard now requires authentication to view, see announcement from a couple of months back.

Is there any way you can monitor the services on the Pi-hole directly. eg check for the presence of pihole-FTL running (eg via SSH using a key)? If not then you could use the chronometer web page approach I posted and simplify it even more (see below). I don't know Docker well so adjust if needed.

Simplified

On the Pi-hole create a symbolic link

sudo ln -s /home/pi/status.txt /var/www/html/pihole/status.txt

Open pi's crontab

crontab -e

Add in the entry below to update the status every 1 minute, and save.

* * * * * bash -l pihole -c -e | awk '/Pi-hole/{print $1,$2}' > /home/pi/status.txt

You can now monitor the text at

http://<your pihole ip>/pihole/status.txt

It will be updated every minute via cron.

Security note

Since you're linking to a file outside the webroot, please do make sure that the Pi-hole is secure and up to date and accessible to only those who should have access. You'll need to make your own security risk assessment of using this approach. In terms of who can access the info without authentication it will be no different to what you had before.

Monitoring for the word "Active" seems a bit risky, in that if the Pi-hole fails then you won't be able to reach a page to monitor. Your monitoring logic would have to make sure it treats that as the service being down. But then if just the web component fails it would flag Pi-hole as down even if DNS was up. Worth going through some example scenarios and assessing the possible outcomes of this approach.

It's possible that you'll read the file exactly as it's being updated and get a blank result, potentially causing a false alarm. Add a few seconds delay to your checking so it's not exactly on the minute so writing and checking don't coincide.

Not sure if the link in www will survive an update; it may be overwritten. Check on next available update.

(Edited to include exact crontab entry needed to work properly and add extra note)

You could use
http://pi.hole/admin/api.php?status

4 Likes

Your original method was too complex.
The most simple way to find if pi-hole status is using the URL mentioned by @yubiuser above.

There's no need to be logged in and the answer will be one of these 2 returns:

  • "status":"enabled" or
  • "status":"disabled".

If you need to use this response on the command line or cron job, you can use:

curl -s http://192.168.0.201/admin/api.php?status | jq .status
1 Like

I noticed three returns:

pi@ph5b:~ $ curl -s http://localhost/admin/api.php?status | jq .status
"enabled"
pi@ph5b:~ $ curl -s http://localhost/admin/api.php?status | jq .status
"disabled"

And for when the pihole-FTL daemon isnt running:

pi@ph5b:~ $ curl -s http://localhost/admin/api.php?status | jq .status
null

EDIT: This will turn into moot with the v6 release though and would need something like below for "heuristics" :wink:

nc -z <PIHOLE_IP> 53 && echo "up" || echo "down"

1 Like

Thanks I didn't know this. @Span please switch to using this method as it's much better than the hack I posted.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.