Skip to content

Instantly share code, notes, and snippets.

@dgl
Created July 25, 2010 18:08
Show Gist options
  • Save dgl/489740 to your computer and use it in GitHub Desktop.
Save dgl/489740 to your computer and use it in GitHub Desktop.
PowerDNS MySQL monitoring

Simple PowerDNS MySQL replication monitoring

Replace domain in "ucheck.domain" with a domain of yours in both the SQL below and ucheck-check.sh. Normally use the one the DNS servers are in (this assumes your servers are called a.ns.domain, b.ns.domain, etc, change in ucheck-check.sh).

Do something like this in MySQL:

CREATE SQL SECURITY DEFINER VIEW ucheck AS
  SELECT id, domain_id, name,type, content, ttl, prio, change_date from records where (name = 'ucheck.domain') WITH CASCADED CHECK OPTION;

GRANT UPDATE on pdns.ucheck to ucheck@localhost;

Then cron up the two scripts below:

5 * * * * ~/bin/ucheck-update.sh
9 * * * * ~/bin/ucheck-check.sh

Then cron will email you when something breaks.

#!/bin/sh
REC=ucheck.domain
NS="a b c d"
HO=.ns.domain
time=$(date +%s)
for n in $NS; do
n="$n$HO"
res=$(dig @$n +short TXT $REC | sed 's/"//g')
if [ -z "$res" -o "${res%[a-z]}" != "${res}" ]; then
echo "Bad $n"
elif [ "$res" -lt "$[$time - 600]" ] 2>/dev/null; then
echo "Bad $n"
fi
done
#!/bin/sh
echo "update ucheck set content=$(date +%s);" | mysql -u ucheck pdns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment