#!/bin/bash

time=9
today=$(     date +%Y-%m-%d                    )
yesterday=$( date +%Y-%m-%d -d "$today -1 day" )

analysiere_nagioslog \
        -ge timestamp=$( date +%s -d "$yesterday $time" )               \
        -lt timestamp=$( date +%s -d "$today $time"     )               \
        -is target=hotline_voice                                        \
        -template /usr/lib/maile_hotline-report/hotline-report.template \
        $( ls -1tr /var/log/nagios*/archives/nagios-??-??-????-??.log |
           tail -1 )                                                    \
        -variable hostname=$(hostname)                                  \
        -variable yesterday="$yesterday"                                \
        -variable today="$today"                                        \
        -variable time="$time"                                          \
        /var/log/nagios/nagios.log | grep Subject | grep '0 Alarme' > /dev/null ||
analysiere_nagioslog							\
	-ge timestamp=$( date +%s -d "$yesterday $time" )		\
	-lt timestamp=$( date +%s -d "$today $time"     )		\
	-is target=hotline_voice					\
	-template /usr/lib/maile_hotline-report/hotline-report.template	\
	$( ls -1tr /var/log/nagios*/archives/nagios-??-??-????-??.log |
	   tail -1 )							\
	-variable hostname=$(hostname)					\
	-variable yesterday="$yesterday"				\
	-variable today="$today"					\
	-variable time="$time"						\
	/var/log/nagios/nagios.log |
	/usr/sbin/sendmail hotline-report@noris.net
