diff --git a/cleanup.php b/cleanup.php index 53c4223dda..854e08799d 100755 --- a/cleanup.php +++ b/cleanup.php @@ -66,7 +66,7 @@ while ($link = mysql_fetch_array($link_query)) { echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at end\n"); echo(mysql_result(mysql_query("SELECT COUNT(adj_id) FROM `adjacencies`"), 0) . " adjacencies at start\n"); -$link_query = mysql_query("SELECT * FROM `adjacencies` AS A, `interfaces` AS I, `devices` AS D, networks AS N WHERE I.interface_id = A.interface_id AND D.id = I.device_id AND N.id = A.network_id;"); +$link_query = mysql_query("SELECT * FROM `adjacencies` AS A, `interfaces` AS I, `devices` AS D, networks AS N WHERE I.interface_id = A.interface_id AND D.device_id = I.device_id AND N.id = A.network_id;"); while ($link = mysql_fetch_array($link_query)) { $id = $link['adj_id']; $netid = $link['network_id']; diff --git a/config.php.default b/config.php.default index a62ff9d287..3516ad318e 100755 --- a/config.php.default +++ b/config.php.default @@ -6,8 +6,9 @@ $db_user = "observer"; $db_pass = ""; $db_name = "observer"; -### Installation Location -$installdir = "/var/sites/network.vostron.net/"; +### Installation Locations +$installdir = "/var/sites/observer/"; +$rrd_dir = $installdir . "rrd/"; ### Default community $community = "public"; @@ -40,6 +41,8 @@ $show_if_transit = 0; $show_if_peering = 0; $show_locations = 1; +$enable_syslog = 0; + ### Interface name strings to ignore $bif = array("null", "virtual-", "unrouted", "eobc", "mpls", "sl0", "lp0", "faith0", "-atm layer", "-atm subif", "-shdsl", "-adsl", diff --git a/cron-hourly.sh b/cron-hourly.sh index f456156a80..7acf99dc2c 100755 --- a/cron-hourly.sh +++ b/cron-hourly.sh @@ -10,3 +10,4 @@ ./discover-cisco-temp.php & ./discover-vlans.php & ./update-interface.php & +./check-errors.php & diff --git a/html/images/16/arrow_out.png b/html/images/16/arrow_out.png index 2e9bc42bec..d2688a799d 100755 Binary files a/html/images/16/arrow_out.png and b/html/images/16/arrow_out.png differ diff --git a/html/includes/authenticate.inc b/html/includes/authenticate.inc index 02db0f8182..168a50c5c0 100644 --- a/html/includes/authenticate.inc +++ b/html/includes/authenticate.inc @@ -22,12 +22,13 @@ if($_GET['logout']) { $encrypted=$_COOKIE['encrypted']; } - $sql = "select username, level from users where username='$_SESSION[username]' and password='$encrypted'"; + $sql = "select username, level, user_id from users where username='$_SESSION[username]' and password='$encrypted'"; $row = mysql_fetch_row(mysql_query($sql)); if ( $_SESSION['username'] != "" && $row[0] == $_SESSION['username'] ) { $_SESSION['userlevel'] = $row[1]; $_SESSION['authenticated'] = true; + $_SESSION['user_id'] = $row[2]; setcookie("username", $username); setcookie("encrypted", $encrypted); } diff --git a/html/includes/print-event-short.inc b/html/includes/print-event-short.inc index fc22c782e2..fe47bbe259 100644 --- a/html/includes/print-event-short.inc +++ b/html/includes/print-event-short.inc @@ -17,10 +17,10 @@ if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } $entry[humandate] "); - $if['id'] = $entry[interface]; - $if['if'] = makeshortif($interface); + $if['interface_id'] = $entry[interface]; + $if['ifDescr'] = makeshortif($interface); echo(" - " . generateiflink($if) . " + " . generateiflink($if) . " " . truncate($entry[message], 45) diff --git a/html/includes/print-interface-graphs.php b/html/includes/print-interface-graphs.php index ab752c1166..5df5829afc 100644 --- a/html/includes/print-interface-graphs.php +++ b/html/includes/print-interface-graphs.php @@ -1,24 +1,26 @@ ', LEFT);\" onmouseout=\"return nd();\"> + $yearly_traffic = "graph.php?if=" . $interface['interface_id'] . "&type=$graph_type&from=$year&to=$now&width=217&height=100"; + $yearly_url = "graph.php?if=" . $interface['interface_id'] . "&type=$graph_type&from=$year&to=$now&width=500&height=150"; + + echo("', LEFT, BORDER, 0);\" onmouseout=\"return nd();\"> "); - echo("', LEFT);\" onmouseout=\"return nd();\"> + echo("', LEFT, BORDER, 0);\" onmouseout=\"return nd();\"> "); - echo("', LEFT);\" onmouseout=\"return nd();\"> + echo("', LEFT, BORDER, 0, WIDTH, 350);\" onmouseout=\"return nd();\"> "); - echo("', LEFT);\" onmouseout=\"return nd();\"> + echo("', LEFT, BORDER, 0, WIDTH, 350);\" onmouseout=\"return nd();\"> "); ?> diff --git a/html/includes/print-interface.inc b/html/includes/print-interface.inc index 3192adad01..13dac6284a 100644 --- a/html/includes/print-interface.inc +++ b/html/includes/print-interface.inc @@ -2,6 +2,11 @@ # This file prints a table row for each interface + $interface['device_id'] = $device['device_id']; + $interface['hostname'] = $device['hostname']; + + if(!$_GET['type']) { $_GET['type'] = "bits"; } + $if_id = $interface['interface_id']; $ifDescr = fixifName($interface['ifDescr']); $ifIndex = $interface['ifIndex']; @@ -10,18 +15,22 @@ $ifPhysAddress = $interface['ifPhysAddress']; $ifType = fixiftype($interface['ifType']); $ifHardType = $interface['ifHardType']; - -# echo($interface['ifHardType']); - +# $errors = interface_errors($interface); +# $rates = interface_rates($interface); + if($ifAlias) {$ifAlias = $ifAlias . "
";} if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; } + if($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { + $error_img = generateiflink($interface,"Interface Errors",errors); + } else { $error_img = ""; } + $graph_url = "graph.php?if=$if_id&from=$twoday&to=$now&width=400&height=120&type=bits"; echo(" - " . generateiflink($interface, "$i. $ifDescr") . " + " . generateiflink($interface, "$i. $ifDescr") . " $error_img
$ifAlias"); unset ($break); if(!$dographs) { @@ -31,6 +40,16 @@ $break = " "; } echo(""); + echo(""); + if($interface['ifOperStatus'] == "up") { + + $in_perc = round($interface['in_rate']/$interface['ifSpeed']*100); + $out_perc = round($interface['in_rate']/$interface['ifSpeed']*100); + + echo(" " . formatRates($interface['in_rate']) . "
"); + echo(" " . formatRates($interface['out_rate']) . ""); + + } echo(""); if($ifSpeed && $ifSpeed != "") { echo("$ifSpeed"); } echo("
"); @@ -84,7 +103,7 @@ echo(""); $this_ifname = fixifName($new['ifDescr']); $wq = mysql_query("select count(*) FROM links WHERE dst_if = '$this_ifid' AND src_if = $if_id;"); if (@mysql_result($wq, 0) == '0' && $this_hostname != $hostname) { - $graph_url = "graph.php?if=$this_ifid&from=$twoday&to=$now&width=400&height=120&type=bits"; + $graph_url = "graph.php?if=$this_ifid&from=$twoday&to=$now&width=400&height=120&type=bits'"; echo("$br  Same Subnet" . generateiflink($new) . " on " . generatedevicelink($new)); $br = "
"; } @@ -97,15 +116,44 @@ echo(""); // If we're showing graphs, generate the graph and print the img tags if($dographs && is_file("rrd/" . $hostname . ".". $ifIndex . ".rrd")) { - $daily_traffic = "graph.php?if=$if_id&type=bits&from=$day&to=$now&width=210&height=100"; - $weekly_traffic = "graph.php?if=$if_id&type=bits&from=$week&to=$now&width=210&height=100"; - $monthly_traffic = "graph.php?if=$if_id&type=bits&from=$month&to=$now&width=210&height=100"; - $yearly_traffic = "graph.php?if=$if_id&type=bits&from=$year&to=$now&width=210&height=100"; + + $type = $_GET['type']; - echo(""); - echo(" "); - echo(" "); - echo(""); +# echo(""); +# include("includes/print-interface-graphs.php"); +# echo(""); + + $daily_traffic = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$day&to=$now&width=210&height=100"; + $daily_url = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$day&to=$now&width=500&height=150"; + + $weekly_traffic = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$week&to=$now&width=210&height=100"; + $weekly_url = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$week&to=$now&width=500&height=150"; + + $monthly_traffic = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$month&to=$now&width=210&height=100"; + $monthly_url = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$month&to=$now&width=500&height=150"; + + $yearly_traffic = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$year&to=$now&width=210&height=100"; + $yearly_url = "graph.php?if=$if_id&type=" . $_GET['type'] . "&from=$year&to=$now&width=500&height=150"; + + echo(""); + + echo("', LEFT, BORDER, 0);\" + onmouseout=\"return nd();\"> "); + echo("', LEFT, BORDER, 0);\" + onmouseout=\"return nd();\"> "); + echo("', LEFT, WIDTH, 350, BORDER, 0);\" + onmouseout=\"return nd();\"> "); + echo("', LEFT, WIDTH, 350, BORDER, 0);\" + onmouseout=\"return nd();\"> "); + + + + echo(""); + +# echo(""); +# echo(" "); +# echo(" "); +# echo(""); } diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 7e887dc580..14b1f75fef 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -19,6 +19,7 @@ unset($this_alert); } + ?> "); $dographs = 1; +if(!$_GET['type']) { $_GET['type'] = "bits"; } + include("pages/device/dev-ifs.inc"); ?> diff --git a/html/pages/device/dev-overview.inc b/html/pages/device/dev-overview.inc index f52c72dbc2..b28dece0fc 100644 --- a/html/pages/device/dev-overview.inc +++ b/html/pages/device/dev-overview.inc @@ -24,12 +24,13 @@ echo(" "); -if(file_exists("includes/dev-data-" . strtolower($device[os]) . ".inc")) { +#if(file_exists("includes/dev-data-" . strtolower($device[os]) . ".inc.php")) { echo("
"); - echo("

Device Data

"); - include("includes/dev-data-" . strtolower($device[os]) . ".inc"); +# echo("

Device Data

"); +# include("includes/dev-data-" . strtolower($device[os]) . ".inc.php"); + include("includes/dev-overview-data.inc.php"); echo("
"); -} +#} if(mysql_result(mysql_query("SELECT count(storage_id) from storage WHERE host_id = '" . $device['device_id'] . "'"),0)) { @@ -38,22 +39,22 @@ if(mysql_result(mysql_query("SELECT count(storage_id) from storage WHERE host_id echo(""); $i = '1'; - echo(" + echo(""); $drives = mysql_query("SELECT * FROM `storage` WHERE host_id = '" . $device['device_id'] . "'"); while($drive = mysql_fetch_array($drives)) { $total = $drive['hrStorageSize'] * $drive['hrStorageAllocationUnits']; $used = $drive['hrStorageUsed'] * $drive['hrStorageAllocationUnits']; - $perc = $drive['storage_perc']; + $perc = round($drive['storage_perc'], 0); $total = formatStorage($total); $used = formatStorage($used); $store_url = "graph.php?id=" . $drive['storage_id'] . "&type=unixfs&from=$month&to=$now&width=400&height=125"; $store_popup = "onmouseover=\"return overlib('', LEFT);\" onmouseout=\"return nd();\""; - if($perc > '80') { $drv_class='red'; } else { $drvclass=''; } + if($perc > '80') { $drv_colour='#cc0000'; } else { $drvclass='#0000cc'; } echo(""); + "); $i++; } echo("
MountpointUsage%Total
MountpointUsageTotal Used
" . $drive['hrStorageDescr'] . " - " . $perc . "%" . $total . "" . $used . "
" . $perc . "%" . $total . "" . $used . "
"); @@ -74,14 +75,12 @@ if(mysql_result(mysql_query("SELECT count(temp_id) from temperature WHERE temp_h while($temp = mysql_fetch_array($temps)) { if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - if($temp['temp_current'] < '30') { $temp_class=''; - } elseif($temp['temp_current'] < '40') { $temp_class='blue'; - } elseif($temp['temp_current'] < '50') { $temp_class='green'; - } elseif($temp['temp_current'] < '60') { $temp_class='orange'; - } else { $temp_class='red'; } + $temp_perc = $temp['temp_current'] / $temp['temp_limit'] * 100; + + $temp_colour = percent_colour($temp_perc); $temp['temp_descr'] = truncate($temp['temp_descr'], 25, ''); - echo("" . $temp['temp_descr'] . "" . $temp['temp_current'] . "°C"); + echo("" . $temp['temp_descr'] . "" . $temp['temp_current'] . "°C"); if($i == $rows) { echo(""); } $i++; } @@ -112,7 +111,7 @@ echo("
"); if($interfaces['total']) { echo("
-

Total Traffic

" . device_traffic_image($device['device_id'], 490, 100, $day, $now) . "
"); +

Total Traffic

" . device_traffic_image($device['device_id'], 490, 100, $day, '-300s') . ""); } if($interfaces['total']) { diff --git a/html/pages/device/dev-syslog.inc b/html/pages/device/dev-syslog.inc index e4c51d37a8..f5db434f37 100644 --- a/html/pages/device/dev-syslog.inc +++ b/html/pages/device/dev-syslog.inc @@ -1,13 +1,13 @@
"); diff --git a/html/pages/eventlog.php b/html/pages/eventlog.php index ddbe8edf3e..cf2d2ec70f 100644 --- a/html/pages/eventlog.php +++ b/html/pages/eventlog.php @@ -1,6 +1,11 @@ "); @@ -16,9 +21,14 @@ while($interface = mysql_fetch_array($query)) { $speed = humanspeed($interface['ifSpeed']); $type = humanmedia($interface['ifType']); + if($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { + $error_img = generateiflink($interface,"Interface Errors",errors); + } else { $error_img = ""; } + + echo(" " . generatedevicelink($interface) . " - " . generateiflink($interface, makeshortif(fixifname($interface['ifDescr']))) . " + " . generateiflink($interface, makeshortif(fixifname($interface['ifDescr']))) . " $error_img $speed $type " . $interface[ifAlias] . " diff --git a/html/pages/locations.php b/html/pages/locations.php index 5fa0142105..58578ba4cc 100644 --- a/html/pages/locations.php +++ b/html/pages/locations.php @@ -1,17 +1,32 @@ "); -$device_query = mysql_query("select location from devices GROUP BY location ORDER BY location"); +if($_SESSION['userlevel'] == '10') { + $sql = "SELECT `location` FROM `devices` GROUP BY `location` ORDER BY `location`"; +} else { + $sql = "SELECT `location` FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' GROUP BY `location` ORDER BY `location`"; +} + + +$device_query = mysql_query($sql); while($device = mysql_fetch_array($device_query)) { if($bg == "#ffffff") { $bg = "#eeeeee"; } else { $bg="#ffffff"; } - $num = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '$device[location]'"),0); - $net = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '$device[location]' AND type = 'network'"),0); - $srv = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '$device[location]' AND type = 'server'"),0); - $fwl = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '$device[location]' AND type = 'firewall'"),0); + if($_SESSION['userlevel'] == '10') { + $num = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "'"),0); + $net = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'network'"),0); + $srv = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'server'"),0); + $fwl = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND type = 'firewall'"),0); + $hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '" . $device['location'] . "' AND status = '0'"),0); + } else { + $num = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "'"),0); + $net = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "' AND D.type = 'network'"),0); + $srv = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "' AND type = 'server'"),0); + $fwl = mysql_result(mysql_query("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $device['location'] . "' AND type = 'firewall'"),0); + $hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE location = '" . $device['location'] . "' AND status = '0'"),0); + } - $hostalerts = mysql_result(mysql_query("SELECT COUNT(device_id) FROM devices WHERE location = '$device[location]' AND status = '0'"),0); if($hostalerts) { $alert = ""; } $loc = $device[location]; diff --git a/html/pages/services.php b/html/pages/services.php index aa35b03d37..a3014fd334 100644 --- a/html/pages/services.php +++ b/html/pages/services.php @@ -1,12 +1,15 @@ "); //echo(""); - +if ($_SESSION['userlevel'] == '10') { $host_sql = "SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.service_host GROUP BY D.hostname ORDER BY D.hostname"; +} else { + $host_sql = "SELECT * FROM devices AS D, services AS S, devices_perms AS P WHERE D.device_id = S.service_host AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' $where GROUP BY D.hostname ORDER BY D.hostname"; +} $host_query = mysql_query($host_sql); while($host_data = mysql_fetch_array($host_query)) { $device_id = $host_data['device_id']; diff --git a/html/pages/syslog.php b/html/pages/syslog.php index 3cc7a25ec2..d48b40567d 100644 --- a/html/pages/syslog.php +++ b/html/pages/syslog.php @@ -1,121 +1,18 @@ - - - - - - - - - - - "); +$sql = "select * from syslog ORDER BY datetime DESC LIMIT 1000"; $query = mysql_query($sql); -while($event = mysql_fetch_array($query)) + +echo("
DeviceServiceStatusChangedCheckedMessage
- - Time - - - Hostname - - - Type - - - Message - -
"); + +while($entry = mysql_fetch_array($query)) { - unset($class); - unset($argh); - - $event[msg] = preg_replace("/.*%/", "", $event[msg]); - $event[msg] = preg_replace("/[0-9]+:\ /", "", $event[msg]); - - $prefix = preg_replace ("/(.+):\ .*/", "\\1", $event[msg]); - - $event[msg] = preg_replace ("/.+:\ /", "", $event[msg]); - - if($prefix == $event[msg]) { unset ($prefix); } - - $prefix = str_replace("CRYPTO-4-RECVD_PKT_INV_SPI: decaps", "Crypto Invalid SPI", $prefix); - $prefix = str_replace("LINEPROTO-5-UPDOWN", "Lineproto Up/Down", $prefix); - $prefix = str_replace("LINK-3-UPDOWN", "Link Up/Down", $prefix); - $prefix = str_replace("LINEPROTO-SP-5-UPDOWN", "Lineproto Up/Down", $prefix); - $prefix = str_replace("LINK-SP-3-UPDOWN", "Link Up/Down", $prefix); - - $prefix = str_replace("PIM-6-INVALID_RP_JOIN", "PIM Invalid RP Join", $prefix); - $prefix = str_replace("BGP-3-NOTIFICATION", "BGP Notification", $prefix); - $prefix = str_replace("LINK-3-UPDOWN", "Link Up/Down", $prefix); - $prefix = str_replace("DIALER-6-UNBIND", "Dialer Unbound", $prefix); - $prefix = str_replace("DIALER-6-BIND", "Dialer Bound", $prefix); - $prefix = str_replace("SYS-5-CONFIG_I", "System Configured", $prefix); - $prefix = str_replace("VPDN-6-CLOSED", "VPDN Closed", $prefix); - $prefix = str_replace("DIALER-6-BIND", "Dialer Bound", $prefix); - $prefix = str_replace("PCMCIAFS-5-DIBERR", "PCMCIA FS Error", $prefix); - $prefix = str_replace("BGP-5-ADJCHANGE", "BGP Adj Change", $prefix); - $prefix = str_replace("MSDP-5-PEER_UPDOWN", "MSDP Peer UP/Down", $prefix); - $prefix = str_replace("SYS-5-CONFIG_I", "System Configured", $prefix); - - $prefix = preg_replace("/.*ETHER-3-UNDERFLO/", "Ethernet Underflow", $prefix); - - if(strstr($event[msg], "BGP authentication failure") !== false) { $class = "pinkbg"; } - if(strstr($event[msg], "Down BGP Notification received") !== false) { $class = "redbg"; } - if(strstr($event[msg], "DOWN on interface") !== false) { $class = "redbg"; } - if(strstr($event[msg], "from FULL to DOWN") !== false) { $class = "redbg"; } - if(strstr($event[msg], "changed state to down") !== false) { $class = "redbg"; } - if(strstr($event[msg], "(cease)") !== false) { $class = "redbg"; } - if(strstr($event[msg], "(hold time expired)") !== false) { $class = "redbg"; } - if(strstr($event[msg], "Configured from console") !== false) { $class = "bluebg"; } - if(strstr($event[msg], "DR change ") !== false) { $class = "bluebg"; } - if(strstr($event[msg], "Up") !== false) { $class = "greenbg"; } - if(strstr($event[msg], "from LOADING to FULL") !== false) { $class = "greenbg"; } - if(strstr($event[msg], "UP on interface ") !== false) { $class = "greenbg"; } - if(strstr($event[msg], "changed state to up") !== false) { $class = "greenbg"; } - if(strstr($event[msg], "A format in this router is required") !== false) { $class = "greybg"; } - if(strstr($event[msg], "bytes failed from") !== false) { $class = "greybg"; } - if($event[msg] == "Attempted to connect to RSHELL from 195.74.96.24" ) { $argh = 1; } - - $event[msg] = str_replace("PCMCIA disk 0 is formatted from a different router or PC. A format in this router is required before an image can be booted from this device", "PCMCIA diak 0 is incorrectly formatted", $event[msg]); - -if(!$argh) { - echo (" - - - - - - - - - - - - -"); + include("includes/print-syslog.inc"); } -} +echo("
- - $event[humandate] - - - $event[host] - - - $prefix - - - $event[msg] - -
"); ?> diff --git a/html/pages/temperatures.php b/html/pages/temperatures.php index 5d1ff47281..25ccbcf221 100644 --- a/html/pages/temperatures.php +++ b/html/pages/temperatures.php @@ -1,6 +1,11 @@ "); @@ -28,11 +33,15 @@ while($temp = mysql_fetch_array($query)) { " . $temp['temp_descr'] . " "; + $temp_perc = $temp['temp_current'] / $temp['temp_limit'] * 100; + $temp_colour = percent_colour($temp_perc); + + echo(" " . generatedevicelink($temp) . " $temp_popup - " . print_temperature($temp['temp_current'], $temp['temp_limit']) . " + " . $temp['temp_current'] . " " . $temp['temp_limit'] . " " . $temp['temp_notes'] . " \n"); diff --git a/includes/functions.php b/includes/functions.php index 99dada22cd..00c067832f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -9,45 +9,97 @@ include("snom.php"); include("graphing.php"); include("print-functions.php"); +function devicepermitted($device_id) { + global $_SESSION; + if($_SESSION['level'] > "5") { $allowed = true; + } elseif ( @mysql_result(mysql_query("SELECT * FROM devices_perms WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `device_id` = $device_id"), 0) > '0' ) { + $allowed = true; + } else { $allowed = false; } + return $allowed; + +} + +function formatRates($rate) { + $sizes = Array('bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps'); + $round = Array('0','0','0','2','2','2','2','2','2'); + $ext = $sizes[0]; + for ($i=1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; } + return round($rate, $round[$i]).$ext; +} function formatStorage($size) { $sizes = Array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'); $ext = $sizes[0]; - for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { - $size = $size / 1024; - $ext = $sizes[$i]; - } + for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; } return round($size, 2).$ext; } + +function percent_colour($perc) +{ + $r = min(255, 5 * ($perc - 50)); + $b = max(0, 255 - (5 * $perc)); + + return sprintf('#%02x%02x%02x', $r, 0, $b); +} + +function percent_colour_old($perc) { + $red = round(5 * $perc); + $blue = round(255 - (5 * $perc)); + if($red > '255') { $red = "255"; } + if($blue < '0') { $blue = "0"; } + $red = dechex($red); + $blue = dechex($blue); + if(strlen($red) == 1) { $red = "0$red"; } + if(strlen($blue) == 1) { $blue = "0$blue"; } + $colour = "#$red" . "00" . "$blue"; + return $colour; +} + function print_error($text){ - -echo("
$text
"); - + echo("
$text
"); } function print_message($text){ - -echo("
$text
"); - + echo("
$text
"); } function truncate($substring, $max = 50, $rep = '...') { - if(strlen($substring) < 1){ - $string = $rep; - }else{ - $string = $substring; - } - - $leave = $max - strlen ($rep); - - if(strlen($string) > $max){ - return substr_replace($string, $rep, $leave); - }else{ - return $string; - } + if(strlen($substring) < 1){ $string = $rep; } else { $string = $substring; } + $leave = $max - strlen ($rep); + if(strlen($string) > $max){ return substr_replace($string, $rep, $leave); } else { return $string; } } + +function interface_rates ($interface) { + global $rrdtool; + $rrdfile = "rrd/" . $interface['hostname'] . "." . $interface['ifIndex'] . ".rrd"; + $data = trim(`$rrdtool fetch -s -600s -e now $rrdfile AVERAGE | grep : | cut -d" " -f 2,3 | grep e`); +# $data = trim(`$rrdtool fetch -s -301s -e -300s $rrdfile AVERAGE | grep : | cut -d" " -f 2,3`); + foreach( explode("\n", $data) as $entry) { + list($in, $out) = split(" ", $entry); + $rate['in'] = $in * 8; + $rate['out'] = $out * 8; + } + return $rate; +} + + +function interface_errors ($interface) { + global $rrdtool; + $rrdfile = "rrd/" . $interface['hostname'] . "." . $interface['ifIndex'] . ".rrd"; + $data = trim(`$rrdtool fetch -s -1d -e -300s $rrdfile AVERAGE | grep : | cut -d" " -f 4,5`); + foreach( explode("\n", $data) as $entry) { + list($in, $out) = explode(" ", $entry); + $in_errors += ($in * 300); + $out_errors += ($out * 300); + } + $errors['in'] = round($in_errors); + $errors['out'] = round($out_errors); + return $errors; +} + + function geteventicon ($message) { if($message == "Device status changed to Down") { $icon = "server_connect.png"; } if($message == "Device status changed to Up") { $icon = "server_go.png"; } @@ -58,14 +110,15 @@ function geteventicon ($message) { if($icon) { return $icon; } else { return false; } } - -function generateiflink($interface, $text=0) { +function generateiflink($interface, $text=0,$type=bits) { global $twoday; global $now; if(!$text) { $text = fixIfName($interface['ifDescr']); } + if(!$type) { $type = 'bits'; } $class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']); - $graph_url = "graph.php?if=" . $interface['interface_id'] . "&from=$twoday&to=$now&width=400&height=120&type=bits"; - $link = "');\" onmouseout=\"return nd();\">$text"; + $graph_url = "graph.php?if=" . $interface['interface_id'] . "&from=$twoday&to=$now&width=400&height=120&type=" . $type; + $link = "');\" onmouseout=\"return nd();\">$text"; return $link; } @@ -95,30 +148,23 @@ function devclass($device) { function getImage($host) { - $sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'"; $data = mysql_fetch_array(mysql_query($sql)); - $type = strtolower($data['os']); - if(file_exists("images/os/$type" . ".png")){ $image = ""; } elseif(file_exists("images/os/$type" . ".gif")){ $image = ""; } if($device['monowall']) {$image = "";} - if($type == "linux") { $features = strtolower(trim($data[features])); list($distro) = split(" ", $features); if(file_exists("images/os/$distro" . ".png")){ $image = ""; } elseif(file_exists("images/os/$distro" . ".gif")){ $image = ""; } } - return $image; - } function delHost($id) { - $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'"); @@ -167,18 +213,15 @@ function scanUDP ($host, $port, $timeout) { $handle = fsockopen($host, $port, &$errno, &$errstr, 2); if (!$handle) { } - socket_set_timeout ($handle, $timeout); $write = fwrite($handle,"\x00"); if (!$write) { next; } - $startTime = time(); $header = fread($handle, 1); $endTime = time(); $timeDiff = $endTime - $startTime; - if ($timeDiff >= $timeout) { fclose($handle); return 1; @@ -225,10 +268,8 @@ function humanspeed($speed) { function netmask2cidr($netmask) { - list ($network, $cidr) = explode("/", trim(`ipcalc $address/$mask | grep Network | cut -d" " -f 4`)); return $cidr; - } function cidr2netmask() { @@ -297,7 +338,6 @@ function isValidInterface($if) { function ifclass($ifOperStatus, $ifAdminStatus) { $ifclass = "interface-upup"; - if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; } if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; } if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; } @@ -330,16 +370,13 @@ function utime() { } function fixiftype ($type) { - $type = str_replace("ethernetCsmacd", "Ethernet", $type); $type = str_replace("tunnel", "Tunnel", $type); $type = str_replace("softwareLoopback", "Software Loopback", $type); $type = str_replace("propVirtual", "Ethernet VLAN", $type); $type = str_replace("ethernetCsmacd", "Ethernet", $type); - $type = str_replace("l2vlan", "Ethernet VLAN", $type); - + $type = str_replace("l2vlan", "Ethernet VLAN", $type); return ($type); - } function fixifName ($inf) { @@ -400,7 +437,6 @@ function fixIOSHardware($hardware){ $hardware = str_replace("C3200XL", "Cisco Catalyst 3200XL", $hardware); $hardware = str_replace("C3550", "Cisco Catalyst 3550", $hardware); $hardware = str_replace("C2950", "Cisco Catalyst 2950", $hardware); - return $hardware; } diff --git a/mysql-schema.sql b/mysql-schema.sql index fb05099b95..6d7c1fdbcc 100644 --- a/mysql-schema.sql +++ b/mysql-schema.sql @@ -1,37 +1,22 @@ --- MySQL dump 10.10 --- --- Host: localhost Database: vostron_network --- ------------------------------------------------------ --- Server version 5.0.22-Debian_0ubuntu6.06.2-log +-- -------------------------------------------------------- -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- +-- -- Table structure for table `adjacencies` --- +-- -DROP TABLE IF EXISTS `adjacencies`; CREATE TABLE `adjacencies` ( `adj_id` int(11) NOT NULL auto_increment, `network_id` int(11) NOT NULL default '0', `interface_id` int(11) NOT NULL default '0', PRIMARY KEY (`adj_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `alerts` --- +-- -DROP TABLE IF EXISTS `alerts`; CREATE TABLE `alerts` ( `id` int(11) NOT NULL auto_increment, `importance` int(11) NOT NULL default '0', @@ -40,37 +25,30 @@ CREATE TABLE `alerts` ( `time_logged` timestamp NOT NULL default CURRENT_TIMESTAMP, `alerted` smallint(6) NOT NULL default '0', KEY `id` (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `customers` --- +-- -DROP TABLE IF EXISTS `customers`; CREATE TABLE `customers` ( + `customer_id` int(11) NOT NULL auto_increment, `username` char(64) NOT NULL, `password` char(32) NOT NULL, `string` char(64) NOT NULL, `level` tinyint(4) NOT NULL default '0', + PRIMARY KEY (`customer_id`), UNIQUE KEY `username` (`username`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- --- Table structure for table `device_uptime` --- +-- -------------------------------------------------------- -DROP TABLE IF EXISTS `device_uptime`; -CREATE TABLE `device_uptime` ( - `device_id` int(11) NOT NULL default '0', - `device_uptime` int(11) NOT NULL default '0', - UNIQUE KEY `device_id` (`device_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - --- +-- -- Table structure for table `devices` --- +-- -DROP TABLE IF EXISTS `devices`; CREATE TABLE `devices` ( `device_id` int(11) NOT NULL auto_increment, `hostname` text NOT NULL, @@ -93,26 +71,39 @@ CREATE TABLE `devices` ( `postfix` tinyint(4) NOT NULL default '0', `type` varchar(8) NOT NULL default 'other', PRIMARY KEY (`device_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `devices_attribs` --- +-- -DROP TABLE IF EXISTS `devices_attribs`; CREATE TABLE `devices_attribs` ( `attrib_id` int(11) NOT NULL auto_increment, `device_id` int(11) NOT NULL, `attrib_type` varchar(32) NOT NULL, `attrib_value` varchar(256) NOT NULL, PRIMARY KEY (`attrib_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `devices_perms` +-- + +CREATE TABLE `devices_perms` ( + `user_id` int(11) NOT NULL, + `device_id` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; --- --- Table structure for table `eventlog` --- +-- -------------------------------------------------------- + +-- +-- Table structure for table `eventlog` +-- -DROP TABLE IF EXISTS `eventlog`; CREATE TABLE `eventlog` ( `id` int(11) NOT NULL default '0', `host` int(11) NOT NULL default '0', @@ -123,11 +114,28 @@ CREATE TABLE `eventlog` ( KEY `host` (`host`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; --- --- Table structure for table `interfaces` --- +-- -------------------------------------------------------- + +-- +-- Table structure for table `interface_measurements` +-- + +CREATE TABLE `interface_measurements` ( + `interface_id` int(11) NOT NULL, + `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, + `period` int(11) NOT NULL, + `delta_in` int(11) NOT NULL, + `delta_out` int(11) NOT NULL, + `rate_in` int(11) NOT NULL, + `rate_out` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `interfaces` +-- -DROP TABLE IF EXISTS `interfaces`; CREATE TABLE `interfaces` ( `interface_id` int(11) NOT NULL auto_increment, `device_id` int(11) NOT NULL default '0', @@ -145,18 +153,26 @@ CREATE TABLE `interfaces` ( `ifLastChange` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `ifVlan` int(11) default NULL, `ifTrunk` varchar(8) default '', + `in_rate` int(11) NOT NULL, + `out_rate` int(11) NOT NULL, + `counter_in` int(11) default NULL, + `counter_out` int(11) default NULL, + `in_errors` int(11) NOT NULL, + `out_errors` int(11) NOT NULL, `ignore` tinyint(1) NOT NULL default '0', + `detailed` tinyint(1) NOT NULL default '0', PRIMARY KEY (`interface_id`), KEY `host` (`device_id`), KEY `snmpid` (`ifIndex`), KEY `if_2` (`ifDescr`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `ipaddr` --- +-- -DROP TABLE IF EXISTS `ipaddr`; CREATE TABLE `ipaddr` ( `id` int(11) NOT NULL auto_increment, `addr` varchar(32) NOT NULL default '', @@ -165,13 +181,14 @@ CREATE TABLE `ipaddr` ( `interface_id` int(11) NOT NULL default '0', PRIMARY KEY (`id`), KEY `addr` (`addr`,`cidr`,`interface_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `links` --- +-- -DROP TABLE IF EXISTS `links`; CREATE TABLE `links` ( `id` int(11) NOT NULL auto_increment, `src_if` int(11) default NULL, @@ -179,13 +196,14 @@ CREATE TABLE `links` ( `active` tinyint(4) NOT NULL default '1', `cdp` int(11) default NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `logs` --- +-- -DROP TABLE IF EXISTS `logs`; CREATE TABLE `logs` ( `host` varchar(32) default NULL, `facility` varchar(10) default NULL, @@ -193,7 +211,7 @@ CREATE TABLE `logs` ( `level` varchar(10) default NULL, `tag` varchar(10) default NULL, `datetime` datetime default NULL, - `program` varchar(15) default NULL, + `program` varchar(32) default NULL, `msg` text, `seq` bigint(20) unsigned NOT NULL auto_increment, PRIMARY KEY (`seq`), @@ -201,27 +219,30 @@ CREATE TABLE `logs` ( KEY `program` (`program`), KEY `datetime` (`datetime`), KEY `priority` (`priority`), - KEY `facility` (`facility`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; + KEY `facility` (`facility`), + KEY `seq` (`seq`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `networks` --- +-- -DROP TABLE IF EXISTS `networks`; CREATE TABLE `networks` ( `id` int(11) NOT NULL auto_increment, `cidr` varchar(32) NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `cidr_2` (`cidr`), FULLTEXT KEY `cidr` (`cidr`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `services` --- +-- -DROP TABLE IF EXISTS `services`; CREATE TABLE `services` ( `service_id` int(11) NOT NULL auto_increment, `service_host` int(11) NOT NULL, @@ -236,13 +257,14 @@ CREATE TABLE `services` ( `service_message` text NOT NULL, PRIMARY KEY (`service_id`), KEY `service_host` (`service_host`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `storage` --- +-- -DROP TABLE IF EXISTS `storage`; CREATE TABLE `storage` ( `storage_id` int(11) NOT NULL auto_increment, `host_id` int(11) NOT NULL, @@ -250,22 +272,25 @@ CREATE TABLE `storage` ( `hrStorageDescr` text NOT NULL, `hrStorageSize` int(11) NOT NULL, `hrStorageAllocationUnits` int(11) NOT NULL, + `hrStorageUsed` int(11) NOT NULL, + `storage_perc` text NOT NULL, PRIMARY KEY (`storage_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `syslog` --- +-- -DROP TABLE IF EXISTS `syslog`; CREATE TABLE `syslog` ( - `host` varchar(32) default NULL, + `host` int(11) default NULL, `facility` varchar(10) default NULL, `priority` varchar(10) default NULL, `level` varchar(10) default NULL, `tag` varchar(10) default NULL, `datetime` datetime default NULL, - `program` varchar(20) default NULL, + `program` varchar(32) default NULL, `msg` text, `seq` bigint(20) unsigned NOT NULL auto_increment, PRIMARY KEY (`seq`), @@ -273,42 +298,49 @@ CREATE TABLE `syslog` ( KEY `program` (`program`), KEY `datetime` (`datetime`), KEY `priority` (`priority`), - KEY `facility` (`facility`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; + KEY `facility` (`facility`), + KEY `seq` (`seq`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `temperature` --- +-- -DROP TABLE IF EXISTS `temperature`; CREATE TABLE `temperature` ( `temp_id` int(11) NOT NULL auto_increment, `temp_host` int(11) NOT NULL default '0', - `temp_oid` varchar(32) NOT NULL default '', + `temp_oid` varchar(64) NOT NULL, `temp_descr` varchar(32) NOT NULL default '', + `temp_tenths` int(1) NOT NULL default '0', `temp_current` tinyint(4) NOT NULL default '0', `temp_limit` tinyint(4) NOT NULL default '70', PRIMARY KEY (`temp_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `users` --- +-- -DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( + `user_id` int(11) NOT NULL auto_increment, `username` char(30) NOT NULL, `password` char(32) NOT NULL, `descr` char(30) NOT NULL, `level` tinyint(4) NOT NULL default '0', + PRIMARY KEY (`user_id`), UNIQUE KEY `username` (`username`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; --- +-- -------------------------------------------------------- + +-- -- Table structure for table `vlans` --- +-- -DROP TABLE IF EXISTS `vlans`; CREATE TABLE `vlans` ( `vlan_id` int(11) NOT NULL auto_increment, `device_id` int(11) default NULL, @@ -317,14 +349,5 @@ CREATE TABLE `vlans` ( `vlan_descr` text, PRIMARY KEY (`vlan_id`), KEY `device_id` (`device_id`,`vlan_vlan`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; diff --git a/poll-device.php b/poll-device.php index 0392ded44b..461dfd56e9 100755 --- a/poll-device.php +++ b/poll-device.php @@ -192,7 +192,14 @@ while ($device = mysql_fetch_array($device_query)) { if ($uptime) { - echo("Uptime : $uptime\n"); + + + $old_uptime = mysql_result(mysql_query("SELECT `attrib_value` FROM `devices_attribs` WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'"), 0); + + if( $uptime < $old_uptime ) { + mail($notify_email, "Rebooted: " . $device['hostname'], "Device " . $device['hostname'] . " rebooted at " . date('l dS F Y h:i:s A')); + } + $uptimerrd = "rrd/" . $device['hostname'] . "-uptime.rrd"; if(!is_file($uptimerrd)) { @@ -209,6 +216,7 @@ while ($device = mysql_fetch_array($device_query)) { if(mysql_affected_rows() == '0') { $insert_uptime_attrib = mysql_query("INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . $device['device_id'] . "', 'uptime', '$uptime')"); } + } diff --git a/poll-interface.php b/poll-interface.php index f8865fd28e..345e251845 100755 --- a/poll-interface.php +++ b/poll-interface.php @@ -10,6 +10,11 @@ $interface_query = mysql_query("SELECT * FROM `interfaces` $where"); while ($interface = mysql_fetch_array($interface_query)) { $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_id = '" . $interface['device_id'] . "'")); + unset($ifAdminStatus, $ifOperStatus, $ifAlias, $ifDescr); + + $interface['hostname'] = $device['hostname']; + $interface['device_id'] = $device['device_id']; + if($device['status'] == '1') { unset($update); @@ -105,29 +110,36 @@ while ($interface = mysql_fetch_array($interface_query)) { echo("Interface " . $device['hostname'] . " " . $interface['ifDescr'] . " is down\n"); } } + + $rates = interface_rates ($interface); + mysql_query("UPDATE `interfaces` SET in_rate = '" . $rates['in'] . "', out_rate = '" . $rates['out'] . "' WHERE interface_id= '" . $interface['interface_id'] . "'"); - 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 ($update) { - $update_query = "UPDATE `interfaces` SET "; - $update_query .= $update; - $update_query .= " WHERE `interface_id` = '" . $interface['interface_id'] . "'"; - $update_result = mysql_query($update_query); - } + + + + +# 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 ($update) { +# $update_query = "UPDATE `interfaces` SET "; +# $update_query .= $update; +# $update_query .= " WHERE `interface_id` = '" . $interface['interface_id'] . "'"; +# $update_result = mysql_query($update_query); +# } } diff --git a/process-syslog.php b/process-syslog.php index 2b80702888..9ddaab11fa 100755 --- a/process-syslog.php +++ b/process-syslog.php @@ -4,11 +4,12 @@ include("config.php"); include("includes/functions.php"); +if(!$enable_syslog) { exit(); } + $add = 0; $discard = 0; $total = 0; - mysql_query("DELETE FROM `logs` WHERE `msg` LIKE '%Connection from UDP: [89.21.224.44]:%'"); mysql_query("DELETE FROM `logs` WHERE `msg` LIKE '%Connection from UDP: [89.21.224.35]:%'"); @@ -26,7 +27,7 @@ while($l = mysql_fetch_array($q)){ $host = $maybehost; } elseif($perhapshost) { $host = $perhapshost; - } + } else { `echo Failed log entry from $l[host] > /var/log/observer.log`; } if($host) { @@ -36,13 +37,10 @@ while($l = mysql_fetch_array($q)){ $l[msg] = preg_replace("/^%(.+):\ /", "\\1||", $l[msg]); list($l[program], $l[msg]) = explode("||", $l[msg]); } else { - $l[msg] = preg_replace("/^" . $l[program] . ":\ /", "", $l[msg]); - } - $x = "INSERT INTO syslog (`host` , `facility` , `priority` , `level` , `tag` , `datetime` , `program` , `msg` )"; $x .= " VALUES ( '$host', '$l[facility]', '$l[priority]', '$l[level]', '$l[tag]', '$l[datetime]', '$l[program]', '$l[msg]' );";