Open vdalakas opened 6 years ago
Hey @vdalakas, thanks for the PR! Great stuff in here and I appreciate the conribution. I've been super busy at work and haven't had a chance to look at the code closely or test your changes. I'll report back soon. Thanks
First of all, THANK YOU for your efforts!
Trying to use your script to my auto discover network has produced only a basic host file with missing vendor and sometimes it could not complete the scan.
Hence, I have modified your code in order to include fast scans for OS, net interfaces and open ports. The ports scan is commented out since it is too slow for a network with more than 50 VLANs like mine. The output file now has the following format and hence one could use check_snmp_int.pl plugin as described by MarcusCaepio here:
https://monitoring-portal.org/woltlab/index.php?thread/35432-snmp-how-to-monitor-all-ports-on-a-switch-router/
The ideal would be to use snmp only once however there are some differences of snmpwalk (it only works for one OID) from snmpget (unfortunately it returns unknown OID for the int OID). Due to this reason I have included two snmp related scans. Another option would be to merge nmap scans with -Pn option to check every device of a C class network but this would slow up the whole auto discover procedure.
Current code creates a conf file in less than 1 hour for my entire infrastructure! In combination with the templates.conf and groups.conf one could have a working Icinga2 environment in less than 5 minutes for a C class subnet.
============== SAMPLE OUTPUT FILE ==================== object Host "hostname.example.com" { address = "xxx.xxx.xxx.xxx" import "generic-host" vars.os = "Cisco IOS 12.X|15.X, Cisco embedded" import "network-host" vars.type = "switch|router|firewall" vars.os_details = "Cisco 2950, 2960, 3550, 3560, 3750, or 4500 switch or 6500 router (IOS 12.1 - 15.0); or Adaptive Security Appliance firewall" vars.description = "Cisco Systems, Inc. WS-C4506-E 6 slot switch " vars.ports = "Unknown" vars.location = "LOCATION" vars.vendor = "ciscoSystems" " notes = "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSAL-M), Version 03.04.04.SG RELEASE SOFTWARE (fc2) vars.int["FastEthernet1"] = { int = "FastEthernet1" } vars.int["TenGigabitEthernet1/1"] = { int = "TenGigabitEthernet1/1" } vars.int["TenGigabitEthernet1/2"] = { int = "TenGigabitEthernet1/2" } vars.int["GigabitEthernet1/3"] = { int = "GigabitEthernet1/3" } vars.int["GigabitEthernet1/4"] = { int = "GigabitEthernet1/4" } vars.int["GigabitEthernet1/5"] = { int = "GigabitEthernet1/5" } vars.int["GigabitEthernet1/6"] = { int = "GigabitEthernet1/6" } vars.int["GigabitEthernet2/1"] = { int = "GigabitEthernet2/1" } vars.int["GigabitEthernet2/2"] = { int = "GigabitEthernet2/2" } vars.int["GigabitEthernet2/3"] = { int = "GigabitEthernet2/3" } vars.int["GigabitEthernet2/4"] = { int = "GigabitEthernet2/4" } vars.int["GigabitEthernet2/5"] = { int = "GigabitEthernet2/5" } vars.int["GigabitEthernet2/6"] = { int = "GigabitEthernet2/6" } vars.int["GigabitEthernet2/7"] = { int = "GigabitEthernet2/7" } vars.int["GigabitEthernet2/8"] = { int = "GigabitEthernet2/8" } vars.int["GigabitEthernet2/9"] = { int = "GigabitEthernet2/9" } vars.int["GigabitEthernet2/10"] = { int = "GigabitEthernet2/10" } vars.int["GigabitEthernet2/11"] = { int = "GigabitEthernet2/11" } vars.int["GigabitEthernet2/12"] = { int = "GigabitEthernet2/12" } vars.int["GigabitEthernet4/1"] = { int = "GigabitEthernet4/1" } vars.int["GigabitEthernet4/2"] = { int = "GigabitEthernet4/2" } vars.int["GigabitEthernet4/3"] = { int = "GigabitEthernet4/3" } vars.int["GigabitEthernet4/4"] = { int = "GigabitEthernet4/4" } vars.int["GigabitEthernet4/5"] = { int = "GigabitEthernet4/5" } vars.int["GigabitEthernet4/6"] = { int = "GigabitEthernet4/6" } vars.int["GigabitEthernet4/7"] = { int = "GigabitEthernet4/7" } vars.int["GigabitEthernet4/8"] = { int = "GigabitEthernet4/8" } vars.int["GigabitEthernet4/9"] = { int = "GigabitEthernet4/9" } vars.int["GigabitEthernet4/10"] = { int = "GigabitEthernet4/10" } vars.int["GigabitEthernet4/11"] = { int = "GigabitEthernet4/11" } vars.int["GigabitEthernet4/12"] = { int = "GigabitEthernet4/12" } vars.int["GigabitEthernet4/13"] = { int = "GigabitEthernet4/13" } vars.int["GigabitEthernet4/14"] = { int = "GigabitEthernet4/14" } vars.int["GigabitEthernet4/15"] = { int = "GigabitEthernet4/15" } vars.int["GigabitEthernet4/16"] = { int = "GigabitEthernet4/16" } vars.int["GigabitEthernet4/17"] = { int = "GigabitEthernet4/17" } vars.int["GigabitEthernet4/18"] = { int = "GigabitEthernet4/18" } vars.int["GigabitEthernet4/19"] = { int = "GigabitEthernet4/19" } vars.int["GigabitEthernet4/20"] = { int = "GigabitEthernet4/20" } vars.int["GigabitEthernet4/21"] = { int = "GigabitEthernet4/21" } vars.int["GigabitEthernet4/22"] = { int = "GigabitEthernet4/22" } vars.int["GigabitEthernet4/23"] = { int = "GigabitEthernet4/23" } vars.int["GigabitEthernet4/24"] = { int = "GigabitEthernet4/24" } vars.int["GigabitEthernet4/25"] = { int = "GigabitEthernet4/25" } vars.int["GigabitEthernet4/26"] = { int = "GigabitEthernet4/26" } vars.int["GigabitEthernet4/27"] = { int = "GigabitEthernet4/27" } vars.int["GigabitEthernet4/28"] = { int = "GigabitEthernet4/28" } vars.int["GigabitEthernet4/29"] = { int = "GigabitEthernet4/29" } vars.int["GigabitEthernet4/30"] = { int = "GigabitEthernet4/30" } vars.int["GigabitEthernet4/31"] = { int = "GigabitEthernet4/31" } vars.int["GigabitEthernet4/32"] = { int = "GigabitEthernet4/32" } vars.int["GigabitEthernet4/33"] = { int = "GigabitEthernet4/33" } vars.int["GigabitEthernet4/34"] = { int = "GigabitEthernet4/34" } vars.int["GigabitEthernet4/35"] = { int = "GigabitEthernet4/35" } vars.int["GigabitEthernet4/36"] = { int = "GigabitEthernet4/36" } vars.int["GigabitEthernet4/37"] = { int = "GigabitEthernet4/37" } vars.int["GigabitEthernet4/38"] = { int = "GigabitEthernet4/38" } vars.int["GigabitEthernet4/39"] = { int = "GigabitEthernet4/39" } vars.int["GigabitEthernet4/40"] = { int = "GigabitEthernet4/40" } vars.int["GigabitEthernet4/41"] = { int = "GigabitEthernet4/41" } vars.int["GigabitEthernet4/42"] = { int = "GigabitEthernet4/42" } vars.int["GigabitEthernet4/43"] = { int = "GigabitEthernet4/43" } vars.int["GigabitEthernet4/44"] = { int = "GigabitEthernet4/44" } vars.int["GigabitEthernet4/45"] = { int = "GigabitEthernet4/45" } vars.int["GigabitEthernet4/46"] = { int = "GigabitEthernet4/46" } vars.int["GigabitEthernet4/47"] = { int = "GigabitEthernet4/47" } vars.int["GigabitEthernet4/48"] = { int = "GigabitEthernet4/48" } vars.int["GigabitEthernet6/1"] = { int = "GigabitEthernet6/1" } vars.int["GigabitEthernet6/2"] = { int = "GigabitEthernet6/2" } vars.int["GigabitEthernet6/3"] = { int = "GigabitEthernet6/3" } vars.int["GigabitEthernet6/4"] = { int = "GigabitEthernet6/4" } vars.int["GigabitEthernet6/5"] = { int = "GigabitEthernet6/5" } vars.int["GigabitEthernet6/6"] = { int = "GigabitEthernet6/6" } vars.int["GigabitEthernet6/7"] = { int = "GigabitEthernet6/7" } vars.int["GigabitEthernet6/8"] = { int = "GigabitEthernet6/8" } vars.int["GigabitEthernet6/9"] = { int = "GigabitEthernet6/9" } vars.int["GigabitEthernet6/10"] = { int = "GigabitEthernet6/10" } vars.int["GigabitEthernet6/11"] = { int = "GigabitEthernet6/11" } vars.int["GigabitEthernet6/12"] = { int = "GigabitEthernet6/12" } vars.int["GigabitEthernet6/13"] = { int = "GigabitEthernet6/13" } vars.int["GigabitEthernet6/14"] = { int = "GigabitEthernet6/14" } vars.int["GigabitEthernet6/15"] = { int = "GigabitEthernet6/15" } vars.int["GigabitEthernet6/16"] = { int = "GigabitEthernet6/16" } vars.int["GigabitEthernet6/17"] = { int = "GigabitEthernet6/17" } vars.int["GigabitEthernet6/18"] = { int = "GigabitEthernet6/18" } vars.int["GigabitEthernet6/19"] = { int = "GigabitEthernet6/19" } vars.int["GigabitEthernet6/20"] = { int = "GigabitEthernet6/20" } vars.int["GigabitEthernet6/21"] = { int = "GigabitEthernet6/21" } vars.int["GigabitEthernet6/22"] = { int = "GigabitEthernet6/22" } vars.int["GigabitEthernet6/23"] = { int = "GigabitEthernet6/23" } vars.int["GigabitEthernet6/24"] = { int = "GigabitEthernet6/24" } vars.int["GigabitEthernet6/25"] = { int = "GigabitEthernet6/25" } vars.int["GigabitEthernet6/26"] = { int = "GigabitEthernet6/26" } vars.int["GigabitEthernet6/27"] = { int = "GigabitEthernet6/27" } vars.int["GigabitEthernet6/28"] = { int = "GigabitEthernet6/28" } vars.int["GigabitEthernet6/29"] = { int = "GigabitEthernet6/29" } vars.int["GigabitEthernet6/30"] = { int = "GigabitEthernet6/30" } vars.int["GigabitEthernet6/31"] = { int = "GigabitEthernet6/31" } vars.int["GigabitEthernet6/32"] = { int = "GigabitEthernet6/32" } vars.int["GigabitEthernet6/33"] = { int = "GigabitEthernet6/33" } vars.int["GigabitEthernet6/34"] = { int = "GigabitEthernet6/34" } vars.int["GigabitEthernet6/35"] = { int = "GigabitEthernet6/35" } vars.int["GigabitEthernet6/36"] = { int = "GigabitEthernet6/36" } vars.int["GigabitEthernet6/37"] = { int = "GigabitEthernet6/37" } vars.int["GigabitEthernet6/38"] = { int = "GigabitEthernet6/38" } vars.int["GigabitEthernet6/39"] = { int = "GigabitEthernet6/39" } vars.int["GigabitEthernet6/40"] = { int = "GigabitEthernet6/40" } vars.int["GigabitEthernet6/41"] = { int = "GigabitEthernet6/41" } vars.int["GigabitEthernet6/42"] = { int = "GigabitEthernet6/42" } vars.int["GigabitEthernet6/43"] = { int = "GigabitEthernet6/43" } vars.int["GigabitEthernet6/44"] = { int = "GigabitEthernet6/44" } vars.int["GigabitEthernet6/45"] = { int = "GigabitEthernet6/45" } vars.int["GigabitEthernet6/46"] = { int = "GigabitEthernet6/46" } vars.int["GigabitEthernet6/47"] = { int = "GigabitEthernet6/47" } vars.int["GigabitEthernet6/48"] = { int = "GigabitEthernet6/48" } vars.int["Null0"] = { int = "Null0" } vars.int["Vlan1"] = { int = "Vlan1" } vars.int["Port-channel1"] = { int = "Port-channel1" } vars.int["Port-channel2"] = { int = "Port-channel2" } vars.int["Port-channel8"] = { int = "Port-channel8" } vars.int["Port-channel10"] = { int = "Port-channel10" } vars.int["Port-channel11"] = { int = "Port-channel11" } vars.int["Port-channel12"] = { int = "Port-channel12" } vars.int["Vlan2"] = { int = "Vlan2" } vars.int["Vlan3"] = { int = "Vlan3" } vars.int["Vlan4"] = { int = "Vlan4" } vars.int["Vlan5"] = { int = "Vlan5" } vars.int["Vlan6"] = { int = "Vlan6" } vars.int["Vlan7"] = { int = "Vlan7" } vars.int["Vlan8"] = { int = "Vlan8" } vars.int["Vlan9"] = { int = "Vlan9" } vars.int["Vlan10"] = { int = "Vlan10" } vars.int["Vlan11"] = { int = "Vlan11" } vars.int["Vlan12"] = { int = "Vlan12" } vars.int["Vlan13"] = { int = "Vlan13" } vars.int["Vlan14"] = { int = "Vlan14" } vars.int["Vlan15"] = { int = "Vlan15" } vars.int["Vlan16"] = { int = "Vlan16" } vars.int["Vlan17"] = { int = "Vlan17" } vars.int["Vlan18"] = { int = "Vlan18" } vars.int["Vlan19"] = { int = "Vlan19" } vars.int["Vlan20"] = { int = "Vlan20" } vars.int["Vlan22"] = { int = "Vlan22" } vars.int["Vlan26"] = { int = "Vlan26" } vars.int["Vlan27"] = { int = "Vlan27" } vars.int["Vlan28"] = { int = "Vlan28" } vars.int["Vlan29"] = { int = "Vlan29" } vars.int["Vlan37"] = { int = "Vlan37" } vars.int["Vlan38"] = { int = "Vlan38" } vars.int["Vlan39"] = { int = "Vlan39" } vars.int["Vlan40"] = { int = "Vlan40" } vars.int["Vlan49"] = { int = "Vlan49" } vars.int["Vlan50"] = { int = "Vlan50" } vars.int["Vlan51"] = { int = "Vlan51" } vars.int["Vlan52"] = { int = "Vlan52" } vars.int["Vlan53"] = { int = "Vlan53" } vars.int["Vlan54"] = { int = "Vlan54" } vars.int["Vlan55"] = { int = "Vlan55" } vars.int["Vlan56"] = { int = "Vlan56" } vars.int["Vlan57"] = { int = "Vlan57" } vars.int["Vlan60"] = { int = "Vlan60" } vars.int["Vlan61"] = { int = "Vlan61" } vars.int["Vlan62"] = { int = "Vlan62" } vars.int["Vlan63"] = { int = "Vlan63" } vars.int["Vlan64"] = { int = "Vlan64" } vars.int["Vlan65"] = { int = "Vlan65" } vars.int["Vlan66"] = { int = "Vlan66" } vars.int["Vlan67"] = { int = "Vlan67" } vars.int["Vlan68"] = { int = "Vlan68" } vars.int["Vlan70"] = { int = "Vlan70" } vars.int["Vlan102"] = { int = "Vlan102" } vars.int["Vlan103"] = { int = "Vlan103" } vars.int["Vlan104"] = { int = "Vlan104" } vars.int["Vlan107"] = { int = "Vlan107" } vars.int["Vlan108"] = { int = "Vlan108" } vars.int["Vlan110"] = { int = "Vlan110" } vars.int["Vlan111"] = { int = "Vlan111" } vars.int["Vlan112"] = { int = "Vlan112" } vars.int["Vlan113"] = { int = "Vlan113" } vars.int["Vlan114"] = { int = "Vlan114" } vars.int["Vlan118"] = { int = "Vlan118" } vars.int["Vlan119"] = { int = "Vlan119" } vars.int["Vlan120"] = { int = "Vlan120" } vars.int["Vlan125"] = { int = "Vlan125" } }