Creating a pull request for snmp_facts module and suggestions

I’ve created an Ansible module which can gather Ansible facts from SNMP enabled devices. I’ve written about the module here:
http://networklore.com/ansible-snmp-facts/

It was suggested on Twitter that I created a pull request to move the module to the extras repo.

My repo is located here:
https://github.com/networklore/ansible-snmp-facts

I’m quite new with Git and I’m not really sure what to do. Can I send a pull request only for the file snmp_facts.py, or how does it work?

Currently the module is quite basic but could be expanded all kinds of other information.

What I’ve been thinking about is how to best structure the data which is returned to Ansible. Currently the return values look like this:

“ansible_facts”: {
“ansible_interfaces”: {
“1”: {
“ifindex”: “1”,
“name”: “Vlan1”
},
“10004”: {
“ifindex”: “10004”,
“name”: “FastEthernet0/4”
},
},

The numbers directly under the ansible_interfaces is the SNMP ifIndex number. I don’t know if that is ideal, but I think it’s better to use those numbers compared to a name like “FastEthernet0/4”. Does anyone have an input on this?

Another question is if we want to look at CDP information to see how Cisco equipment is connected to each other.

These are the interfaces on one on my switches:

[patrick@srv-script-1 ~]# snmpwalk -v2c -c cisco 172.29.50.3 ifDescr
IF-MIB::ifDescr.1 = STRING: Vlan1
IF-MIB::ifDescr.20 = STRING: Vlan20
IF-MIB::ifDescr.40 = STRING: Vlan40
IF-MIB::ifDescr.41 = STRING: Vlan41
IF-MIB::ifDescr.5001 = STRING: Port-channel1
IF-MIB::ifDescr.10101 = STRING: GigabitEthernet0/1
IF-MIB::ifDescr.10102 = STRING: GigabitEthernet0/2
IF-MIB::ifDescr.10103 = STRING: GigabitEthernet0/3
IF-MIB::ifDescr.10104 = STRING: GigabitEthernet0/4
IF-MIB::ifDescr.10105 = STRING: GigabitEthernet0/5
IF-MIB::ifDescr.10106 = STRING: GigabitEthernet0/6
IF-MIB::ifDescr.10107 = STRING: GigabitEthernet0/7
IF-MIB::ifDescr.10108 = STRING: GigabitEthernet0/8
IF-MIB::ifDescr.10501 = STRING: Null0

This is part of the SNMP table for CDP.

CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10101.5 = STRING: “Switch1”
CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10106.1 = STRING: “Router2”
CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10106.2 = STRING: “Router1”
CISCO-SMI::ciscoMgmt.23.1.2.1.1.6.10106.3 = STRING: “Router3”
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10101.5 = STRING: “GigabitEthernet0/1”
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10106.1 = STRING: “GigabitEthernet0/2”
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10106.2 = STRING: “GigabitEthernet0/3”
CISCO-SMI::ciscoMgmt.23.1.2.1.1.7.10106.3 = STRING: “GigabitEthernet0/2”

We can see that we have one device called Switch is connected to the 10101 interface (GigabitEthernet0/1) and three devices called router1, router2 and router3 which are connected through the interface 10106 (GigabitEthernet0/6). So on one interface there is a one to one relationship, but on the other local interface there is a one to three relation.

It wouldn’t be a problem to store this in a database with two tables, but I’m unsure of the best structure with Ansible facts. Perhaps the best way is to solve it like the IPv6 addresses in Ansible now, I’m unsure about the terminology, but “unnamed keys” or something:

“ansible_eth1”: {
“active”: true,
“device”: “eth1”,
“ipv4”: {
“address”: “10.10.20.1”,
“netmask”: “255.255.255.0”,
“network”: “10.10.20.0”
},
“ipv6”: [
{
“address”: “2201::1”,
“prefix”: “64”,
“scope”: “global”
},
{
“address”: “2001::1”,
“prefix”: “64”,
“scope”: “global”
},
{
“address”: “fe80::20c:29ff:fe25:c94c”,
“prefix”: “64”,
“scope”: “link”
}
],

If someone have any suggestions about this I’m all ears.

Hi Patrick,

I think I replied to a recent SNMP post earlier, so this may be a stray email in drafts.

Let me know if this is not a dup and there are specific new things you’d like input on.

–Michael