90 lines
2.7 KiB
Bash
Executable File
90 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
HTML="/var/www/html/port_alerts.html"
|
|
OBSURL="http://10.101.0.11"
|
|
|
|
echo "<html>
|
|
<head>
|
|
<style>
|
|
body { font-size: 120%; }
|
|
td { font-size: 120%; }
|
|
h3 {text-align:center;}
|
|
#ok {background-color:#00ff00;}
|
|
#fail {background-color:#ff5555;}
|
|
</style>
|
|
<meta http-equiv='refresh' content='60; URL=port_alerts.html'>
|
|
</head>
|
|
<body>" > $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 "<h3 id='ok'>No Ports with errors!</h3>" >> $HTML
|
|
else
|
|
echo "<h3 id='fail'>Ports with errors!</h3>" >> $HTML
|
|
|
|
echo "<table cellpadding=4pt>" >> $HTML
|
|
echo "<tr><td>Hostname</td><td>Port</td><td>Last Change</td><td>InErrorsRate</td><td>OutErrorsRate</td><td>Port Description</td></tr>" >> $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 "<tr>
|
|
<td>
|
|
<a href='$OBSURL/device/device=$DEVICE_ID' target='frame_obs'>$HOSTNAME</a>
|
|
</td>
|
|
<td>
|
|
<a href='$OBSURL/device/device=$DEVICE_ID/tab=port/port=$PORT_ID' target='frame_obs'>$PORT_LABEL</a>
|
|
</td>
|
|
<td>
|
|
$LAST_CHANGE
|
|
</td>
|
|
<td>
|
|
$IN_ERR
|
|
</td>
|
|
<td>
|
|
$OUT_ERR
|
|
</td>
|
|
<td>
|
|
$PORT_DESCR
|
|
</td>
|
|
</tr>" >> $HTML
|
|
done < /tmp/result
|
|
fi
|
|
echo "</table>
|
|
</body>
|
|
</html>
|
|
" >> $HTML
|
|
|