How can I graph active switch ports? Cisco 6509

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

Moderators: Developers, Moderators

Post Reply
User avatar
mschwen
Posts: 17
Joined: Thu Nov 06, 2008 1:03 pm
Location: Orem, Utah

How can I graph active switch ports? Cisco 6509

Post by mschwen »

Hey Cacti Pros,

This request is actually pretty simple, but I am not a cacti ninja yet, just know basic scripting.

I have a request from my boss at work, he needs to know how many active ports are on a specific switch over a given period of time. So switch X has X amount of ports Average over the last 2 weeks. It seems like you would pull SNMP on the switch finding all active/inactive ports then count them and graph that count. Can anyone help me out with this? That would be much appreciated.
“Sometimes the questions are complicated and the answers are simple.” - Dr. Suess

- Matthew Schwen
Network Engineer
Adobe Systems
druwade
Posts: 5
Joined: Tue Sep 06, 2011 3:11 am

Re: How can I graph active switch ports? Cisco 6509

Post by druwade »

I too would love this feature, if anyone can shed some light this would be excellent.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: How can I graph active switch ports? Cisco 6509

Post by noname »

mschwen wrote:how many active ports are on a specific switch over a given period of time
For example:
1) Create script which returns number of active ports
2) Use the script as Data Input Method in Cacti

See Walkthrough: My First Data Input Method - Cacti Docs


Below is my sample..

I don't know what OID has number of active ports.
So tried counting interfaces which ifOperStatus (.1.3.6.1.2.1.2.2.1.8) is "up".
% snmpwalk -Ov -v1 -c <community> <host> .1.3.6.1.2.1.2.2.1.8
INTEGER: down(2)
INTEGER: up(1)
INTEGER: up(1)
INTEGER: up(1)
INTEGER: down(2)
INTEGER: down(2)
INTEGER: down(2)
INTEGER: down(2)
INTEGER: down(2)
INTEGER: down(2)
INTEGER: down(2)
INTEGER: up(1)
INTEGER: up(1)
Script

Code: Select all

#!/bin/sh

/usr/local/bin/snmpwalk -Ov -v1 -c $1 $2 .1.3.6.1.2.1.2.2.1.8 | /usr/bin/grep -c up
Data Input Method
Image

Data Template
Image

Graph Template
Image

Graph
Image
minmei
Posts: 16
Joined: Thu Sep 28, 2006 1:02 pm

Re: How can I graph active switch ports? Cisco 6509

Post by minmei »

You can also do this - this script only looks at ports which have "Fast" in the the description (100mbps ports) and gives me total ports for the switch. We have 80-ish stacks on campus and it's nice to be able to see how many ports are active versus the total.

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;

if (file_exists(dirname(__FILE__) . "/../include/global.php")) {
        include(dirname(__FILE__) . "/../include/global.php");
}
include(dirname(__FILE__) . "/../include/config.php");
include(dirname(__FILE__) . "/../lib/snmp.php");


$hostname = $_SERVER["argv"][1];
$snmp_community = $_SERVER["argv"][2];
$snmp_version = $_SERVER["argv"][3];


$interfaceDescIndex = ".1.3.6.1.2.1.2.2.1.2";
$interfaceUpIndex = ".1.3.6.1.2.1.2.2.1.8";

$interfaceDescArray = reindex(cacti_snmp_walk($hostname, $snmp_community, $interfaceDescIndex, $snmp_version, "", "", "", "", "", "", 161, 1000));
$interfaceUpArray = reindex(cacti_snmp_walk($hostname, $snmp_community, $interfaceUpIndex, $snmp_version, "", "", "", "", "", "", 161, 1000));

#print_r($interfaceUpArray);

$interfaceCulledUpArray = cull($interfaceDescArray,$interfaceUpArray);

#print_r($interfaceCulledUpArray);

$findUpInterfaces= array_count_values($interfaceCulledUpArray);

#print_r($findUpInterfaces);

$interfacesUp=0;

if (array_key_exists("up(1)", $findUpInterfaces)) {
        $interfacesUp=$findUpInterfaces["up(1)"];
        }

$interfacesTotal = sizeof($interfaceCulledUpArray);

print "totalinterfaces:" . $interfacesTotal . " upinterfaces:" . $interfacesUp;

function reindex($arr) {
        $return_arr = array();

        for ($i=0;($i<sizeof($arr));$i++) {
                $return_arr[$i] = $arr[$i]["value"];
        }

        return $return_arr;
}

function cull($arrDesc,$arrUp) {
        $return_arr = array();
        $fast = "Fast";

        for ($i=0;($i<sizeof($arrDesc));$i++) {
                #print $arrDesc[$i] . strpos($arrDesc[$i],$fast);
                if (strpos($arrDesc[$i],$fast) !== false ) {
                        $return_arr[$i] = $arrUp[$i];
                }
        }

        return $return_arr;
}

?>
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: How can I graph active switch ports? Cisco 6509

Post by noname »

minmei wrote:You can also do this - this script only looks at ports which have "Fast" in the the description (100mbps ports) and gives me total ports for the switch.
Oh, that's good idea! :)
By that method, we can exclude logical ports (VLAN, Port-channel, Null interfaces, etc.) from counting.
User avatar
mschwen
Posts: 17
Joined: Thu Nov 06, 2008 1:03 pm
Location: Orem, Utah

Re: How can I graph active switch ports? Cisco 6509

Post by mschwen »

Thanks guys! This is perfect, I have actually successfully created the script. Its weird, when I run the script in the console it returns an number. But when Cacti runs the script it is returning 0 every time. Any Ideas?


[#######@ne2 scripts]$ sh activeports.sh ##### ########
183


10/04/2011 11:45:44 AM - SPINE: Poller[0] Host[68] TH[1] DS[1541] SCRIPT: /var/www/cacti/scripts/activeports.sh , output: 0
Attachments
Screen Shot 2011-10-04 at 11.50.07 AM.png
Screen Shot 2011-10-04 at 11.50.07 AM.png (26.32 KiB) Viewed 8995 times
“Sometimes the questions are complicated and the answers are simple.” - Dr. Suess

- Matthew Schwen
Network Engineer
Adobe Systems
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: How can I graph active switch ports? Cisco 6509

Post by noname »

Try to add the following blue line in crontab for debugging:
*/5 * * * * php /var/www/cacti/poller.php > /dev/null 2>&1
*/5 * * * * /var/www/cacti/scripts/activeports.sh ##### ######## >> /tmp/activeports.log 2>&1
Is there any error in that log?
User avatar
mschwen
Posts: 17
Joined: Thu Nov 06, 2008 1:03 pm
Location: Orem, Utah

Re: How can I graph active switch ports? Cisco 6509

Post by mschwen »

Looks to be working...

[root@ne2 tmp]# tail -f activeports.log
232
“Sometimes the questions are complicated and the answers are simple.” - Dr. Suess

- Matthew Schwen
Network Engineer
Adobe Systems
User avatar
mschwen
Posts: 17
Joined: Thu Nov 06, 2008 1:03 pm
Location: Orem, Utah

Re: How can I graph active switch ports? Cisco 6509

Post by mschwen »

Thanks for all the help guys! I love Cacti and will continue to use it in my environment, here at Adobe, for ever, mainly due to the amount of support!

Got it working, just needed to add sh to the beginning of my script command.
“Sometimes the questions are complicated and the answers are simple.” - Dr. Suess

- Matthew Schwen
Network Engineer
Adobe Systems
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: How can I graph active switch ports? Cisco 6509

Post by gandalf »

mschwen wrote:Thanks for all the help guys! I love Cacti and will continue to use it in my environment, here at Adobe, for ever, mainly due to the amount of support!
Hey! We should consider visiting you next year at Adobe on our yearly Cacti Developer Meeting :wink:
R.
wasserbox
Posts: 2
Joined: Fri Feb 10, 2012 12:54 pm

Re: How can I graph active switch ports? Cisco 6509

Post by wasserbox »

minmei wrote:You can also do this - this script only looks at ports which have "Fast" in the the description (100mbps ports) and gives me total ports for the switch.
Thanks for this. Through much trial, error, and RTFM I got it working. I'm not much of a coder - more of a muddler.
I edited it to use "Ether" since we are moving a lot of stuff over to 1 &10G ports.
Also changed it to use "Async" to graph inbound modem usage on some AS5350's - which is something my boss has been bugging me about for years.
Attachments
graph_image.php.png
graph_image.php.png (21.29 KiB) Viewed 8606 times
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests