#!/bin/sh
# $Id: sm_alarm,v 1.6 2007/10/05 09:04:51 sesam Exp $
#******************************************************************************
#
# File      : sm_alarm
# Copyright : (c) SEP AG  D83629 Weyarn
# Date      : 2007
#
#******************************************************************************
#
# Description : This is the alarm interface of SESAM backup utility.
#               It is called from nearly all SESAM modules, whenever a
#               fatal error occurs.
#
# Parameters  : $1 = Name of module which signals the alarm
#               $2 = Text of error message
#
# This is a user programmable shell script with 2 parameters.
# Please insert your specific code lines after this comment.
# Take care of not inserting commands which wait for an answer from
# the user ( OK-buttons etc. ) - this may cause a total blocking of
# backups during the night.
#
#
#********************************************************************************
# Beschreibung: Dies ist die Alarmschnittstelle der SESAM Sicherungssoftware.
#               Sie wird von fast allen Modulen im Falle eines Fehlers
#               aufgerufen.
#
# Parameter   : $1 = Name des signalisierenden Moduls
#               $2 = Text der Meldung
#
# Dies ist ein benutzerprogrammierbares Shell Skript mit 2 Parametern.
# Fuegen Sie bitte Ihre eigenen Kommandozeilen nach diesem Kommentar ein,
# wobei Kommandos, die eine Antwort erwarten ( OK-Buttons etc. ) vermieden
# werden sollten, da sie Sicherungen waehrend der Nacht blockieren koennten.
#
#********************************************************************************
#
# Example
#
read_ini()
{
   source `grep -i '^sm_ini=' /etc/sesam2000.ini|cut -d"=" -f2` 2>/dev/null
}
#
send_mail()
{
   ## Set mail subject
   mail_subject="Sesam $1 $2"
   ## Send Sesam status file as mail body
   sm_smtp -A "sesam" -s "$mail_subject" -M "gv_dayfile:" -a "gv_prot:"
}
#
send_backup_mail()
{
   ## Set mail subject
   mail_subject="Sesam $1 $2"
   ## Send Sesam not file as mail body
   f=$( echo $2|cut -d ':' -f 1)
   echo $f
   sm_smtp -A "sesam" -s "$mail_subject" -M "$( ls -tr ${gv_rw_lis}/$f*not|tail -1 )" ""
}

#--------------- MAIN ----------------------
read_ini
source "${gv_rw_ini}/sesam2000.profile" >/dev/null 2>&1
echo "$0" "$*" >> "${gv_rw_lgc}/sm_alarm.lgc"
case $1 in
   INIT)
     #send_mail "$1" "$2"
     ;;
   GET_VOLUME)
     send_mail "$1" "$2";
     ;;
   BACKUP)
     send_backup_mail "$1" "$2";
     ;;
   RESTORE)
     send_mail "$1" "$2" "$3";
     ;;
   *)
   send_mail "$1" "$2";
   ;;
esac
exit
