Files
scripts/Observium Bash Report Einfach/report.sh
2024-10-14 00:08:40 +02:00

91 lines
2.4 KiB
Bash

#übersetzungsfunktion
function translation {
device_storage="Disks"
device_mempool="RAM"
device_ucd_memory="RAM detailed"
device_processor="CPU"
device_ucd_ss_cpu="CPU detailed"
device_la="Load"
}
#frunktion zum abrufen der bilder aus observium
function get_png {
d=$1; t=$2; a=$3; e=$4; h=$5; w=$6; i=$7 n=$8
#rm -f $n---$t---$i.png
#echo "http://10.101.0.11/graph.php?device=$d&type=$t&from=$a&to=$e&width=$w&height=$h"
wget -q -O $n---$t---$i.png "http://10.101.0.11/graph.php?device=$d&type=$t&from=$a&to=$e&width=$w&height=$h"
}
# welche parameter sollen im report auftauchen
ALLG="device_storage"
# device_mempool device_ucd_memory device_processor device_ucd_ss_cpu device_la"
# welche zeiträume (in tagen) sollen im report angezeigt werden
ALLD="1 31"
# wird vom skript gefüllt
ALLH=""
# 1 einziger select der alle host ids aus der db holt für die der report erstellt werden soll
#report_nameserver
# select device_id from entity_attribs where attrib_type="notes" and attrib_value like "%report_nameserver%"
#for ID in `echo 'select device_id from devices where devices.distro like "Debian%"' | mysql -B -u observium -pobservium -Dobservium`
for ID in `echo 'select device_id from entity_attribs where attrib_type="notes" and attrib_value like "%report_internal%"' | mysql -B -u observium -pobservium -Dobservium`
do
if [ "$ID" != "device_id" ]
then
HN=`echo "select hostname from devices where device_id = '$ID'" | mysql -B -u observium -pobservium -Dobservium | grep -v hostname`
ALLH=$ALLH" "$HN
if [ "$ID" != "device_id" ]
then
ENDE=`date +%s`
for G in `echo $ALLG`
do
for TR in `echo $ALLD`
do
echo "dev:"$HN" graph:"$G" days:"$TR
SPAN=`expr 60 \* 60 \* 24 \* $TR`
START=`expr $ENDE - $SPAN`
get_png $ID $G $START $ENDE 200 400 $TR $HN
done
done
fi
fi
done
# Zeichenkettenübersetungen sind menschenfreundlicher
translation
# build output
for H in `echo $ALLH`
do
echo "<h2>$H</h2>"
for G in `echo $ALLG`
do
echo "<h3>${!G}</h3>"
echo "<table>"
echo " <tr>"
for D in `echo $ALLD`
do
if [ "$D" == "1" ]
then
echo " <td>$D Tag</td>"
else
echo " <td>$D Tage</td>"
fi
done
echo " </tr>"
echo " <tr>"
for D in `echo $ALLD`
do
echo " <td><img src='$H---$G---$D.png'></td>"
done
echo " </tr>"
echo "</table>"
done
done > index.html