Switchports InUse/Available

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

Moderators: Developers, Moderators

Post Reply
Fred
Cacti User
Posts: 81
Joined: Fri Jan 03, 2003 11:43 am

Switchports InUse/Available

Post by Fred »

I'd like to have a graph showing switchports "in use" versus available. Specifically for Cisco switches, but if it's SNMP based, I don't see why it wouldn't be more generic than that.

Does anybody more familiar with SNMP have a good idea on where to get this information? I could write a script to walk the 'up/down' state of the interfaces and keep counters, but perhaps there's a more direct way to get this information?
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Switchports InUse/Available

Post by gandalf »

Fred wrote:Does anybody more familiar with SNMP have a good idea on where to get this information? I could write a script to walk the 'up/down' state of the interfaces and keep counters, but perhaps there's a more direct way to get this information?
I would go the same way. Find help at the first link of my signature
Reinhard
Fred
Cacti User
Posts: 81
Joined: Fri Jan 03, 2003 11:43 am

Template and such

Post by Fred »

Well, I created this graph. I don't have a screenshot, but it shows ports in use and available. The script is a simple perl script that does an snmpwalk, so paths may need to be corrected.

It shows all ports, including virtual ones, so the readings might seem a little off. (i.e., you'll probably see 14 ports total on a 12-port switch).

Written for and tested on linux. Put the .pl script in your scripts directory, and import the .xml. No guarantee that it will work in your particular environment. It will probably work against non-cisco switches, as well.
Attachments
cisco_switchports.pl
The perl script
(327 Bytes) Downloaded 444 times
cacti_graph_template_cisco_switchports_availableinuse.xml
The XML
(14.66 KiB) Downloaded 594 times
User avatar
pgus
Cacti User
Posts: 55
Joined: Fri Feb 10, 2006 9:54 am

Zero value in grafh

Post by pgus »

Hi!

In logfile I get this:

SCRIPT: /usr/bin/perl /var/www/html/scripts/cisco_switchports.pl 192.168.0.1Public, output: total:0 up:0 down:0

And in my Data Imput Methods
/usr/bin/perl <path_cacti>/scripts/cisco_switchports.pl <ip><community>

If i run on server
/usr/bin/perl /var/www/html/scripts/cisco_switchports.pl 192.168.0.1 Public
Total:30 up:10 down:20

Can someone help me?

Thanks in advance
Fred
Cacti User
Posts: 81
Joined: Fri Jan 03, 2003 11:43 am

Re: Zero value in grafh

Post by Fred »

Is that space actually missing between the IP address and the community string? Your data input method should read:

Code: Select all

/usr/bin/perl <path_cacti>/scripts/cisco_switchports.pl <ip> <community>
That space is going to be very important. But perhaps it was just a copy and paste problem.
User avatar
pgus
Cacti User
Posts: 55
Joined: Fri Feb 10, 2006 9:54 am

Post by pgus »

Uppdated script, my friend Jesper Ekberg solved problem with virtual ports.
Attachments
cisco_switchports.pl
(704 Bytes) Downloaded 209 times
aleu
Cacti User
Posts: 216
Joined: Mon Dec 11, 2006 10:17 am

Post by aleu »

pgus wrote:Uppdated script, my friend Jesper Ekberg solved problem with virtual ports.
Hmm, nice template. I was wondering whether there is a way to make it more accurate though. First of all, if you have a 3560 switch it will report switch ports for each configured VLAN (and this number is not fixed as you may have different number of VLANs on each physical switch). Besides that it will list portchannel interfaces and the Null0 interface. On 3750s it will also count all stack ports, as well. Any idea whether it is do-able to re-write the perl script somehow to exclude these:

VLAN Interfaces
StackSub
StackPort Interfaces
Portchannel Interfaces
Null0 interface?

I looked into it, but I do not know perl.

Thanks,
AL
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

It's more the SNMP that you need to know. ifType tells you whether the port is a virtual one, or some other type. If the script is ONLY going to be used on an ethernet switch, then you should be able to skip all interfaces that don't have ifType of 6 (ethernetCsmacd).

That should correspond to the physical switch ports. Not sure what the stackports on a 3750 show up as though... (looks like they don't appear at all)
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

This works for me, for an all-ethernet switch. The '6' is the magic thing to ignore all other port types. (and the first walk is different, so as to collect the ifType and store it away)

and it doesn't use 'magic' to assume that the last couple of ports are virtual. I don't think the order that interfaces are listed in is a defined thing.
Attachments
cisco_switchports.pl
(764 Bytes) Downloaded 276 times
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
aleu
Cacti User
Posts: 216
Joined: Mon Dec 11, 2006 10:17 am

Post by aleu »

Howie wrote:This works for me, for an all-ethernet switch. The '6' is the magic thing to ignore all other port types. (and the first walk is different, so as to collect the ifType and store it away)

and it doesn't use 'magic' to assume that the last couple of ports are virtual. I don't think the order that interfaces are listed in is a defined thing.
Wow, that was a quick response. Thanks Howie, it seems that your updated script does the job correctly. I will post if I find any errors, but so far everything is looking god. Thanks a lot.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests