How can I graph active switch ports? Cisco 6509
Moderators: Developers, Moderators
How can I graph active switch ports? Cisco 6509
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.
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
- Matthew Schwen
Network Engineer
Adobe Systems
Re: How can I graph active switch ports? Cisco 6509
I too would love this feature, if anyone can shed some light this would be excellent.
Re: How can I graph active switch ports? Cisco 6509
For example:mschwen wrote:how many active ports are on a specific switch over a given period of time
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".
Script% 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)
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 Template
Graph Template
Graph
Re: How can I graph active switch ports? Cisco 6509
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;
}
?>
Re: How can I graph active switch ports? Cisco 6509
Oh, that's good idea! :)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.
By that method, we can exclude logical ports (VLAN, Port-channel, Null interfaces, etc.) from counting.
Re: How can I graph active switch ports? Cisco 6509
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
[#######@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 (26.32 KiB) Viewed 9008 times
“Sometimes the questions are complicated and the answers are simple.” - Dr. Suess
- Matthew Schwen
Network Engineer
Adobe Systems
- Matthew Schwen
Network Engineer
Adobe Systems
Re: How can I graph active switch ports? Cisco 6509
Try to add the following blue line in crontab for debugging:
Is there any error in that log?*/5 * * * * php /var/www/cacti/poller.php > /dev/null 2>&1
*/5 * * * * /var/www/cacti/scripts/activeports.sh ##### ######## >> /tmp/activeports.log 2>&1
Re: How can I graph active switch ports? Cisco 6509
Looks to be working...
[root@ne2 tmp]# tail -f activeports.log
232
[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
- Matthew Schwen
Network Engineer
Adobe Systems
Re: How can I graph active switch ports? Cisco 6509
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.
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
- Matthew Schwen
Network Engineer
Adobe Systems
- 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
Hey! We should consider visiting you next year at Adobe on our yearly Cacti Developer Meetingmschwen 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!
R.
Re: How can I graph active switch ports? Cisco 6509
Thanks for this. Through much trial, error, and RTFM I got it working. I'm not much of a coder - more of a muddler.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.
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 (21.29 KiB) Viewed 8619 times
Who is online
Users browsing this forum: No registered users and 0 guests