petar.company/rrdtools/archive/ciscoGraph.sh

342 lines
7 KiB
Bash
Raw Permalink Normal View History

2025-03-01 00:58:18 +01:00
#!/bin/sh
#
# $VER: ciscoGraphs.sh 0.10 (20.10.2005) Riccardo "VIC" Torrini
#
tmp=/tmp/tmp_$$
debug=
trap 'Break' 1 2 15
CleanUp ()
{
rm -f ${tmp}*
}
Break ()
{
echo "${Program}: ** User Break"
CleanUp
exit 2
}
Debug ()
{
[ ${debug} ] && echo "DEBUG: ${1}"
}
Error ()
{
echo "** Error ! ${1}"
CleanUp
exit 2
}
Warning ()
{
echo "* Warning ! ${1}"
CleanUp
exit 1
}
Panic ()
{
echo "** Internal error ! ${1}"
CleanUp
exit 3
}
Message ()
{
echo "* ${1}"
return 1
}
isNotNull ()
{
[ "_${2}" = "_" ] && Error "${1}"
}
CheckFile ()
{
isNotNull "Invalid parameter to CheckFile()" "${1}"
if [ ! -f ${1} ]
then
if [ "_${2}" = "_" ]
then
Error "File not found (${1})"
else
Error "${2}"
fi
fi
}
CheckDir ()
{
isNotNull "Invalid parameter to CheckDir()" "${1}"
if [ ! -d ${1} ]
then
if [ "_${2}" = "_" ]
then
Error "Directory not found (${1})"
else
Error "${2}"
fi
fi
}
FileNotFound ()
{
Message "File not found (`basename ${1}`)"
}
DirectoryNotFound ()
{
Message "Directory not found (${1})"
}
FileExist ()
{
Message "File exist (`basename ${1}`)"
}
# Main
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/local/vbin
dbHome=/var/db/rrd
###
#
# called as: # ${0} {action} "router|switch" {HOSTNAME} ...
#
action=${1:-NULL}
isNotNull "Missing action" "${action}"
service=${2:-NULL}
host=${3:-NULL}
db=${dbHome}/${service}-mpls-${host}.rrd
images=/home/web/virtual-internal/data/stats/services
CheckDir ${images}
CheckDir ${dbHome}
cd ${dbHome}
##
# we can't check 'coz variable parms
#
##isNotNull "Missing service" "${service}"
##isNotNull "Missing host name" "${host}"
case ${action:-NULL} in
create)
###
#
# called as: create {SERVICEDESC} {HOSTNAME}
#
case ${service:-NULL} in
ping|smtp|http)
test -f ${db} && Error "we are on-air, don't try to destroy existing db (${db})"
rrdtool create ${db} \
--start `date -v2000y -v6m -v21d -v0H -v0M -v0S +%s` \
--step 60 \
DS:trip:GAUGE:300:0:U \
DS:lost:GAUGE:300:0:U \
RRA:AVERAGE:0.5:1:50400 \
RRA:AVERAGE:0.5:60:43800 \
RRA:MAX:0.5:1:50400 \
RRA:MAX:0.5:60:43800
chown nagios ${db}
;;
router|switch)
test -f ${db} && Error "we are on-air, don't try to destroy existing db (${db})"
rrdtool create ${db} \
--start `date -v2000y -v6m -v21d -v0H -v0M -v0S +%s` \
--step 300 \
DS:load:GAUGE:600:0:100 \
DS:heat:GAUGE:600:0:U \
DS:io:COUNTER:600:0:U \
DS:oo:COUNTER:600:0:U \
DS:ie:COUNTER:600:0:U \
DS:oe:COUNTER:600:0:U \
RRA:AVERAGE:0.5:1:50400 \
RRA:AVERAGE:0.5:60:43800 \
RRA:MAX:0.5:1:50400 \
RRA:MAX:0.5:60:43800
chown nagios ${db}
;;
*)
Error "not yet !"
;;
esac
;;
collect)
###
#
# called as: collect {SERVICEDESC} {HOSTNAME}
#
case ${service:-NULL} in
ping)
##test -f ${db} || Error "db not found (${db})"
if [ -f ${db} ]
then
shift 5
data=`echo "${*}" | awk -F"@@" '
{
split($0, a);
gsub(/[a-zA-Z %]/, "", a[2]);
split(a[2], b, ",");
split(b[1], c, "=");
split(b[2], d, "=");
if ($0 ~ /timed out after 10 seconds/) {
d[2] = 10000;
c[2] = 100;
}
}
END {
printf( "%s:%s", d[2], c[2] );
}'`
rrdtool update ${db} ${when}:${data}
fi
;;
smtp)
echo "${*}" >> /tmp/nagios.debug
;;
http)
echo "${*}" >> /tmp/nagios.debug
;;
router|switch)
#
host=fi
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2fi.fi-fastweb.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
#
host=fk
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2fi.fi-telecom.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
#
host=ge
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2ge.ge-fastweb.esaote.it ifInOctets.2 ifOutOctets.2 ifInErrors.2 ifOutErrors.2 | awk '{printf( ":%.0f", $NF)}'`
#
host=mi
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2mi.mi-fastweb.esaote.it ifInOctets.2 ifOutOctets.2 ifInErrors.2 ifOutErrors.2 | awk '{printf( ":%.0f", $NF)}'`
#
host=rm
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2rm.rm-fastweb.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
#
host=nx
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2nx.nx-fastweb.esaote.it ifInOctets.2 ifOutOctets.2 ifInErrors.2 ifOutErrors.2 | awk '{printf( ":%.0f", $NF)}'`
#
host=pd
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2pd.pd-fastweb.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
#
host=ba
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2ba.ba-fastweb.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
#
host=bo
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2bo.bo-fastweb.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
#
host=ct
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2ct.ct-fastweb.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
#
host=na
db=${dbHome}/${service}-mpls-${host}.rrd
rrdtool update ${db} N:0:0`snmpget -cpublic -v1 fw2na.na-fastweb.esaote.it ifInOctets.1 ifOutOctets.1 ifInErrors.1 ifOutErrors.1 | awk '{printf( ":%.0f", $NF)}'`
;;
*)
Error "not yet !"
;;
esac
;;
dump)
;;
reload)
;;
daily|weekly|monthly|yearly)
###
#
# called as: (graph)? (daily|weekly|monthly|yearly)
#
case ${action} in
daily)
dfrom="-s `date -v-1d +%s`"
dend=""
;;
weekly)
dfrom="-s `date -v-1w +%s`"
dend=""
;;
monthly)
dfrom="-s `date -v-1m +%s`"
dend=""
;;
yearly)
dfrom="-s `date -v-6m +%s`"
dend=""
;;
esac
thisCanvas="--imgformat PNG"
thisGeometry=""
thisRange="${dfrom} ${dend}"
for service in router
do
for rrd in `ls ${service}-*.rrd`
do
host=${rrd##${service}-}
host=${host%%.rrd}
db=${dbHome}/${service}-${host}.rrd
rrdtool graph ${images}/pkt-${host}-${action}.png \
${thisCanvas} ${thisGeometry} ${thisRange} \
--lower-limit 0 \
--title "${host} bytes (${service} - ${action})" \
--vertical-label "bytes/sec" \
DEF:io=${db}:io:AVERAGE \
DEF:oo=${db}:oo:AVERAGE \
LINE2:io#00ff00 \
LINE2:oo#0000ff
rrdtool graph ${images}/err-${host}-${action}.png \
${thisCanvas} ${thisGeometry} ${thisRange} \
--lower-limit 0 \
--title "${host} errors (${service} - ${action})" \
--vertical-label "errors/sec" \
DEF:ie=${db}:ie:AVERAGE \
DEF:oe=${db}:oe:AVERAGE \
LINE2:ie#ff0000 \
LINE2:oe#808000
done
done
;;
help)
echo "Usage: ${0} [create|collect|update|dump|reload|daily|weekly|monthly|yearly|help]"
exit 1
;;
esac
exit 0