3 # Copyright(c) 2008 op5 AB
10 last_sent_file
=/opt
/monitor
/op
5/log_pusher
/last_sent
11 config_file
=/opt
/monitor
/etc
/nagios.cfg
12 archive_dir
=$
(sed -n 's/^log_archive_path=\([^ \t]*\).*$/\1/p' $config_file)
13 log_file
=$
(sed -n 's/^log_file=\([^ \t]*\).*$/\1/p' $config_file)
14 test "$log_file" || log_file
=/opt
/monitor
/var
/nagios.log
15 fpart
="${log_file##*/}"
16 test "$archive_dir" || archive_dir
=$
(echo $log_file |
sed 's#/$fpart.*##g')
17 test -d "$archive_dir" && \
18 newest_archived
=$
(/bin
/ls --color=none
-rt1 $archive_dir/*.log
2>/dev
/null |
tail -1)
19 #echo "fpart: $fpart; log_file: $log_file"
20 #echo "archive_dir: $archive_dir"
21 #echo "newest_archived: $newest_archived"
27 -e ' HOST ALERT:' -e ' SERVICE ALERT:' \
28 -e ' INITIAL HOST STATE:' -e ' INITIAL SERVICE STATE:' \
29 -e ' CURRENT HOST STATE:' -e ' CURRENT SERVICE STATE:' \
30 -e ' HOST DOWNTIME ALERT:' -e ' SERVICE DOWNTIME ALERT:' \
31 "$@" 2>/dev
/null |
sort
35 trap "rm -f $tmpfile" 0 1 2 3 15
36 test -f "$last_sent_file" && last_sent
=$
(cat "$last_sent_file" 2>/dev
/null
)
37 if [ "$last_sent" ]; then
38 get_lines
$newest_archived $log_file \
39 |
sed -n "/^.$last_sent/,\$p" |
sed "/^.$last_sent/d" > $tmpfile
42 get_lines
"$archive_dir"/* $log_file > $tmpfile
45 if ! [ -s "$tmpfile" ]; then
46 echo "No updates to send."
50 cur_sent
=$
(sed -n '$s/^.\([0-9]*\).*/\1/p' $tmpfile)
53 trap "rm -f $tmpfile $tmpfile.gz" 0 1 2 3 15
56 dest_name
="/opt/monitor/pushed_logs/$(hostname).$last_sent-$cur_sent.log.gz"
57 scp
-i $ssh_key $tmpfile monitor@
$master:$dest_name && \
58 echo "$cur_sent" > "$last_sent_file"