Juniper BGP received prefixes - Script query

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
Hinzel
Posts: 16
Joined: Thu Feb 18, 2010 6:01 pm

Juniper BGP received prefixes - Script query

Post by Hinzel »

Hey All,

I have created a script query to graph the # of received prefixes over a BGP session. The script itself works from the command line when passing arguments to it, and I can add it to a device in Cacti as a data query and successfully retrieve indexes, peer ip, # of received prefixes, etc...

However it looks like the script query is not actually being executed, no rrd files are created, and nothing is placed in the poller cache.

Can someone please take a look at this and let me know where I went wrong? Thanks a bunch.

Unfortunately JunOS requires 2 look ups, as the BGP index and IP address are stored in a diff table then the # of received prexifes. Which is why I'm doing a script query rather then a basic snmp query. Also you cannot do an snmpget on the second lookup which contains the # of received prefixes, you have to do another walk.

Output is below. Please let me know if you need anything else. Thanks!

IPs have been replaced with x's, community string has also been taken out.

Code: Select all

+ Running data query [59].
+ Found type = '6 '[script query].
+ Found data query XML file at '/home/mhinzel/cacti/resource/script_queries/juniper_bgp.xml'
+ XML file parsed ok.
+ Executing script for list of indexes '/usr/bin/php5 -q /home/mhinzel/cacti/scripts/juniperbgpreceived.php x.x.x.x 2:161:10000:1:10:cstring:::MD5::DES: index'
+ Executing script query '/usr/bin/php5 -q /home/mhinzel/cacti/scripts/juniperbgpreceived.php x.x.x.x 2:161:10000:1:10:cstring:::MD5::DES: query index'
+ Executing script query '/usr/bin/php5 -q /home/mhinzel/cacti/scripts/juniperbgpreceived.php x.x.x.x 2:161:10000:1:10:cstring:::MD5::DES: query peerip'
+ Found item [hrPeerIP='x.x.x.x'] index: 52
+ Found item [hrPeerIP='x.x.x.x'] index: 44
...(output trimmmed)
+ Found data query XML file at '/home/mhinzel/cacti/resource/script_queries/juniper_bgp.xml'
+ Found data query XML file at '/home/mhinzel/cacti/resource/script_queries/juniper_bgp.xml'
+ Found data query XML file at '/home/mhinzel/cacti/resource/script_queries/juniper_bgp.xml'

Code: Select all

cacti:~/cacti/resource/script_queries$ /usr/bin/php5 -q /home/mhinzel/cacti/scripts/juniperbgpreceived.php x.x.x.x 2:161:10000:1:10:cstring:::MD5::DES: get received 10
214418

Code: Select all

cacti:~/cacti/resource/script_queries$ /usr/bin/php5 -q /home/mhinzel/cacti/scripts/juniperbgpreceived.php x.x.x.x 2:161:10000:1:10:cstring:::MD5::DES: index
52
44
45
46
53
47
....

Code: Select all

cacti:~/cacti/resource/script_queries$ /usr/bin/php5 -q /home/mhinzel/cacti/scripts/juniperbgpreceived.php x.x.x.x 2:161:10000:1:10:cstring:::MD5::DES: query peerip
52!x.x.x.x
44!x.x.x.x
45!x.x.x.x
46!x.x.x.x

XML file:

Code: Select all

<interface>
        <name>Juniper BGP Peer received prefixes</name>
        <script_path>|path_php_binary| -q |path_cacti|/scripts/juniperbgpreceived.php</script_path>
        <arg_prepend>|host_hostname| |host_snmp_version|:|host_snmp_port|:|host_snmp_timeout|:|host_ping_retries|:|host_max_oids|:|host_snmp_community|:|host_snmp_username|:|host_snmp_password|:|host_snmp_auth_protocol|:|host_snmp_priv_passphrase|:|host_snmp_priv_protocol|:|host_snmp_context|</arg_prepend>
        <arg_index>index</arg_index>
        <arg_query>query</arg_query>
        <arg_get>get</arg_get>
        <output_delimeter>!</output_delimeter>
        <index_order>hrPeerIndex</index_order>
        <index_order_type>numeric</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <hrPeerIndex>
                        <name>Index</name>
                        <direction>input</direction>
                        <query_name>index</query_name>
                </hrPeerIndex>
                <hrPeerIP>
                        <name>BGP Peer IP</name>
                        <direction>input</direction>
                        <query_name>peerip</query_name>
                </hrPeerIP>
                <hrPrefixes>
                        <name>Prefixes Received</name>
                        <direction>output</direction>
                        <query_name>received</query_name>
                </hrPrefixes>
        </fields>
</interface>
Hinzel
Posts: 16
Joined: Thu Feb 18, 2010 6:01 pm

Post by Hinzel »

Code: Select all

<?php


/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
   die("<br><strong>This script is only meant to run at the command line.</strong>");
}

$no_http_headers = true;

include(dirname(__FILE__)."/../include/global.php");
include(dirname(__FILE__)."/../lib/snmp.php");

$oids = array(
        "index"                 => ".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14",
        "peerip"                => ".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14",
        "received"              => ".1.3.6.1.4.1.2636.5.1.1.2.6.2.1.7",
        );
$xml_delimiter                  =  "!";

$hostname       = $_SERVER["argv"][1];
$snmp_auth      = $_SERVER["argv"][2];
$cmd            = $_SERVER["argv"][3];

/* support for SNMP V2 and SNMP V3 parameters */
$snmp = explode(":", $snmp_auth);
$snmp_version   = $snmp[0];
$snmp_port      = $snmp[1];
$snmp_timeout   = $snmp[2];
$ping_retries   = $snmp[3];
$max_oids               = $snmp[4];

$snmp_auth_username     = "";
$snmp_auth_password     = "";
$snmp_auth_protocol     = "";
$snmp_priv_passphrase   = "";
$snmp_priv_protocol     = "";
$snmp_context           = "";
$snmp_community                 = "";

if ($snmp_version == 3) {
        $snmp_auth_username   = $snmp[6];
        $snmp_auth_password   = $snmp[7];
        $snmp_auth_protocol   = $snmp[8];
        $snmp_priv_passphrase = $snmp[9];
        $snmp_priv_protocol   = $snmp[10];
        $snmp_context         = $snmp[11];
}else{
        $snmp_community = $snmp[5];
}


/* process index requests */
if ($cmd == "index") {
        $return_arr = cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);

        foreach ($return_arr as $arr) {
                print $arr["value"] . "\n";
        }

/* process query requests */
} elseif ($cmd == "query") {
        $arg = $_SERVER["argv"][4];

        if ($arg == "peerip") {
                $return_arr = cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                foreach ($return_arr as $arr) {
                        $temp = explode(".", $arr["oid"]);
                        $peer["ip"] = $temp[22] . "." . $temp[23] . "." . $temp[24] . "." . $temp[25];
                        print $arr["value"] . "!" . $peer["ip"] . "\n";
                }
        } elseif ($arg == "received") {
                $return_arr = cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                foreach ($return_arr as $arr) {

                        $return_arr2 = cacti_snmp_walk($hostname, $snmp_community, $oids[$arg] . "." . $arr["value"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                        foreach ($return_arr2 as $arr2) {
                                if ($arr2["value"]) {
                                        print $arr["value"] . "!" . $arr2["value"] . "\n";
                                }
                        }
                }
        }

/* process prefix requests */
} elseif ($cmd == "get") {
        $arg = $_SERVER["argv"][4];
        $index = $_SERVER["argv"][5];

        if ($arg == "received") {
                $return_arr2 = cacti_snmp_walk($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                foreach ($return_arr2 as $arr) {
                        if ($arr["value"]) {
                                print $arr["value"];
                        }
                }
        }
}

?>
Hinzel
Posts: 16
Joined: Thu Feb 18, 2010 6:01 pm

Post by Hinzel »

I have added this to a secondary cacti instance i have running, and turned debugging up to the highest level.

I see polling for other OIDs showing up for this host in the log file, but nothing for this actual query. Also there are no errors or anything, just nothing shows up in the logs.
Hinzel
Posts: 16
Joined: Thu Feb 18, 2010 6:01 pm

Post by Hinzel »

Whoops, figured out the issue on this one. Did not have a valid results being returned for "query index". This has since been fixed, and updated script query can be found below.

If anyone has any interest in this query I can provide my data template, graph template, and data query setup. However they are all quite basic. Otherwise feel free to create your own. Enjoy!

Code: Select all

<?php


/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
   die("<br><strong>This script is only meant to run at the command line.</strong>");
}

$no_http_headers = true;

include(dirname(__FILE__)."/../include/global.php");
include(dirname(__FILE__)."/../lib/snmp.php");

$oids = array(
        "index"                 => ".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14",
        "peerip"                => ".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14",
        "received"              => ".1.3.6.1.4.1.2636.5.1.1.2.6.2.1.7",
        );
$xml_delimiter                  =  "!";

$hostname       = $_SERVER["argv"][1];
$snmp_auth      = $_SERVER["argv"][2];
$cmd            = $_SERVER["argv"][3];

/* support for SNMP V2 and SNMP V3 parameters */
$snmp = explode(":", $snmp_auth);
$snmp_version   = $snmp[0];
$snmp_port      = $snmp[1];
$snmp_timeout   = $snmp[2];
$ping_retries   = $snmp[3];
$max_oids               = $snmp[4];

$snmp_auth_username     = "";
$snmp_auth_password     = "";
$snmp_auth_protocol     = "";
$snmp_priv_passphrase   = "";
$snmp_priv_protocol     = "";
$snmp_context           = "";
$snmp_community                 = "";

if ($snmp_version == 3) {
        $snmp_auth_username   = $snmp[6];
        $snmp_auth_password   = $snmp[7];
        $snmp_auth_protocol   = $snmp[8];
        $snmp_priv_passphrase = $snmp[9];
        $snmp_priv_protocol   = $snmp[10];
        $snmp_context         = $snmp[11];
}else{
        $snmp_community = $snmp[5];
}


/* process index requests */
if ($cmd == "index") {
        $return_arr = cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);

        foreach ($return_arr as $arr) {
                print $arr["value"] . "\n";
        }

/* process query requests */
} elseif ($cmd == "query") {
        $arg = $_SERVER["argv"][4];

        if ($arg == "peerip") {
                $return_arr = cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                foreach ($return_arr as $arr) {
                        $temp = explode(".", $arr["oid"]);
                        $peer["ip"] = $temp[22] . "." . $temp[23] . "." . $temp[24] . "." . $temp[25];
                        print $arr["value"] . "!" . $peer["ip"] . "\n";
                }
        } elseif ($arg == "received") {
                $return_arr = cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                foreach ($return_arr as $arr) {

                        $return_arr2 = cacti_snmp_walk($hostname, $snmp_community, $oids[$arg] . "." . $arr["value"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                        foreach ($return_arr2 as $arr2) {
                                if ($arr2["value"]) {
                                        print $arr["value"] . "!" . $arr2["value"] . "\n";
                                }
                        }
                }
        } elseif ($arg == "index") {
                $return_arr = cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);

                foreach ($return_arr as $arr) {
                        print $arr["value"] . "!" . $arr["value"] . "\n";
                }
        }

/* process prefix requests */
} elseif ($cmd == "get") {
        $arg = $_SERVER["argv"][4];
        $index = $_SERVER["argv"][5];

        if ($arg == "received") {
                $return_arr2 = cacti_snmp_walk($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER);
                foreach ($return_arr2 as $arr) {
                        if ($arr["value"]) {
                                print $arr["value"];
                        }
                }
        }
}

?>
scottevil
Posts: 24
Joined: Tue Nov 28, 2006 6:44 am
Location: Akron
Contact:

Re: Juniper BGP received prefixes - Script query

Post by scottevil »

I tried it with a script first too, but then figured out how to do it as a data query. I believe the Cisco is set up the same way, check out this data query as a template
ttp://forums.cacti.net/viewtopic.php?f=12&t=36770&start=0&hilit=bgp
Scott McCarty
Solutions Architect/Open Source Evangelist
Twitter: @fatherlinux
URL: http://crunchtools.com
pluxton
Posts: 4
Joined: Fri May 13, 2011 12:41 pm

Re: Juniper BGP received prefixes - Script query

Post by pluxton »

Hi guys,
I've tried both of these methods and come up short on both.
I'm trying to get them working for Juniper.
I'm not even sure which one I'm closer to a resolution on. Let's start with the snmp query.
For the snmp query, I get Nan results. One thing that I think might be wrong is that in the snmp query for prefixes, the OID is .1.3.6.1.4.1.2636.5.1.1.2.6.2.1.7
If I do an SNMP walk on this, I get the following results:

snmpwalk -v 2c -c password 172.24.x.x 1.3.6.1.4.1.2636.5.1.1.2.6.2.1.7
SNMPv2-SMI::enterprises.2636.5.1.1.2.6.2.1.7.0.1.1 = Gauge32: 355564
SNMPv2-SMI::enterprises.2636.5.1.1.2.6.2.1.7.1.1.1 = Gauge32: 1
SNMPv2-SMI::enterprises.2636.5.1.1.2.6.2.1.7.2.1.1 = Gauge32: 350240

Seems to be working fine. But note that after the 7 it appends y.1.1, where y is the index of the peer.
But in looking at the poller cache, I see the following (note that I removed the oid_suffix that existed in the ebgp_ibgp.xml script). It wants to append the IP address, and not this y.1.1.

SNMP Version: 2, Community: password, OID: 1.3.6.1.4.1.2636.5.1.1.2.6.2.1.7.x.x.x.x
RRD: /var/www/cacti_v0.8.7e/rra/lax1-rt-01_received_1929.rrd

where x.x.x.x is the neighbor IP address.

So how can I get the xml query to stop appending the IP address? As the Juniper wants to see the index in the form of y.1.1

Thanks in advance - if I'm close on this, then I'll continue on, otherwise I'll post what problems I'm having with the script (like not creating an RRD file, I created one, now that's working, but the query attempt still does not show up in the poller cache, nor does it show up in the cacti log when I set it to debug).

Hope you can help!
Patty
pluxton
Posts: 4
Joined: Fri May 13, 2011 12:41 pm

Re: Juniper BGP received prefixes - Script query

Post by pluxton »

NM - I think I figured out how to put append the index rather than IP. I will post when I get this part resolved if it's still not graphing.
Thanks,
Patty
pluxton
Posts: 4
Joined: Fri May 13, 2011 12:41 pm

Re: Juniper BGP received prefixes - Script query

Post by pluxton »

Forget that. I have no idea how to append the index juniper is expecting vs. the IP address.
Thanks for any help!
Patty
pluxton
Posts: 4
Joined: Fri May 13, 2011 12:41 pm

Re: Juniper BGP received prefixes - Script query

Post by pluxton »

Got it got it. My problem is that I had the Juniper specific OID for the prefixes, but then the generic BGP mib for the rx and tx. I changed the oid_index to a x.x.x syntax, and changed all other OIDs to be Juniper specific. Let's cross our fingers.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests