python interface-checker

I’d like helpdesk to be able to enable and disable switchports without requiring them to know the underlying OS. My plan is to have a webpage with a list of devices. When you click on a device it will check the interfaces status via SNMP and display administrative and operational status of all interfaces on the device. Then via a few click it’ll use NETCONF to enable or disable a port.

As a first step I’ve created a quick python script to SNMP into a device and get it’s output. For the moment this just outputs to the CLI in a table. Long term the front end will use this to get the interface status when a device is clicked.

The next step is to get NETCONF working.

I’ve tested this script on Juniper, Cisco, and Brocade and all data is retrieved correctly.

Here is an example from a Juniper MX80:

Darren-MBP:interface-checker darren$ ./ic.py router-name
+-------------------------+-----------------+--------------+--------------------+
|        OID Value        |  Interface Name | Admin Status | Operational Status |
+-------------------------+-----------------+--------------+--------------------+
|  1.3.6.1.2.1.2.2.1.2.1  |       fxp0      |     DOWN     |        DOWN        |
|  1.3.6.1.2.1.2.2.1.2.4  |       lsi       |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.5  |       dsc       |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.6  |       lo0       |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.7  |       tap       |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.8  |       gre       |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.9  |       ipip      |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.10 |       pime      |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.11 |       pimd      |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.12 |       mtun      |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.16 |      lo0.0      |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.17 |       em0       |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.18 |      em0.0      |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.21 |    lo0.16384    |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.22 |    lo0.16385    |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.23 |       em1       |      UP      |        DOWN        |
|  1.3.6.1.2.1.2.2.1.2.33 |       me0       |      UP      |         UP         |
|  1.3.6.1.2.1.2.2.1.2.34 |      me0.0      |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.501 |      demux0     |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.502 |     lc-0/0/0    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.503 |  lc-0/0/0.32769 |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.504 |       cbp0      |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.505 |       pip0      |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.506 |       pp0       |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.507 |       irb       |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.508 |     xe-0/0/0    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.509 |     xe-0/0/1    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.510 |     xe-0/0/2    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.511 |     xe-0/0/3    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.512 |     ge-1/0/0    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.513 |     ge-1/0/1    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.514 |     ge-1/0/2    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.515 |     ge-1/0/3    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.516 |     ge-1/0/4    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.517 |     ge-1/0/5    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.518 |     ge-1/0/6    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.519 |     ge-1/0/7    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.520 |     ge-1/0/8    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.521 |     ge-1/0/9    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.522 |     ge-1/1/0    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.523 |     ge-1/1/1    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.524 |     ge-1/1/2    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.525 |     ge-1/1/3    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.526 |     ge-1/1/4    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.527 |     ge-1/1/5    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.528 |     ge-1/1/6    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.529 |     ge-1/1/7    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.530 |     ge-1/1/8    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.531 |     ge-1/1/9    |     DOWN     |        DOWN        |
| 1.3.6.1.2.1.2.2.1.2.532 |    pfh-0/0/0    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.533 |    pfe-0/0/0    |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.534 | pfh-0/0/0.16383 |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.535 | pfe-0/0/0.16383 |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.547 |    ge-1/1/0.0   |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.552 |    ge-1/1/1.0   |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.553 |    ge-1/1/2.0   |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.554 |    ge-1/1/3.0   |      UP      |         UP         |
| 1.3.6.1.2.1.2.2.1.2.555 |    ge-1/1/4.0   |      UP      |         UP         |
+-------------------------+-----------------+--------------+--------------------+

You can find it here: https://github.com/mellowdrifter/interface-checker

© 2009-2020 Darren O'Connor All Rights Reserved -- Copyright notice by Blog Copyright