mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
Lots of bugfixes, some new features - VLANS
git-svn-id: http://www.observium.org/svn/observer/trunk@95 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
+1
-2
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
./cdp.php
|
./cdp.php
|
||||||
./poll-reachability.php
|
|
||||||
./poll-os.php
|
|
||||||
./discover-ifs.php
|
./discover-ifs.php
|
||||||
./discover-nets.php
|
./discover-nets.php
|
||||||
./ips.php
|
./ips.php
|
||||||
@@ -10,3 +8,4 @@
|
|||||||
./discover-temperatures.php
|
./discover-temperatures.php
|
||||||
./generate-map.sh
|
./generate-map.sh
|
||||||
./discover-cisco-temp.php
|
./discover-cisco-temp.php
|
||||||
|
./update-interface.php
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
include("config.php");
|
include("config.php");
|
||||||
include("includes/functions.php");
|
include("includes/functions.php");
|
||||||
include("includes/cdp.php");
|
include("includes/cdp.inc.php");
|
||||||
|
|
||||||
$device_query = mysql_query("SELECT * FROM `devices` WHERE `status` = '1' AND `os` = 'IOS' ORDER BY `device_id` DESC");
|
$device_query = mysql_query("SELECT * FROM `devices` WHERE `status` = '1' AND `os` = 'IOS' ORDER BY `device_id` DESC");
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -14,7 +14,10 @@ while ($device = mysql_fetch_array($device_query)) {
|
|||||||
|
|
||||||
if($vtpversion == '1' || $vtpversion == '2') {
|
if($vtpversion == '1' || $vtpversion == '2') {
|
||||||
|
|
||||||
echo("VLAN Trunking Protocol Version $vtpversion\n");
|
$vtp_domain_cmd = "snmpget -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.2.1.1.2.1";
|
||||||
|
$vtp_domain = trim(str_replace("\"", "", `$vtp_domain_cmd 2>/dev/null`));
|
||||||
|
|
||||||
|
echo("VLAN Trunking Protocol Version $vtpversion Domain : $vtp_domain\n");
|
||||||
|
|
||||||
$vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ";
|
$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_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\" \"";
|
||||||
@@ -29,6 +32,11 @@ while ($device = mysql_fetch_array($device_query)) {
|
|||||||
|
|
||||||
$vlan_descr = trim(str_replace("\"", "", $vlan_descr));
|
$vlan_descr = trim(str_replace("\"", "", $vlan_descr));
|
||||||
|
|
||||||
|
if(mysql_result(mysql_query("SELECT COUNT(vlan_id) FROM `vlans` WHERE `device_id` = '" . $device['device_id'] . "' AND `vlan_domain` = '" . $vtp_domain . "' AND `vlan_vlan` = '" . $vlan . "'"), 0) == '0') {
|
||||||
|
echo "Adding VLAN $vlan - $vlan_descr \n";
|
||||||
|
mysql_query("INSERT INTO `vlans` (`device_id`,`vlan_domain`,`vlan_vlan`, `vlan_descr`) VALUES (" . $device['device_id'] . ",'" . $vtp_domain . "','$vlan', '$vlan_descr')");
|
||||||
|
}
|
||||||
|
|
||||||
echo("VLAN $vlan ($vlan_descr)\n");
|
echo("VLAN $vlan ($vlan_descr)\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,15 @@
|
|||||||
echo("</td><td width=70>");
|
echo("</td><td width=70>");
|
||||||
if($ifSpeed && $ifSpeed != "") { echo("<span class=box-desc>$ifSpeed</span>"); }
|
if($ifSpeed && $ifSpeed != "") { echo("<span class=box-desc>$ifSpeed</span>"); }
|
||||||
echo("<br />");
|
echo("<br />");
|
||||||
if($interface[ifDuplex] != unknown) { echo("<span class=box-desc>Duplex " . $interface['ifDuplex'] . "</span>"); } else { echo("-"); }
|
# if($interface[ifDuplex] != unknown) { echo("<span class=box-desc>Duplex " . $interface['ifDuplex'] . "</span>"); } else { echo("-"); }
|
||||||
|
|
||||||
|
if($device['os'] == "IOS") {
|
||||||
|
|
||||||
|
if($interface['ifTrunk']) { echo("<span class=box-desc><span class=red>" . $interface['ifTrunk'] . "</span></span>");
|
||||||
|
} elseif ($interface['ifVlan']) { echo("<span class=box-desc><span class=blue>VLAN " . $interface['ifVlan'] . "</span></span>"); }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
echo("</td><td width=150>");
|
echo("</td><td width=150>");
|
||||||
if($ifType && $ifType != "") { echo("<span class=box-desc>" . $ifType . "</span>"); } else { echo("-"); }
|
if($ifType && $ifType != "") { echo("<span class=box-desc>" . $ifType . "</span>"); } else { echo("-"); }
|
||||||
echo("<br />");
|
echo("<br />");
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ echo("
|
|||||||
<img src='images/16/server_lightning.png' align=absmiddle border=0> Overview
|
<img src='images/16/server_lightning.png' align=absmiddle border=0> Overview
|
||||||
</a>
|
</a>
|
||||||
</li>");
|
</li>");
|
||||||
|
|
||||||
|
if(@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') {
|
||||||
|
echo("
|
||||||
|
<li class=$select[devvlans]>
|
||||||
|
<a href='?page=device&id=" . $device['device_id'] . "§ion=dev-vlans' >
|
||||||
|
<img src='images/16/rainbow.png' align=absmiddle border=0> VLANs
|
||||||
|
</a>
|
||||||
|
</li>");
|
||||||
|
}
|
||||||
|
|
||||||
if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') {
|
if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') {
|
||||||
echo("
|
echo("
|
||||||
<li class=$select[devifs]>
|
<li class=$select[devifs]>
|
||||||
@@ -38,6 +48,7 @@ if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE d
|
|||||||
</a>
|
</a>
|
||||||
</li>");
|
</li>");
|
||||||
}
|
}
|
||||||
|
|
||||||
echo("<li class=$select[devgraphs]>
|
echo("<li class=$select[devgraphs]>
|
||||||
<a href='?page=device&id=" . $device['device_id'] . "§ion=dev-graphs'>
|
<a href='?page=device&id=" . $device['device_id'] . "§ion=dev-graphs'>
|
||||||
<img src='images/16/server_chart.png' align=absmiddle border=0> Host Graphs
|
<img src='images/16/server_chart.png' align=absmiddle border=0> Host Graphs
|
||||||
|
|||||||
+11
-59
@@ -12,30 +12,26 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
|||||||
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_id = '" . $interface['device_id'] . "'"));
|
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_id = '" . $interface['device_id'] . "'"));
|
||||||
if($device['status'] == '1') {
|
if($device['status'] == '1') {
|
||||||
|
|
||||||
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ifName." . $interface['ifIndex'];
|
unset($update);
|
||||||
$snmp_cmd .= " ifDescr." . $interface['ifIndex'] . " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ";
|
unset($update_query);
|
||||||
$snmp_cmd .= "ifAlias." . $interface['ifIndex'] . " ifSpeed." . $interface['ifIndex'] . " 1.3.6.1.2.1.10.7.2.1." . $interface['ifIndex'];
|
unset($seperator);
|
||||||
$snmp_cmd .= " ifType." . $interface['ifIndex'] . " ifMtu." . $interface['ifIndex'] . " ifPhysAddress." . $interface['ifIndex'];
|
|
||||||
$snmp_cmd .= " 1.3.6.1.4.1.9.2.2.1.1.1." . $interface['ifIndex'];
|
echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n");
|
||||||
|
|
||||||
|
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
|
||||||
|
$snmp_cmd .= " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ifAlias." . $interface['ifIndex'];
|
||||||
|
|
||||||
$snmp_output = trim(`$snmp_cmd`);
|
$snmp_output = trim(`$snmp_cmd`);
|
||||||
$snmp_output = str_replace("No Such Object available on this agent at this OID", "", $snmp_output);
|
$snmp_output = str_replace("No Such Object available on this agent at this OID", "", $snmp_output);
|
||||||
$snmp_output = str_replace("No Such Instance currently exists at this OID", "", $snmp_output);
|
$snmp_output = str_replace("No Such Instance currently exists at this OID", "", $snmp_output);
|
||||||
$snmp_output = str_replace("\"", "", $snmp_output);
|
$snmp_output = str_replace("\"", "", $snmp_output);
|
||||||
|
|
||||||
echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n");
|
list($ifAdminStatus, $ifOperStatus, $ifAlias) = explode("\n", $snmp_output);
|
||||||
|
|
||||||
list($ifName, $ifDescr, $ifAdminStatus, $ifOperStatus, $ifAlias, $ifSpeed, $ifDuplex, $ifType, $ifMtu, $ifPhysAddress, $ifHardType) = explode("\n", $snmp_output);
|
|
||||||
$ifDescr = trim(str_replace("\"", "", $ifDescr));
|
|
||||||
if ($ifDuplex == 3) { $ifDuplex = "half"; } elseif ($ifDuplex == 2) { $ifDuplex = "full"; } else { $ifDuplex = "unknown"; }
|
|
||||||
$ifDescr = strtolower($ifDescr);
|
|
||||||
if ($ifAlias == " ") { $ifAlias = str_replace(" ", "", $ifAlias); }
|
if ($ifAlias == " ") { $ifAlias = str_replace(" ", "", $ifAlias); }
|
||||||
$ifAlias = trim(str_replace("\"", "", $ifAlias));
|
$ifAlias = trim(str_replace("\"", "", $ifAlias));
|
||||||
$ifAlias = trim($ifAlias);
|
$ifAlias = trim($ifAlias);
|
||||||
|
|
||||||
$ifPhysAddress = strtolower(str_replace("\"", "", $ifPhysAddress));
|
|
||||||
$ifPhysAddress = str_replace(" ", ":", $ifPhysAddress);
|
|
||||||
|
|
||||||
$rrdfile = "rrd/" . $device['hostname'] . "." . $interface['ifIndex'] . ".rrd";
|
$rrdfile = "rrd/" . $device['hostname'] . "." . $interface['ifIndex'] . ".rrd";
|
||||||
if(!is_file($rrdfile)) {
|
if(!is_file($rrdfile)) {
|
||||||
$woo = `rrdtool create $rrdfile \
|
$woo = `rrdtool create $rrdfile \
|
||||||
@@ -57,17 +53,8 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
|||||||
RRA:MAX:0.5:288:797`;
|
RRA:MAX:0.5:288:797`;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($update);
|
|
||||||
unset($update_query);
|
|
||||||
unset($seperator);
|
|
||||||
|
|
||||||
if ( $interface['ifDescr'] != $ifDescr && $ifDescr != "" ) {
|
|
||||||
$update = "`if` = '$ifDescr'";
|
|
||||||
$seperator = ", ";
|
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Name -> " . $ifDescr . "')");
|
|
||||||
}
|
|
||||||
if ( $interface['ifAlias'] != $ifAlias ) {
|
if ( $interface['ifAlias'] != $ifAlias ) {
|
||||||
$update .= $seperator . "`name` = '$ifAlias'";
|
$update .= $seperator . "`ifAlias` = '$ifAlias'";
|
||||||
$seperator = ", ";
|
$seperator = ", ";
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')");
|
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')");
|
||||||
}
|
}
|
||||||
@@ -82,41 +69,6 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
|||||||
if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; }
|
if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; }
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')");
|
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')");
|
||||||
}
|
}
|
||||||
if ( $interface['ifDuplex'] != $ifDuplex && $ifDuplex != "" ) {
|
|
||||||
$update .= $seperator . "`ifDuplex` = '$ifDuplex'";
|
|
||||||
$seperator = ", ";
|
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Duplex -> $ifDuplex')");
|
|
||||||
}
|
|
||||||
if ( $interface['ifType'] != $ifType && $ifType != "" ) {
|
|
||||||
$update .= $seperator . "`ifType` = '$ifType'";
|
|
||||||
$seperator = ", ";
|
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Type -> $ifType')");
|
|
||||||
}
|
|
||||||
if ( $interface['ifMtu'] != $ifMtu && $ifMtu != "" ) {
|
|
||||||
$update .= $seperator . "`ifMtu` = '$ifMtu'";
|
|
||||||
$seperator = ", ";
|
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'MTU -> $ifMtu')");
|
|
||||||
}
|
|
||||||
if ( $interface['ifPhysAddress'] != $ifPhysAddress && $ifPhysAddress != "" ) {
|
|
||||||
$update .= $seperator . "`ifPhysAddress` = '$ifPhysAddress'";
|
|
||||||
$seperator = ", ";
|
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'MAC -> $ifPhysAddress')");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $interface['ifHardType'] != $ifHardType && $ifHardType != "" ) {
|
|
||||||
$update .= $seperator . "`ifHardType` = '$ifHardType'";
|
|
||||||
$seperator = ", ";
|
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" .$interface['interface_id'] . "', NOW(), 'HW Type -> $ifHardType')");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( $interface['ifSpeed'] != $ifSpeed && $ifSpeed != "" ) {
|
|
||||||
$update .= $seperator . "`ifSpeed` = '$ifSpeed'";
|
|
||||||
$seperator = ", ";
|
|
||||||
$prev = humanspeed($interface['ifSpeed']);
|
|
||||||
$now = humanspeed($ifSpeed);
|
|
||||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Speed -> $now')");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($update) {
|
if ($update) {
|
||||||
$update_query = "UPDATE `interfaces` SET ";
|
$update_query = "UPDATE `interfaces` SET ";
|
||||||
@@ -125,7 +77,7 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
|||||||
echo("Updating : " . $device['hostname'] . " $ifDescr\nSQL :$update_query\n\n");
|
echo("Updating : " . $device['hostname'] . " $ifDescr\nSQL :$update_query\n\n");
|
||||||
$update_result = mysql_query($update_query);
|
$update_result = mysql_query($update_query);
|
||||||
} else {
|
} else {
|
||||||
echo("Not Updating : " . $device['hostname'] ." $ifDescr ( " . $interface['ifDescr'] . " )\n\n");
|
# echo("Not Updating : " . $device['hostname'] ." $ifDescr ( " . $interface['ifDescr'] . " )\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ifOperStatus == "up") {
|
if($ifOperStatus == "up") {
|
||||||
|
|||||||
Reference in New Issue
Block a user