mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
move some rrds, fix some graphing, fix interface data updater
git-svn-id: http://www.observium.org/svn/observer/trunk@137 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -51,19 +51,19 @@
|
||||
$graph = graph_device_bits ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'bits':
|
||||
$graph = trafgraph ($hostname . ".". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
$graph = trafgraph ($hostname . "/". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'pkts':
|
||||
$graph = pktsgraph ($hostname . ".". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
$graph = pktsgraph ($hostname . "/". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'errors':
|
||||
$graph = errorgraph ($hostname . ".". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
$graph = errorgraph ($hostname . "/". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'nupkts':
|
||||
$graph = nucastgraph ($hostname . ".". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
$graph = nucastgraph ($hostname . "/". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'uptime':
|
||||
$graph = uptimegraph ($hostname . "-uptime.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
$graph = uptimegraph ($hostname . "/uptime.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
break;
|
||||
case 'unixfs_dev':
|
||||
$graph = unixfsgraph_dev ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical);
|
||||
|
@@ -117,7 +117,7 @@ echo("</td>");
|
||||
echo("</td></tr>");
|
||||
|
||||
// If we're showing graphs, generate the graph and print the img tags
|
||||
if($dographs && is_file("rrd/" . $hostname . ".". $ifIndex . ".rrd")) {
|
||||
if($dographs && is_file($rrd_dir . "/" . $hostname . "/". $ifIndex . ".rrd")) {
|
||||
|
||||
$type = $_GET['type'];
|
||||
|
||||
|
@@ -154,8 +154,8 @@ function truncate($substring, $max = 50, $rep = '...') {
|
||||
|
||||
|
||||
function interface_rates ($interface) {
|
||||
global $config;
|
||||
$rrdfile = "rrd/" . $interface['hostname'] . "." . $interface['ifIndex'] . ".rrd";
|
||||
global $config, $rrd_dir;
|
||||
$rrdfile = $rrd_dir . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd";
|
||||
$cmd = $config['rrdtool']." fetch -s -600s -e now ".$rrdfile." AVERAGE | grep : | cut -d\" \" -f 2,3 | grep e";
|
||||
$data = trim(`$cmd`);
|
||||
foreach( explode("\n", $data) as $entry) {
|
||||
@@ -169,7 +169,7 @@ function interface_rates ($interface) {
|
||||
|
||||
function interface_errors ($interface) {
|
||||
global $config;
|
||||
$rrdfile = "rrd/" . $interface['hostname'] . "." . $interface['ifIndex'] . ".rrd";
|
||||
$rrdfile = $rrd_dir . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd";
|
||||
$cmd = $config['rrdtool']." fetch -s -1d -e -300s $rrdfile AVERAGE | grep : | cut -d\" \" -f 4,5";
|
||||
$data = trim(`$cmd`);
|
||||
foreach( explode("\n", $data) as $entry) {
|
||||
@@ -251,6 +251,7 @@ $type = strtolower($data['os']);
|
||||
|
||||
|
||||
function delHost($id) {
|
||||
global $rrd_dir;
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
|
||||
mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'");
|
||||
$int_query = mysql_query("SELECT * FROM `interfaces` WHERE `device_id` = '$id'");
|
||||
@@ -272,7 +273,8 @@ function delHost($id) {
|
||||
mysql_query("DELETE FROM `interfaces` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `services` WHERE `service_host` = '$id'");
|
||||
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
|
||||
`rm -f rrd/$host-*.rrd`;
|
||||
`rm -f $rrd_dir/$host-*.rrd`;
|
||||
`rm -rf $rrd_dir/$host`;
|
||||
echo("Removed device $host<br />");
|
||||
}
|
||||
|
||||
|
@@ -7,9 +7,9 @@ function graph_multi_bits ($interfaces, $graph, $from, $to, $width, $height) {
|
||||
foreach(explode("\n", $interfaces) as $ifid) {
|
||||
$query = mysql_query("SELECT `ifIndex`, `hostname` FROM `interfaces` AS I, devices as D WHERE I.interface_id = '" . $ifid . "' AND I.device_id = D.device_id");
|
||||
$int = mysql_fetch_row($query);
|
||||
if(is_file($rrd_dir . "/" . $int[1] . "." . $int[0] . ".rrd")) {
|
||||
$options .= " DEF:inoctets" . $int[0] . "=" . $rrd_dir . "/" . $int[1] . "." . $int[0] . ".rrd:INOCTETS:AVERAGE";
|
||||
$options .= " DEF:outoctets" . $int[0] . "=" . $rrd_dir . "/" . $int[1] . "." . $int[0] . ".rrd:OUTOCTETS:AVERAGE";
|
||||
if(is_file($rrd_dir . "/" . $int[1] . "/" . $int[0] . ".rrd")) {
|
||||
$options .= " DEF:inoctets" . $int[0] . "=" . $rrd_dir . "/" . $int[1] . "/" . $int[0] . ".rrd:INOCTETS:AVERAGE";
|
||||
$options .= " DEF:outoctets" . $int[0] . "=" . $rrd_dir . "/" . $int[1] . "/" . $int[0] . ".rrd:OUTOCTETS:AVERAGE";
|
||||
$in_thing .= $seperator . "inoctets" . $int[0] . ",UN,0," . "inoctets" . $int[0] . ",IF";
|
||||
$out_thing .= $seperator . "outoctets" . $int[0] . ",UN,0," . "outoctets" . $int[0] . ",IF";
|
||||
$pluses .= $plus;
|
||||
@@ -139,14 +139,14 @@ function graph_device_bits ($device, $graph, $from, $to, $width, $height) {
|
||||
if($width <= "300") { $options .= "--font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
|
||||
$pluses = "";
|
||||
while($int = mysql_fetch_row($query)) {
|
||||
if(is_file($rrd_dir . "/" . $hostname . "." . $int[0] . ".rrd")) {
|
||||
if(is_file($rrd_dir . "/" . $hostname . "/" . $int[0] . ".rrd")) {
|
||||
$in_thing .= $seperator . "inoctets" . $int[0] . ",UN,0," . "inoctets" . $int[0] . ",IF";
|
||||
$out_thing .= $seperator . "outoctets" . $int[0] . ",UN,0," . "outoctets" . $int[0] . ",IF";
|
||||
$pluses = $pluses . $plus;
|
||||
$pluses .= $plus;
|
||||
$seperator = ",";
|
||||
$plus = ",+";
|
||||
$options .= "DEF:inoctets" . $int[0] . "=" . $rrd_dir . "/" . $hostname . "." . $int[0] . ".rrd:INOCTETS:AVERAGE ";
|
||||
$options .= "DEF:outoctets" . $int[0] . "=" . $rrd_dir . "/" . $hostname . "." . $int[0] . ".rrd:OUTOCTETS:AVERAGE ";
|
||||
$options .= "DEF:inoctets" . $int[0] . "=" . $rrd_dir . "/" . $hostname . "/" . $int[0] . ".rrd:INOCTETS:AVERAGE ";
|
||||
$options .= "DEF:outoctets" . $int[0] . "=" . $rrd_dir . "/" . $hostname . "/" . $int[0] . ".rrd:OUTOCTETS:AVERAGE ";
|
||||
}
|
||||
}
|
||||
$options .= " CDEF:inoctets=$in_thing$pluses ";
|
||||
@@ -171,8 +171,8 @@ function graph_device_bits ($device, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function trafgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$period = $to - $from;
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
@@ -213,8 +213,8 @@ function trafgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function pktsgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
|
||||
@@ -237,8 +237,8 @@ function pktsgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function errorgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
|
||||
@@ -261,8 +261,8 @@ function errorgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function nucastgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
|
||||
@@ -285,8 +285,8 @@ function nucastgraph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function cpugraph ($rrd, $graph , $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($width <= "300") {$options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
|
||||
@@ -301,8 +301,8 @@ function cpugraph ($rrd, $graph , $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function uptimegraph ($rrd, $graph , $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:$mono_font --font AXIS:6:$mono_font --font-render-mode normal "; }
|
||||
@@ -319,8 +319,8 @@ function uptimegraph ($rrd, $graph , $from, $to, $width, $height, $title, $verti
|
||||
|
||||
|
||||
function memgraph ($rrd, $graph , $from, $to, $width, $height, $title, $vertical) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$period = $to - $from;
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
@@ -350,8 +350,8 @@ function memgraph ($rrd, $graph , $from, $to, $width, $height, $title, $vertical
|
||||
}
|
||||
|
||||
function ip_graph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$period = $to - $from;
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
@@ -397,8 +397,8 @@ function ip_graph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function icmp_graph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$period = $to - $from;
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
@@ -448,8 +448,8 @@ function icmp_graph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function tcp_graph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$period = $to - $from;
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
@@ -495,8 +495,8 @@ function tcp_graph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
}
|
||||
|
||||
function udp_graph ($rrd, $graph, $from, $to, $width, $height) {
|
||||
global $config, $rrdtool, $installdir, $mono_font;
|
||||
$database = "rrd/" . $rrd;
|
||||
global $config, $rrdtool, $installdir, $mono_font, $rrd_dir;
|
||||
$database = $rrd_dir . "/" . $rrd;
|
||||
$imgfile = "graphs/" . "$graph";
|
||||
$period = $to - $from;
|
||||
$options = "--alt-autoscale-max -E --start $from --end $to --width $width --height $height ";
|
||||
|
@@ -32,7 +32,11 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
||||
$ifAlias = trim(str_replace("\"", "", $ifAlias));
|
||||
$ifAlias = trim($ifAlias);
|
||||
|
||||
$rrdfile = "rrd/" . $device['hostname'] . "." . $interface['ifIndex'] . ".rrd";
|
||||
$old_rrdfile = "rrd/" . $device['hostname'] . "." . $interface['ifIndex'] . ".rrd";
|
||||
$rrdfile = $host_rrd . "/" . $interface['ifIndex'] . ".rrd";
|
||||
|
||||
if(is_file($old_rrdfile) && !is_file($rrdfile)) { rename($old_rrdfile, $rrdfile); echo("Moving $old_rrdfile to $rrdfile"); }
|
||||
|
||||
if(!is_file($rrdfile)) {
|
||||
$woo = `rrdtool create $rrdfile \
|
||||
DS:INOCTETS:COUNTER:600:U:100000000000 \
|
||||
|
@@ -35,6 +35,10 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
|
||||
$pingable = isPingable($device['hostname']);
|
||||
|
||||
$host_rrd = $rrd_dir . "/" . $device['hostname'];
|
||||
|
||||
if(!is_dir($host_rrd)) { mkdir($host_rrd); echo("Created directory : $host_rrd\n"); }
|
||||
|
||||
if($pingable) { echo("Pings : yes :)\n"); } else { echo("Pings : no :(\n"); }
|
||||
|
||||
$snmpable = FALSE;
|
||||
@@ -249,7 +253,11 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
mail($notify_email, "Device Rebooted: " . $device['hostname'], "Device Rebooted :" . $device['hostname'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']);
|
||||
}
|
||||
|
||||
$uptimerrd = "rrd/" . $device['hostname'] . "-uptime.rrd";
|
||||
$uptime_rrd = $rrd_dir . "/" . $device['hostname'] . "/uptime.rrd";
|
||||
|
||||
$old_uptime_rrd = "rrd/" . $device['hostname'] . "-uptime.rrd";
|
||||
if(is_file($old_uptime_rrd) && !is_file($uptimerrd)) { rename($old_uptime_rrd, $uptime_rrd); echo("Moving $old_uptime_rrd to $uptime_rrd"); }
|
||||
|
||||
if(!is_file($uptimerrd)) {
|
||||
$woo = `rrdtool create $uptimerrd \
|
||||
DS:uptime:GAUGE:600:0:U \
|
||||
|
151
update-inteface.php
Executable file
151
update-inteface.php
Executable file
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/php
|
||||
<?
|
||||
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
|
||||
if($argv[1]) { $where = "WHERE `interface_id` = '$argv[1]'"; }
|
||||
|
||||
$interface_query = mysql_query("SELECT * FROM `interfaces` $where");
|
||||
while ($interface = mysql_fetch_array($interface_query)) {
|
||||
|
||||
unset($this);
|
||||
|
||||
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_id = '" . $interface['device_id'] . "'"));
|
||||
if($device['status'] == '1') {
|
||||
|
||||
unset($update);
|
||||
unset($update_query);
|
||||
unset($seperator);
|
||||
|
||||
echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n");
|
||||
|
||||
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ifName." . $interface['ifIndex'];
|
||||
$snmp_cmd .= " ifDescr." . $interface['ifIndex'] . " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ";
|
||||
$snmp_cmd .= "ifAlias." . $interface['ifIndex'] . " ifSpeed." . $interface['ifIndex'] . " 1.3.6.1.2.1.10.7.2.1." . $interface['ifIndex'];
|
||||
$snmp_cmd .= " ifType." . $interface['ifIndex'] . " ifMtu." . $interface['ifIndex'] . " ifPhysAddress." . $interface['ifIndex'];
|
||||
|
||||
$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 Instance currently exists at this OID", "", $snmp_output);
|
||||
$snmp_output = str_replace("\"", "", $snmp_output);
|
||||
|
||||
if($device['os'] == "IOS") {
|
||||
|
||||
$snmp_cmdb = "snmpget -M /usr/share/snmp/mibs/ -m CISCO-VLAN-MEMBERSHIP-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
|
||||
$snmp_cmdb .= " .1.3.6.1.4.1.9.2.2.1.1.1." . $interface['ifIndex'];
|
||||
$snmp_cmdb .= " .1.3.6.1.4.1.9.9.68.1.2.2.1.2." . $interface['ifIndex'];
|
||||
$snmp_cmdb .= " .1.3.6.1.4.1.9.9.46.1.6.1.1.16." . $interface['ifIndex'];
|
||||
|
||||
$snmp_outputb = trim(`$snmp_cmdb`);
|
||||
$snmp_outputb = str_replace("No Such Object available on this agent at this OID", "", $snmp_outputb);
|
||||
$snmp_outputb = str_replace("No Such Instance currently exists at this OID", "", $snmp_outputb);
|
||||
$snmp_outputb = str_replace("\"", "", $snmp_outputb);
|
||||
|
||||
list($this['ifHardType'], $this['ifVlan'], $this['ifTrunk']) = explode("\n", $snmp_outputb);
|
||||
if($this['ifTrunk'] == "notApplicable") { unset($this['ifTrunk']); }
|
||||
if($this['ifVlan'] == "") { unset($this['ifVlan']); }
|
||||
|
||||
if ( $interface['ifTrunk'] != $this['ifTrunk'] ) {
|
||||
$update .= $seperator . "`ifTrunk` = '" . $this['ifTrunk'] . "'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'VLAN Trunk -> " . $this['ifTrunk'] . "')");
|
||||
}
|
||||
|
||||
|
||||
if ( $interface['ifVlan'] != $this['ifVlan']) {
|
||||
$update .= $seperator . "`ifVlan` = '" . $this['ifVlan'] . "'";
|
||||
echo($update);
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'VLAN Vlan -> " . $this['ifVlan'] . "')");
|
||||
}
|
||||
|
||||
if($this['ifTrunk']) { echo("Interface is a " . $this['ifTrunk'] . " trunk\n"); }
|
||||
if($this['ifVlan']) { echo("Interface is a member of vlan " . $this['ifVlan'] . " \n"); }
|
||||
|
||||
|
||||
}
|
||||
|
||||
list($ifName, $ifDescr, $ifAdminStatus, $ifOperStatus, $ifAlias, $ifSpeed, $ifDuplex, $ifType, $ifMtu, $ifPhysAddress) = 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); }
|
||||
$ifAlias = trim(str_replace("\"", "", $ifAlias));
|
||||
$ifAlias = trim($ifAlias);
|
||||
|
||||
$ifPhysAddress = strtolower(str_replace("\"", "", $ifPhysAddress));
|
||||
$ifPhysAddress = str_replace(" ", ":", $ifPhysAddress);
|
||||
|
||||
if ( $interface['ifDescr'] != $ifDescr && $ifDescr != "" ) {
|
||||
$update .= $seperator . "`ifDescr` = '$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 ) {
|
||||
$update .= $seperator . "`ifAlias` = '$ifAlias'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')");
|
||||
}
|
||||
if ( $interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "" ) {
|
||||
$update .= $seperator . "`ifOperStatus` = '$ifOperStatus'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface went $ifOperStatus')");
|
||||
}
|
||||
if ( $interface['ifAdminStatus'] != $ifAdminStatus && $ifAdminStatus != "" ) {
|
||||
$update .= $seperator . "`ifAdminStatus` = '$ifAdminStatus'";
|
||||
$seperator = ", ";
|
||||
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')");
|
||||
}
|
||||
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'] != $this['ifHardType']) {
|
||||
$update .= $seperator . "`ifHardType` = '" . $this['ifHardType'] . "'";
|
||||
$seperator = ", ";
|
||||
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" .$interface['interface_id'] . "', NOW(), 'HW Type -> " . $this['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) {
|
||||
$update_query = "UPDATE `interfaces` SET ";
|
||||
$update_query .= $update;
|
||||
$update_query .= " WHERE `interface_id` = '" . $interface['interface_id'] . "'";
|
||||
$update_result = mysql_query($update_query);
|
||||
} else {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mysql_query("UPDATE interfaces set ifPhysAddress = '' WHERE ifPhysAddress = 'No Such Instance currently exists at this OID'");
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user