#!/bin/bash
HTML="/var/www/html/port_alerts.html"
OBSURL="http://10.101.0.11"
echo "
" > $HTML
echo "select device_id from devices where \`ignore\`='1';" | mysql --user=observium --password=observium observium | grep -v device_id > /tmp/ign_device
WHERE="and "
MATCH=0
while read DEVICE
do
MATCH=1
WHERE=`echo "$WHERE device_id != '$DEVICE' and"`
done < /tmp/ign_device
WHERE=`echo "$WHERE 1"`
if [ "$MATCH" == "0" ]; then
WHERE=""
fi
echo "select count(*) from ports where ( ifInErrors_rate > 0 or IfOutErrors_rate > 0 ) and \`ignore\`='0' and deleted='0' $WHERE;" | mysql --user=observium --password=observium observium | grep -v count > /tmp/result1
COUNT=`cat /tmp/result1`
if [ "$COUNT" == "0" ]
then
echo "No Ports with errors!
" >> $HTML
else
echo "Ports with errors!
" >> $HTML
echo "" >> $HTML
echo "| Hostname | Port | Last Change | InErrorsRate | OutErrorsRate | Port Description |
" >> $HTML
# suche infos über ports die down aber admin up aber nicht ignoriert werden sollen und nicht gelöscht sind
echo "select device_id,port_label,port_id,ifLastChange,ifInErrors_rate,ifOutErrors_rate,ifAlias from ports where ( ifInErrors_rate > 0 ) and \`ignore\`='0' and deleted='0' $WHERE;" | mysql --user=observium --password=observium observium | grep -v device > /tmp/result
while read PORT
do
DEVICE_ID=`echo $PORT | awk '{print $1}'`
PORT_LABEL=`echo $PORT | awk '{print $2}'`
PORT_ID=`echo $PORT | awk '{print $3}'`
LAST_CHANGED=`echo $PORT | awk '{print $4}'`
LAST_CHANGET=`echo $PORT | awk '{print $5}'`
IN_ERR=`echo $PORT | awk '{print $6}'`
OUT_ERR=`echo $PORT | awk '{print $7}'`
LAST_CHANGE="$LAST_CHANGED $LAST_CHANGET"
PORT_DESCR=`echo $PORT | awk '{ $1=""; $2=""; $3=""; $4=""; $5=""; $6=""; $7=""; print}'`
if [[ "$PORT_DESCR" =~ "NULL" ]]; then
PORT_DESCR="-"
fi
HOSTNAME=`echo "select hostname from devices where device_id=$DEVICE_ID;" | mysql --user=observium --password=observium observium | grep -v hostname`
echo "
|
$HOSTNAME
|
$PORT_LABEL
|
$LAST_CHANGE
|
$IN_ERR
|
$OUT_ERR
|
$PORT_DESCR
|
" >> $HTML
done < /tmp/result
fi
echo "
" >> $HTML