Graphing Dynamically Changing index

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
zankaleesh
Posts: 20
Joined: Sun Nov 07, 2010 6:28 am

Graphing Dynamically Changing index

Post by zankaleesh »

Hi

We have some Juniper e320 BRAs devices for which we want to monitor L2TP tunnels coming from the MPLS network.

These tunnels have the same IP address and the same name always but for the fact that these tunnels are dynamically created or terminated they frequently change their INDEX values.
Another issue would be that at times there are two logical tunnels for the same IP with two different sessions values

Here is a sample output for the snmp queries

Code: Select all


These are the INDEX values
snmpwalk -Ov -c community -v2c dsl-1 .1.3.6.1.4.1.4874.2.2.35.1.3.4.2.1.2
INTEGER: 335548244
INTEGER: 335548026
INTEGER: 335548054
INTEGER: 335544354
INTEGER: 335546114
INTEGER: 335544348
INTEGER: 335546315

And these are the IP addresses
snmpwalk -Ov -c community -v2c dsl-1 .1.3.6.1.4.1.4874.2.2.35.1.5.1.3.1.1.7
IpAddress: 192.168.1.50
IpAddress: 192.168.1.14
IpAddress: 192.168.1.50
IpAddress: 192.168.1.40
IpAddress: 192.168.1.40
IpAddress: 192.168.1.13
IpAddress: 192.168.1.13


And the session per tunnel as follows
snmpwalk -Ov -c community -v2c dsl-1 .1.3.6.1.4.1.4874.2.2.35.1.3.2.1.1.23
Gauge32: 12
Gauge32: 11
Gauge32: 448
Gauge32: 220
Gauge32: 7
Gauge32: 327
Gauge32: 7

Any ideas on how to build the xml file for the above would be greatly appreciated.
And how is it possible to sum up the sessions for the same tunnel IP.

If this is not doable then here is what I am thinking and let me know if there would be a more efficient/easier way
I am thinking to get the values and store them in a database then sum them up with select queries, then again i will have to do a select query for each tunnel and i am not quite sure how that is going to be at the moment.

Thank you in advance and looking forward to your replies
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Re: Graphing Dynamically Changing index

Post by BSOD2600 »

Looks like a typical SNMP XML script will work for collecting the data.

Since the indexes change frequently, looks like you'll have to use a reindex method of always verify.

As for summing the sessions... you can either graph them individually and then sum in a graph (using aggregate plugin) or write a script to sum them and spit the number out to Cacti.
zankaleesh
Posts: 20
Joined: Sun Nov 07, 2010 6:28 am

Re: Graphing Dynamically Changing index

Post by zankaleesh »

Thanks BSOD2600

I am writing a script for it and will post the results when done
zankaleesh
Posts: 20
Joined: Sun Nov 07, 2010 6:28 am

Re: Graphing Dynamically Changing index

Post by zankaleesh »

Hi

Now I wrote a script to output what I want to a text file.

Code: Select all


#!/bin/sh

device=$1
community=snmp_community
tempfile=/tmp/tunnels/$device
tunnelfile=/tmp/tunnels/$device.t
index=(`snmpwalk  -c $community -v2c $device .1.3.6.1.4.1.4874.2.2.35.1.5.1.3.1.1.7 | egrep -o "[0-9]{7,10}"`)
ips=(`snmpwalk -Ov -c $community -v2c  $device .1.3.6.1.4.1.4874.2.2.35.1.5.1.3.1.1.7 | awk '{print $2}'`)
descr=(`snmpwalk -Ov -c $community -v2c $device .1.3.6.1.4.1.4874.2.2.35.1.3.2.1.1.8 | awk '{print $2}'`)
sessions=(`snmpwalk -Ov -c $community -v2c $device .1.3.6.1.4.1.4874.2.2.35.1.3.2.1.1.23 | awk '{print $2}'`)

lenx=${#index[*]}
i=0
while [ $i -lt $lenx ]; do

echo  ${ips[$i]} ${descr[$i]} ${sessions[$i]} >> $tempfile

       let i++
done

y=1
while read ip descr; do
        session=`grep "$ip "  $tempfile | awk '{sum+=$NF} END {print sum + 0}'`
        echo $y $ip $descr $session
        let y++
done < tunnels > $tunnelfile

#tunnels is a file that contains tunnelIP  tunnelNAME
This script gets me the results I want in a text file for each BRAs as

Code: Select all

1 192.168.1.1 tunnel1 396
2 192.168.1.2 tunnel2 630
3 192.168.1.3 tunnel3 547
4 192.168.1.4 tunnel4 551
5 192.168.1.5 tunnel5 509
6 192.168.1.6 tunnel6 356
.
.
.
I am confused to how can I construct an xml that will read this file? considering the columns order as follows
INDEX, tIP, tDescr, tSessions

I would appreciate any comments to enhance my script or solve my problem

Thank you
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Re: Graphing Dynamically Changing index

Post by BSOD2600 »

Since you're just doing SNMP calls, I'd strongly suggest you make it compatible with the php script server for optimum performance. http://docs.cacti.net/manual:087:3a_adv ... ipt_server

Otherwise to continue to use your script http://docs.cacti.net/manual:087:3a_adv ... alkthrough
zankaleesh
Posts: 20
Joined: Sun Nov 07, 2010 6:28 am

Re: Graphing Dynamically Changing index

Post by zankaleesh »

BSOD2600 wrote:Since you're just doing SNMP calls, I'd strongly suggest you make it compatible with the php script server for optimum performance. http://docs.cacti.net/manual:087:3a_adv ... ipt_server

Otherwise to continue to use your script http://docs.cacti.net/manual:087:3a_adv ... alkthrough
Thanks a million BSOD2600

Wow I think I have the ugliest script ever made for cacti now, but it works as I want.

Now I have this script running every 5 minutes by a cron job
#!/bin/sh

routerfile=/pathto/ROUTERS
comm=snmpcommunity
tempfile=/tmp/tunnels/$device
tunnelfile=/tmp/tunnels/$device.t

for device in `cat $routerfile`; do

index=(`snmpwalk -c $comm -v2c $device .1.3.6.1.4.1.4874.2.2.35.1.5.1.3.1.1.7 | egrep -o "[0-9]{7,10}"`)
ips=(`snmpwalk -Ov -c $comm -v2c $device .1.3.6.1.4.1.4874.2.2.35.1.5.1.3.1.1.7 | awk '{print $2}'`)
descr=(`snmpwalk -Ov -c $comm -v2c $device .1.3.6.1.4.1.4874.2.2.35.1.3.2.1.1.8 | awk '{print $2}'`)
sessions=(`snmpwalk -Ov -c $comm -v2c $device .1.3.6.1.4.1.4874.2.2.35.1.3.2.1.1.23 | awk '{print $2}'`)

lenx=${#index[*]}
if [ -a $tempfile ]
then rm -f $tempfile
fi

i=0
while [ $i -lt $lenx ]; do

echo ${ips[$i]} ${descr[$i]} ${sessions[$i]} >> $tempfile

let i++
done

y=1
while read ip descr; do
session=`grep "$ip " $tempfile | awk '{sum+=$NF} END {print sum + 0}'`
echo $y $ip $descr $session
let y++

done < pathto/tunnels > $tunnelfile
done
And another script to be called by the XML file
#!/bin/sh

device=$1
file=/tmp/tunnels/$device.t
arg=$2
indexarg=($3-1)
ind=(`cat $file | awk '{print $1}'`)

if [[ $arg == index ]]
then cat $file | awk '{print $1":"$1}'
elif [[ $arg == tunnel ]]
then cat $file | awk '{print $1":"$2}'
elif [[ $arg == descr ]]
then cat $file | awk '{print $1":"$3}'
elif [[ $arg == sessions ]]
then grep -e ^"${ind[$indexarg]} " $file | awk '{print $NF}'

fi
And the XML file

Code: Select all

<interface>
        <name>Get Tunnels</name>
        <description>Get l2tp tunnels</description>
        <script_path>sh /tmp/tunnels/data.sh</script_path>
        <arg_prepend>|host_hostname|</arg_prepend>
        <arg_index>index</arg_index>
        <output_delimeter>:</output_delimeter>

        <fields>
                <index>
                        <name>index</name>
                        <direction>input</direction>
                        <query_name>index</query_name>
                </index>
                <descr>
                        <name>Description</name>
                        <direction>input</direction>
                        <query_name>descr</query_name>
                </descr>

                <tunnel>
                        <name>Tunnel IP</name>
                        <direction>input</direction>
                        <query_name>tunnel</query_name>
                </tunnel>
                <sessions>
                        <name>sessions</name>
                        <direction>output</direction>
                        <query_name>sessions</query_name>
                </sessions>
        </fields>
</interface>
I know I will be writing this in php later as I learn more about it but for now it does the job
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest