#! /bin/sh
# --------------------------------------------------------------------------------------
#
#  CARD MONITOR EXAMPLE FILE
#
#  Copiright (c) 1993-2001 by Eicon Networks
#
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2, or (at your option)
# * any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# *
#
#  Should be used as:
#  "divactrl load -c X -CardMonitor -File /YYY/card_monitor"
#  Where:
#     "X"   is adapter number
#     "YYY" is full path to this file
#
#  Provides reporting of card failure via EMail.
#
#  Please set "MAILTO" variable to correct EMail address
#
# --------------------------------------------------------------------------------------

MAILTO="root"

# --------------------------------------------------------------------------------------

PATH=/sbin:/usr/sbin:/usr/bin:/bin; export PATH

# --------------------------------------------------------------------------------------

if [ $(($#)) -eq 0 ]
then
	echo "Please start 'divactrl load -c X -CardMonitor -File /..../card_monitor'"
	echo "where 'X' is the adapter number."
  exit 1
fi

# --------------------------------------------------------------------------------------

adapter=${1}
tmp_file="/tmp/diva_card_monitor_tmp_adapter${adapter}.txt"
divactrl="/usr/lib/eicon/divas/divactrl"
if [ ! -f ${divactr} ]
then
divactrl="divactrl"
fi

rm -f ${tmp_file}

divactrl="${divactrl} load -c ${adapter}"
name=$(${divactrl} -CardName)
sn=$(${divactrl} -SerialNumber)
state=$(${divactrl} -CardState)

# --------------------------------------------------------------------------------------

echo "------------------------------" > ${tmp_file}
echo $(date) >> ${tmp_file}
echo "DIVA Adapter Nr:${adapter} ${name} SN: ${sn} failed" >> ${tmp_file}
echo "" >> ${tmp_file}
echo "Adapter State: ${state}" >> ${tmp_file}
echo "" >> ${tmp_file}
cat /proc/net/isdn/eicon/adapter${adapter}/info >> ${tmp_file}
echo "------------------------------" >> ${tmp_file}
echo "." >> ${tmp_file}

# --------------------------------------------------------------------------------------

subject="PROBLEM: Diva Card ${adapter} failed"

mail -s "${subject}" "${MAILTO}" < ${tmp_file}

# --------------------------------------------------------------------------------------

exit 0

# --------------------------------------------------------------------------------------

