Feb 122010
 

Recently I had to prepare for a Zenoss upgrade. During my prep work I had to create a zenpack of all of our Templates. For those of you who use Zenoss, you know how many templates you can start to accumulate in a short amount of time. You can have Templates attached to single Devices, to SubClasses, and to Classes. Now if you have a few devices this is not a big deal. But if you have a couple hundred to a couple of thousand devices, this could be a real hassle.

Now you can take a ton of your time and review Class by Class and Device by Device until you finally finish. You will eventually get it all in a Zenpack……. Well lucky for you guys I created a Python Script that runs as the Zenoss user and create a Zenpack for you. All you have to do is pick a name for the ZenPack and optionally the Device Class you want to scan. The script will scan the Device Class that you specified ( or by default scan the entire /Device Class and its Sub Classes). It will then create the ZenPack with all the locally attached Device Templates. I am thinking of also adding the Events class as part of the next release of this script.

Update 1.0.1, I added the –unique option. If you decide to use this option, This Zenpack will only add, The Device Templates that are not already part of an existing ZenPack. I also added the –verbose option, so that you can see which Device Templates are being added or being dismissed.

You can download the script here
Download

Continue reading “HowTo backup all of your Zenoss Templates the easy way.” »

Feb 072010
 

In this HowTo, I will show you how you can get statistics off of the Netscaler without using SNMP. You might be asking why would I want to do that?? Well like many other devices that support SNMP, the Netscaler makes use of dynamic OID creation. For those of you that do not understand what I mean. Dynamic OID creation, is the way that Networking devices give OID’s to variables that are not static in the device itself.

Here are some common static variables/OID’s, amongst most devices out there.

  • CPU Utilization
  • Disk Utilization
  • Memory Utilization
  • TCP Statistics

Here are some common, non-static variables/OID’s..

  • A Load Balanced Virtual Server
  • Statistics about LUNS
  • Statistics about Services

Now you can get these statistics off of the SNMP based device. But if and when this device is rebooted, more then likely the OID has changed. Now you are stuck with the task, of finding the new OID. Since the Netscalers have a SOAP Based API, we can get those same statistics with out ever needing to know the OID.

Here I have attached a script that I wrote, using Python and Suds to connect to the Netscaler. This script works perfectly with Zenoss and its DataPoint structure. Download

Continue reading “HowTo monitor the Netscaler using Python and Soap instead of SNMP” »

Feb 012010
 

Recently I just started to use the Citrix Netscalers again ( Load Balancers ). Being the person that I am, I wanted a way to grab the information using the SOAP API.
Now Citrix has a ton of documentation for Perl/C/C# and Java ( None for Python ). SOAP client support has not been the best for Python, in my opinion.
I know you have soappy/ZSI, which I have had issues with consuming Broken WSDL files ( Having to fix the Broken WSDL file manually, SUCKS!).

Just 2 weeks ago, I encounterd SUDS. This module is by far, the best SOAP client for Python.
There documentation is simple and straight to the point, with a bunch of nice samples to get you on your way.

Install SUDS before proceeding further. You can get suds from here. https://fedorahosted.org/suds/
Connection to my netscaler was as simple as this…

Python 2.4.3 (#1, Sep  3 2009, 15:37:37)[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)]
on linux2Type "help", "copyright", "credits" or "license" for more information.
>>> from suds.client import Client
>>> url = "http://nsip/api/NSConfig.wsdl"
>>> from suds.xsd.doctor import *
>>> imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
>>> imp.filter.add("urn:NSConfig")
>>> d = ImportDoctor(imp)
>>> client = Client(url, doctor=d, location="http://nsip/soap/")
>>> client.service.login(username="login", password="pass")(simpleResult){ rc = 0 message = "Done" }
>>>

Continue reading “How to get information from the Netscaler using Python and Suds.” »

Sep 102009
 
This new script is for Network Engineers and System Engineers a like. Though I must admit it is more for the System Engineers who do not have access to the command line on the CDP enabled device. Have you ever wanted to know what CDP enabled devces ( and info related to those devices ) that were directly connected to your your Core Switch? But you just do not have the access to get that info. But you do have access to the monitoring system, which has SNMP access to the Core Switch.

Well this is where my script comes into play... Stay tuned for updates, as I'm planning on adding to this script. So you can run it with the detail option and a detail port option. Please post any support related question in the forums here..http://www.linuxdynasty.org/forums/Scripting/scripting/sh_cdp_neighbor_help

Revision 1.2 9/13/2009
  • Catch all CDP connected switches, even if there is more then 1 switch seen through 1 port.

Revision 1.1 9/11/2009

  • Added –type option ( –type=detail )
Revision 1.0 9/10/2009
  • This script is the equivalent of sho cdp nei on a cisco switch, but this is using snmp.
When you log into a switch and run a show cdp neighbor, your info might look a little like this.. show cdp neighborCapability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone Device ID Local Intrfce Holdtme Capability Platform Port ID71_5th_SW1 Gig 10/15 145 S I WS-C2960G-Gig 0/48D_M1001_V180_SW1 Gig 1/42 132 S I WS-C2960G-Gig 0/1D_M1001_V181_SW1 Gig 1/46 136 S I WS-C2960G-Gig 0/1D_M1001_V181_SW2 Gig 1/47 166 S I WS-C2960G-Gig 0/1D_M1001_V180_SW3 Gig 1/43 147 S I WS-C2960G-Gig 0/1D_M1001_V181_SW3 Gig 1/48 158 S I WS-C2960G-Gig 0/1D_M1001_V180_SW2 Gig 1/41 141 S I WS-C2960G-Gig 0/1D_M1001_V181_SW4 Gig 1/44 179 S I WS-C2960G-Gig 0/1D_M1001_V180_SW4 Gig 1/40 145 S I WS-C3560G-Gig 0/1D_M701_V177_SW4 Gig 10/7 174 S I WS-C2970G-Gig 0/25D_M701_V177_SW1 Gig 10/6 154 S I WS-C2970G-Gig 0/25Router Gig 10/1 162 R S WS-C6513 Gig 9/9Router1 Gig 10/14 168 R S WS-C6513 Gig 9/1679_18th_Fl_SW1 Gig 10/12 174 S I WS-C2960G-Gig 0/48D_1700_V187_SW1 Gig 10/13 129 S I WS-C3560G-Gig 0/28D_1700_V187_SW3 Gig 10/10 146 S I WS-C2960G-Gig 0/48D_1700_V187_SW2 Gig 10/9 148 S I WS-C2960G-Gig 0/48D_522_V176_SW1 Gig 10/3 121 S I WS-C2970G-Gig 0/25D_522_V176_SW4 Gig 10/4 125 S I WS-C2970G-Gig 0/25D_CL001_V200_SW1 Gig 10/11 125 S I WS-C2960G-Gig 0/242W_4507R Gig 7/2 147 R S I WS-C4507R Gig 3/9

Now this is how it will look if you run sh_cdp_neighbor.py script…

Continue reading “HowTo get CDP neighbor information through Python and SNMP” »

Apr 122009
 

 

In my previous HowTO, I created the get_port.py script. Now this script did the job, but had a few faults in it.

  • Major fault was the fact that the script could not match multiple MAC
    Addresses per port
  • Also if the port had multiple MAC Addresses it usually would fail while doing the search
  • Better error checking. For example if you searched by IP Address before, the error was ambiguous.
    Now the error will say the IP Address you are looking for is not in the ARP Table

This script has been heavily tested on Cisco Core Switches and on Cisco Catalyst Switches. So far no issues like in the previous one.
I will post some of my output below so you can get an idea on how the script works.

Also to see the script in action immediately, you should run the command like this..

python port_report.py -d 192.168.101.1 -c public -n "1/40"

The reason you should run the above first, is that if the ip address you are searching for is not in the ARP table you will not get any results. Also I have already seen instance where a someone runs the script and uses the search for mac function and it does not return a mac. One reason this happens, is because the mac you are searching for is not on the switch you are walking or not part of any vlan.So by passing a port, the script  will scan every vlan on the switch for MAC Addresses connected to that port.This script uses the dot1d tables to get the MAC info as per the CISCO website.

Update 1.1

  • Fixed Port Matching…
  • Now for the -n option you can pass the port number ’1/1′ or the Port Name as per ifName “Gi1/1″
    1. Pysnmp
    2. Pyasn1
    3. SNMP Access to the switch you want to talk too and its community string.
  • Three things you will need for this script to work..

    1. install python-setuptools
    2. then run easy_install pysnmp
    3. and easy_install pyasn1
  • To make your life easier you should do the following

    I am using the following revisions from the python cheese shop pysnmp 4.1.7a  and pyasn1 0.0.6a

    You can download the script here
    port_report.py

    {quickdown:39}
    Please post anything related to this script on this forum link http://www.linuxdynasty.org/forums/Scripting/scripting/port_report
    Unless it is just a comment, thank you…

    Also if you download this script on other Platforms besides Cisco, please let me know if it works, so I can added under platforms supported.

    Continue reading “HowTo find the port on a switch that a host belongs to, the easy way, part 2” »

Apr 072009
 

 

The Port Report Project is essentially a Switch Port Mapper Tool or a Switch Port Mapping Tool like a few other commercial products out there, except The Port Report Project is free. Right now there is no GUI or WEB interface for the project but it is in the works.

The other day I was speaking to a buddy of mine. I asked him how cool would it be, if you could just get the port on a switch that you are plugged into, in one line?? So since I thought about it… I figured why not…. I just finished writing the first revision ( I’m assuming more to come). I must say that I am quite pleased with it. Right now you can pass the switch you want to talk too, the community string, and either the MAC or IP address of the host device. In return you will get the MAC Address, IP Address, Port Description (VLAN), and Port you are plugged into.

This script requires, Pysnmp and Pyasn1. If you have python-setuptools, you can install it by running this..
easy_install pysnmp, easy_install pyasn1

 

Three things you will need for this script to work..

  1. Pysnmp
  2. Pyasn1
  3. SNMP Access to the switch you want to talk too and its community string.
To make your life easier you should do the following
  1. install python-setuptools
  2. then run easy_install pysnmp
  3. and easy_install pyasn1
  4. or you can download the 2 modules manually.
    pysnmp and pyasn1
  5. then unzip the 2 files and in each directory run python setup.py install

I am using the following revisions from the python cheese shop pysnmp 4.1.7a  and pyasn1 0.0.6a

 

Revision 2, will even add more features like…

  • Trying to find out what is plugged into a certain Port.
  • Passing a list of switches
  • follow chained switches
  • Gettinginfo from non vlan ports.
  • If you have more ideas, please let me know..

Update 1.7….This is a big update for Port Report…. In this revision the following brands and devices are supported

  1. Cisco
    • Catalyst 6509 w/ Supervisor 720 running IOS
    • Catalyst 3560
    • Catalyst 3550 (SMI)
    • Cisco CIGESM series Chassis Blades
    • Cisco Catalyst 2960
  2. Foundry
    • Foundry Server Iron
  3. Nortel
    • Nortel Passport 8600
    • Nortel 5520 Ethernet Routing Switch
  4. HP
    • HP Procurve 5406xl

The Script has been tested with the above devices… If you have run this script against other devices, please let us know. Also the speed in the report function has drastically increased. I ran this script against a 6509 with 800+ devices connected to it in just over 2 minutes.

You can download the script here {quickdown:44}

Update..  revision 1.6 has been released.

  • Support for HP PROCURVE switches
  • Added Verbose option
  • Combined switch_report.py in port_report.py

Update, version 1.4…
Only changes that have been made are below..

  • Code Clean up
  • added check by port name
  • Added Error Checking
  • fixed a few bugs with matching the ifIndex port to the bridgeport

So from the looks of it this script does work on Cisco Switches,which has been tested. But does not work on HP Procurve switches. I would like to add this feature to this script but I do not have HP switches to test on.  If anyone would like me to add this feature to HP switches oranyother manufacturer please let me know and maybe we can work together to get it working.

     example below...    python get_port.py -d "switch" -c "community" -m "mac address"

    MAC Address = 00 14 28 1f 2d 38    IP Address = 192.168.101.100    PortDescr = Vlan175    Port = GigabitEthernet1/17

    python get_port.py -d "switch" -c "community" -i "ip address"

    MAC Address = 00 14 28 1f 2d 38    IP Address = 192.168.101.100    PortDescr = Vlan175    Port = GigabitEthernet1/17

Please post any questions related to this script here.. http://www.linuxdynasty.org/forums/Scripting/scripting/port_report
You can download the script here… get_port.py

python port_report.py -d 192.168.101.1 -c public --report GigabitEthernet1/11,00 21 5a 80 0b a6,192.168.101.23,vlan51,up,up,fullDuplex,1gbps,GigabitEthernet1/12,00 12 79 83 3b f3,192.168.101.24,vlan51,up,up,fullDuplex,1gbps,

python port_report.py -d 192.168.101.1 -c public -i "192.168.101.201"This IPAddress is not in the ARP table

python port_report.py -d 192.168.101.1 -c public -i "192.168.101.202"--verboseFri Apr 24 15:15:41 2009  Main StartedFri Apr 24 15:15:41 2009  In snmpget function Fri Apr 24 15:15:42 2009  Out of snmpget function Cisco Internetwork Operating System Software IOS (tm) s72033_rp Software (s72033_rp-JK9S-M), Version 12.2(17d)SXB7, RELEASE SOFTWARE (fc2)Technical Support: http://www.cisco.com/techsupportCopyright (c) 1986-2005 by cisco Systems, Inc.Compiled ThuFri Apr 24 15:15:42 2009  Finished Checking for macFri Apr 24 15:15:42 2009  Found IPFri Apr 24 15:15:42 2009  192.168.101.202 is a Cisco Switch Fri Apr 24 15:15:42 2009  In generic_mac_or_ip Function00 14 38 4f 5e 38 Fri Apr 24 15:15:42 2009  Looping Through CommTableFri Apr 24 15:15:42 2009  In CommTable For LoopFri Apr 24 15:15:42 2009  First If Statement Fri Apr 24 15:15:42 2009  Looping Through CommTableFri Apr 24 15:15:42 2009  In CommTable For LoopFri Apr 24 15:15:42 2009  Looping Through CommTableFri Apr 24 15:15:42 2009  In CommTable For Loop

python port_report.py -d 192.168.101.1 -c public -i "192.168.101.209"MAC  = 00 14 38 7f 6e 38Port = GigabitEthernet1/17Vlan = 175IPAddr = 192.168.101.209

python port_report.py -d 192.168.101.1 -c public -m "00 14 38 4f 5e 39"MAC  = 00 14 38 4f 5e 39Port = GigabitEthernet1/17Vlan = 175IPAddr = 192.168.101.201

python port_report.py -d 192.168.101.1 -c public -n "1/40"Port 1/40 has the below MAC Addresses associated with itMAC  = 00 1b 95 97 3c 81Port = GigabitEthernet1/40Vlan = 1IPAddr = The IP Address for this MAC is not in the ARP Table

MAC  = 00 15 fa b4 10 06Port = GigabitEthernet1/40Vlan = 174IPAddr = The IP Address for this MAC is not in the ARP Table

Total MAC Addresses associated with this interface 2

python port_report.py -d 192.168.101.1 -c public -n "1/2"Port 1/2 has the below MAC Addresses associated with itMAC  = 08 00 0f 20 b3 aaPort = GigabitEthernet1/2Vlan = 176IPAddr = 192.168.101.104

MAC  = 08 00 0f 21 d3 78Port = GigabitEthernet1/2Vlan = 173IPAddr = 192.168.101.105

MAC  = 08 00 0f 20 b3 aaPort = GigabitEthernet1/2Vlan = 175IPAddr = 192.168.101.115
Apr 042009
 

Today a friend of mine wanted to know how he can check the status and or speed of multiple Network Interfaces/Ports on a device ( Switch, Router, Server, etcc ) using SNMP. Specifically he wanted to know if the Interfaces/Ports are Operationally Up or Down and also if it is Administratively. Then he also wanted to know the speed of the Interfaces/Ports that were Up or Down.

Now you can easily get this information through SNMP or if you have a monitoring tool like Zenoss. But he wanted a command line script that would run fairly quickly and either print the results to STDOUT or that he can pipe the ouput in an email.

So I decided, ok I’ll wite you a quick script in Python that will get you that information. FYI, I’m thinking of making this script compatible with the Nagios API. If you want this feature please let me know… Below I will give you some examples of the script…. 

    python check_int_speed.py --device zenoss --community "public" --astatus "Up" --ostatus "Up"
lo is Administratively Up and Operationally Up and running at 10mbs
eth0 is Administratively Up and Operationally Up and running at 1gbps

Continue reading “HowTo check the status of one or multiple network interfaces the easy way” »

Mar 222009
 

Apache, among many other httpds, can be configured to log to an executable’s STDIN instead of a file. But older Apaches, again like other httpds, won’t let you pipe that programme’s output to another’s input, so you’re limited to whatever the one was made to do.*

httpd error logs often contain error conditions one wants to be alerted about, but for most people that means either monitoring it with some variant of tailf running on the host, or sshing to the host to run tail (or tail -f) on the log, piped to egrep, etcetera. This kind of set-up can work fine for one or two web servers, but gets cumbersome when you have more than just a few, and can become impracticable when dealing with many or when the error logs are being written to frequently.

Well, I sometimes have to deal with six hundred or more. Screw ssh 'tailf | egrep' ...

Continue reading “Apache Logs: Multiple Pipeline” »

Feb 272009
 

Recently I had to input quite a few OID’s into Zenoss. This meant I had to create a Data Source for each OID I wanted to monitor as well as one Data Point.
Now I knew this was going to be a hassle!!! So I decided to write a custom Python script that uses pysnmp to essentially do a snmpwalk (nextCmd)
on a Branch of OID’s. This means that I can create one Data Source and Mutiple Data Points.
Which drops the amount of time that I have to input into the Zenoss GUI.

Please Post any questions about this script here http://www.linuxdynasty.org/forums/Scripting/scripting/snmp_branch_help
You can download the script snmp_branch.py

  • Update 1.0.10
    1. Fixed labeling bug, (Thanks Stephan26 for finding this)
    2. Added –fsearch option
      Thanks Stephan26 for suggesting to add a way to find OID’s by their begining Digits on their last Octect
    3. Added –length option
      This will allow you to search for an Index on the final Octect of the OID, when the final octect is not just the index.
      Example…. You want the index OID of 100 but the entire last octect of the OID is .6534389100)

 

So here is an example below of what the data looks like from SNMP..

UCD-SNMP-MIB::ssIndex.0 = INTEGER: 1UCD-SNMP-MIB::ssSwapIn.0 = INTEGER: 0UCD-SNMP-MIB::ssSwapOut.0 = INTEGER: 0UCD-SNMP-MIB::ssIOSent.0 = INTEGER: 0UCD-SNMP-MIB::ssIOReceive.0 = INTEGER: 1UCD-SNMP-MIB::ssSysInterrupts.0 = INTEGER: 3|UCD-SNMP-MIB::ssSysContext.0 = INTEGER: 19UCD-SNMP-MIB::ssCpuUser.0 = INTEGER: 7UCD-SNMP-MIB::ssCpuSystem.0 = INTEGER: 7UCD-SNMP-MIB::ssCpuIdle.0 = INTEGER: 84

 

Continue reading “HowTo monitor and add multiple Data Points the easy way in Zenoss” »


Warning: fopen(/home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/lib/standard.txt) [function.fopen]: failed to open stream: No such file or directory in /home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/plusone.php on line 104

Warning: fread(): supplied argument is not a valid stream resource in /home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/plusone.php on line 105

Warning: fclose(): supplied argument is not a valid stream resource in /home/dynasty/linuxdynasty.org/wp-content/plugins/wp-google-plus-one/plusone.php on line 106
.