librenms-librenms/discover-vlans.php

30 lines
957 B
PHP
Raw Normal View History

#!/usr/bin/php
<?
include("config.php");
include("includes/functions.php");
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os = 'IOS'");
while ($device = mysql_fetch_array($device_query)) {
echo("Discovering VLANs on " . $device['hostname'] . "\n");
$vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ";
$vlans_cmd .= "1.3.6.1.4.1.9.9.46.1.3.1.1.2.1 | sed s/.1.3.6.1.4.1.9.9.46.1.3.1.1.2.1.//g | cut -f 1 -d\" \"";
$vlans = trim(`$vlans_cmd | grep -v o`);
foreach(explode("\n", $vlans) as $vlan) {
$vlan_descr_cmd = "snmpget -O nvq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ";
$vlan_descr_cmd .= ".1.3.6.1.4.1.9.9.46.1.3.1.1.4.1." . $vlan;
$vlan_descr = `$vlan_descr_cmd`;
$vlan_descr = trim(str_replace("\"", "", $vlan_descr));
echo("VLAN $vlan ($vlan_descr)\n");
}
}