2 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
5 # Ninjareport - generate a single simple report for a lot of hosts
9 # Copyright (C) 2007 - riseup.net -- property is theft.
13 # . check for logs that are never updating and warn
14 # . change constantly updating logs (maildir) to be more friendly
16 # . maybe make config option that lists all hosts that should report-in, and if
17 # one doesn't then warn
18 # . restrict rsync somehow?
19 # . abstract path for logtail
20 # . on the report master, the reportdirectory should be set where the reports will be going, note this
27 # look in the logfile for any lines like the following:
28 # Jan 20 01:02:46 Info: FINISHED: 2 actions run. 0 fatal. 0 error. 0 warning.
30 # note: some backups never finish, such as the maildir one, need to handle these
31 # perhaps by looking for FAILED messages?
32 # note2: what about logs that aren't being updated? this is a failure case and
33 # should be looked for
34 # note3: there are also these entries:
35 # Jan 20 14:00:01 Fatal: No backup actions configured in '/etc/backup.d', run ninjahelper!
37 # The following has to be done without invoking a subshell (see BashFAQ #24)
38 logupdates=`maketemp ninjadata`
40 /usr/sbin/logtail -f $host > $logupdates
41 grep FINISHED $logupdates |
50 fatal=$(($fatal + ${line_array[8]}))
51 error=$(($error + ${line_array[10]}))
52 warning=$(($warning + ${line_array[12]}))
54 if (( $fatal || $warning || $error )); then
55 echo "`basename $host .log`: $fatal fatals found, $error errors found, $warning warnings found" >> $statusfile
56 echo "" >> $reportappend
57 echo "`basename $host .log` log entries since last ninjareport" >> $reportappend
58 echo "---------" >> $reportappend
59 cat $logupdates >> $reportappend
68 reportfile=`maketemp ninjareport`
70 # Generate a report, only if there are failures
71 if [ -s $statusfile ]; then
72 echo " backupninja mission failures - `date`" >> $reportfile
73 echo " --------------------------------------------------------------" >> $reportfile
74 echo "" >> $reportfile
75 cat $statusfile | column -t >> $reportfile
76 echo "" >> $reportfile
77 echo " log entries from failed reports" >> $reportfile
78 echo " -----------------------------------" >> $reportfile
79 cat $reportappend >> $reportfile
86 This script generates a backupninja status report for all configured
87 systems. It requires that each status report is placed in a spot where
88 ninjareport can read it, reports are mailed to the reportemail
89 configured in @CFGDIR@/backupninja.conf.
91 The following options are available:
92 -h, --help This usage message
93 -f, --conffile FILE Use FILE for the configuration instead
94 of @CFGDIR@/backupninja.conf
95 -m, --mail <email> Mail the report to this address
96 -o, --out Don't mail the report, just display it
101 #####################################################
104 conffile="@CFGDIR@/backupninja.conf"
106 ## process command line options
108 while [ $# -ge 1 ]; do
118 echo "-f|--conffile option must be followed by an existing filename"
119 fatal "-f|--conffile option must be followed by an existing filename"
122 # we shift here to avoid processing the file path
134 echo "Unknown option $1"
142 ## Load and confirm basic configuration values
145 if [ ! -r "$conffile" ]; then
146 echo "Configuration file $conffile not found."
147 fatal "Configuration file $conffile not found."
151 libdirectory=`grep '^libdirectory' $conffile | awk '{print $3}'`
152 if [ -z "$libdirectory" ]; then
153 if [ -d "@libdir@" ]; then
154 libdirectory="@libdir@"
156 echo "Could not find entry 'libdirectory' in $conffile."
160 if [ ! -d "$libdirectory" ]; then
161 echo "Lib directory $libdirectory not found."
166 # include shared functions
167 . $libdirectory/tools
171 getconf reportdirectory
174 ## Process each configuration file
176 hosts=`find $reportdirectory -follow -mindepth 1 -maxdepth 1 -type f ! -name '*.offset' | sort -n`
178 if [ -z "$hosts" ]; then
179 echo "Fatal: No backupninja reports found in '$reportdirectory'!"
183 statusfile=`maketemp ninjastatus`
184 reportappend=`maketemp ninjaappend`
186 for host in $hosts; do
187 [ -f "$host" ] || continue
188 # Check somehow that the file is a valid report file
194 ## mail the report to the report address or display it
196 if [ -s $reportfile ]; then
197 if [ $mail == 1 ]; then
198 mail -s "backupninja mission failure report" $reportemail < $reportfile
202 if [ $display == 1 ]; then