#! /bin/bash # script to create/update rrd bases # tnka@linux-sottises.net # Config file must be given if ! [ "$1" ];then echo "Error: provide the config file name" exit 1 fi # Configuration file is read from command line CONFIG=$1 FREQ="300" # check general config file exists if ! [ -f /etc/mrtnk.setup ];then echo "Error: you have to put mrtnk.setup in /etc" exit 1 fi # General Parameters . /etc/mrtnk.setup ######## NON SNMP ######################## # Determine all the targets which are not snmp TARGET_LIST=(`cat $CONFIG|grep -i target|grep -v "#"|grep -vi snmp|cut -d"[" -f2|cut -d "]" -f1`) # Loop on all the non snmp targets for i in "${TARGET_LIST[@]}"; do TYPE=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i type|cut -d'"' -f2` ABSMIN=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i absmin|cut -d'"' -f2` ABSMAX=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i absmax|cut -d'"' -f2` EXECUTE=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i target|cut -d'"' -f2` # Check the TYPE parameter before creating the rrd database if [ "$TYPE" != GAUGE ] && [ "$TYPE" != COUNTER ];then echo wrong type $TYPE for target $i exit 1 fi if [ -z "$ABSMAX" ];then echo Error ABSMAX for target $i exit 1 fi if [ -z "$ABSMIN" ];then echo Error ABSMIN for target $i exit 1 fi # if rrd file does not exist for target, create it!! if ! [ -f "$LOGS"/"$i".rrd ]; then $MRTNK/rrd-tnk create $i.rrd $TYPE $FREQ $ABSMIN $ABSMAX else # Make a systematic update of AMSMAX, ABSMIN and TYPE $RRD tune $LOGS/$i.rrd -i ds0:$ABSMIN -a ds0:$ABSMAX -d ds0:$TYPE $RRD tune $LOGS/$i.rrd -i ds1:$ABSMIN -a ds1:$ABSMAX -d ds1:$TYPE fi # Now update rrd database $MRTNK/rrd-tnk update $i.rrd "$EXECUTE" & done ##### End Non SNMP ################ ################ SNMP ####################### # Determine all the targets which are snmp TARGET_LIST=(`cat $CONFIG|grep -i target|grep -v "#"|grep -i snmp|cut -d"[" -f2|cut -d "]" -f1`) # Loop on all the snmp targets for i in "${TARGET_LIST[@]}"; do TYPE=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i type|cut -d'"' -f2` ABSMIN=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i absmin|cut -d'"' -f2` ABSMAX=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i absmax|cut -d'"' -f2` SNMP_IF=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i snmp_if|cut -d'"' -f2` SNMP_NUMBER=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i snmp_number|cut -d'"' -f2` SNMP_OID_IN=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i snmp_oid_in|cut -d'"' -f2` SNMP_OID_OUT=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i snmp_oid_out|cut -d'"' -f2` SNMP_HOST=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i snmp_host|cut -d'"' -f2` SNMP_COMMUNITY=`cat $CONFIG|grep -i "\[$i\]"|grep -v "#"|grep -i snmp_community|cut -d'"' -f2` # Check the TYPE parameter before creating the rrd database if [ "$TYPE" != GAUGE ] && [ "$TYPE" != COUNTER ];then echo "wrong type $TYPE for target $i" exit 1 fi if [ -z "$ABSMAX" ];then echo "Error ABSMAX for target $i" exit 1 fi if [ -z "$ABSMIN" ];then echo "Error ABSMIN for target $i" exit 1 fi if [ -z "$SNMP_COMMUNITY" ];then echo "Error Missing SNMP_COMMUNITY for target $i" exit 1 fi if [ -z "$SNMP_HOST" ];then echo "Error Missing SNMP_HOST for target $i" exit 1 fi if [ -n "$SNMP_IF" ] && [ -n "$SNMP_OID_IN" ];then echo "Error Choose SNMP_IF or SNMP_OID_IN SNMP_OID_OUT for target $i" exit 1 fi if [ -n "$SNMP_IF" ] && [ -n "$SNMP_OID_OUT" ];then echo "Error Choose SNMP_IF or SNMP_OID_IN SNMP_OID_OUT for target $i" exit 1 fi if [ -n "$SNMP_IF" ] && [ -z "$SNMP_NUMBER" ];then echo "Error SNMP_IF requires SNMP_NUMBER for target $i" exit 1 fi # if rrd file does not exist for target, create it!! if ! [ -f "$LOGS"/"$i".rrd ]; then $MRTNK/rrd-tnk create $i.rrd $TYPE $FREQ $ABSMIN $ABSMAX else # Make a systematic update of AMSMAX, ABSMIN and TYPE $RRD tune $LOGS/$i.rrd -i ds0:$ABSMIN -a ds0:$ABSMAX -d ds0:$TYPE $RRD tune $LOGS/$i.rrd -i ds1:$ABSMIN -a ds1:$ABSMAX -d ds1:$TYPE fi ### SNMP interfaces ###### if [ -n "$SNMP_IF" ];then SNMP_RESULT=`$SNMPGET -Oqv $SNMP_HOST $SNMP_COMMUNITY ifInOctets.$SNMP_NUMBER ifOutOctets.$SNMP_NUMBER ifDescr.$SNMP_NUMBER` CHECK=`echo $SNMP_RESULT|cut -d" " -f3` if [ $CHECK != $SNMP_IF ];then echo "Error for target $i, SNMP_NUMBER is not right" echo "run again mrtnk-confmake to check your configuration" exit 1 fi IN=`echo $SNMP_RESULT|cut -d" " -f1` OUT=`echo $SNMP_RESULT|cut -d" " -f2` fi ######## end SNMP interfaces ########## ### SNMP OIDS #### if [ -n "$SNMP_OID_IN" ];then SNMP_RESULT=`$SNMPGET -Oqv $SNMP_HOST $SNMP_COMMUNITY $SNMP_OID_IN $SNMP_OID_OUT` IN=`echo $SNMP_RESULT|cut -d" " -f1` OUT=`echo $SNMP_RESULT|cut -d" " -f2` if [ -z "$OUT" ];then OUT=0 fi #### End SNMP OIDS ######## fi $RRD update $LOGS/$i.rrd N:$IN:$OUT done ######## End SNMP ########