diff --git a/html/graph.php b/html/graph.php index 161ba12179..d8b6494d5f 100644 --- a/html/graph.php +++ b/html/graph.php @@ -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); diff --git a/html/includes/print-interface.inc b/html/includes/print-interface.inc index fe353e0e1a..7621780a97 100644 --- a/html/includes/print-interface.inc +++ b/html/includes/print-interface.inc @@ -117,7 +117,7 @@ echo(""); echo(""); // 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']; diff --git a/includes/functions.php b/includes/functions.php index 50bf3a65bb..47fbf5c75e 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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
"); } diff --git a/includes/graphing.php b/includes/graphing.php index dd1f3f6ac9..4ca5f3fc67 100644 --- a/includes/graphing.php +++ b/includes/graphing.php @@ -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 "; diff --git a/includes/polling/interfaces.inc.php b/includes/polling/interfaces.inc.php index 1bf5e41059..564c1f7bbb 100644 --- a/includes/polling/interfaces.inc.php +++ b/includes/polling/interfaces.inc.php @@ -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 \ diff --git a/poll-device.php b/poll-device.php index 77ab6139dd..990508e634 100755 --- a/poll-device.php +++ b/poll-device.php @@ -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 \ diff --git a/update-inteface.php b/update-inteface.php new file mode 100755 index 0000000000..ea046e6a0d --- /dev/null +++ b/update-inteface.php @@ -0,0 +1,151 @@ +#!/usr/bin/php + " . $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'"); + +?> +