retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-log-age-loghost
1 #! /bin/bash
2 #
3 # Copyright 2009 Stephen Gran <sgran@debian.org>
4 # Copyright 2010 Peter Palfrader
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 usage(){
26         ret=$1
27         exit $ret
28 }
29
30 host="$1"
31 if [ -z "$host" ] || [ "$host" = "-h" ] ||  [ "$host" = "--help" ]; then
32         echo >&2 "Usage: $0 <host>"
33         usage 3
34 fi
35
36 if [ "${host/[^a-z0-9-]/}" != "$host" ]; then
37         echo >&2 "$0: Invalid hostname $1"
38         exit 3
39 fi
40
41 ts=$(date -d 'now' +'%Y/%m/%d')
42 file="/var/log/hosts/$host/$ts/syslog"
43 if [ ! -e "$file" ]; then
44         # maybe we did not log anything today yet?
45         ts=$(date -d 'now - 1 hour' +'%Y/%m/%d')
46         file="/var/log/hosts/$host/$ts/syslog"
47 fi
48
49 if [ ! -e "$file" ]; then
50         echo "log file $file is missing"
51         exit 2
52 fi
53
54 if [ "$( date -d 'now - 60 minutes' +%s )" -gt "$(stat -c %Y "$file" )" ]; then
55         echo "log file $file is older than 60 minutes"
56         exit 2
57 fi
58
59 printf "log file %s OK: last changed %s\n" $file "$(stat -c %y $file)"