#!/bin/sh # validation reporter - reports validation failures to a collection server. # Copyright NLnet Labs, 2010 # BSD license. ### # Here is the configuration for the validation reporter # it greps the failure lines out of the log and sends them to a server. # The pidfile for the reporter daemon. setglobal pidfile = '"/var/run/validation-reporter.pid'" # The logfile to watch for logged validation failures. setglobal logfile = '"/var/log/unbound.log'" # how to notify the upstream # nc is netcat, it sends tcp to given host port. It makes a tcp connection # and writes one log-line to it (grepped from the logfile). # the notify command can be: "nc the.server.name.org 1234" # the listening daemon could be: nc -lk 127.0.0.1 1234 >> outputfile & setglobal notify_cmd = '"nc localhost 1234'" ### # Below this line is the code for the validation reporter, # first the daemon itself, then the controller for the daemon. proc reporter_daemon { trap "rm -f \"$pidfile\"" EXIT tail -F $logfile | grep --line-buffered "unbound.*info: validation failure" | \ while read x { echo $x | $notify_cmd } } ### # controller for daemon. proc start_daemon { echo "starting reporter" nohup $0 rundaemon /dev/null 2>&1 & echo $BgPid > "$pidfile" } proc kill_daemon { echo "stopping reporter" if test -s $pidfile { kill $[cat $pidfile] # check it is really dead if kill -0 $[cat $pidfile] >/dev/null 2>&1 { sleep 1 while kill -0 $[cat $pidfile] { kill $[cat $pidfile] >/dev/null 2>&1 echo "waiting for reporter to stop" sleep 1 } } } } proc get_status_daemon { if test -s $pidfile { if kill -0 $[cat $pidfile] { return 0; } } return 1; } proc restart_daemon { kill_daemon start_daemon } proc condrestart_daemon { if get_status_daemon { echo "reporter ("$[cat $pidfile]") is running" exit 0 } start_daemon exit 0 } proc status_daemon { if get_status_daemon { echo "reporter ("$[cat $pidfile]") is running" exit 0 } echo "reporter is not running" exit 1 } match $1 { with rundaemon reporter_daemon with start start_daemon with stop kill_daemon with restart restart_daemon with condrestart condrestart_daemon with status status_daemon with * echo "Usage: $0 {start|stop|restart|condrestart|status}" exit 2 } exit $?