diff --git a/README b/README index 95d4905672..bcb0c30eb6 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ Please see COPYING for usage requirements and restrictions. Introduction ------------ -Observium is an auto-discovering network monitoring system. +Observium is an auto-discovering network monitoring system. It's designed to be an easily-navigable interface to the health of your network. diff --git a/check-services.php b/check-services.php index 24fb540e26..bbccd16584 100755 --- a/check-services.php +++ b/check-services.php @@ -3,57 +3,66 @@ include("includes/defaults.inc.php"); include("config.php"); include("includes/functions.php"); - + $sql = "SELECT * FROM devices AS D, services AS S WHERE S.device_id = D.device_id ORDER by D.device_id DESC"; $query = mysql_query($sql); -while ($service = mysql_fetch_array($query)) { +while ($service = mysql_fetch_array($query)) +{ + if ($service['status'] = "1") + { + unset($check, $service_status, $time, $status); + $service_status = $service['service_status']; + $service_type = strtolower($service['service_type']); + $service_param = $service['service_param']; + $checker_script = $config['install_dir'] . "/includes/services/" . $service_type . "/check.inc"; - if($service['status'] = "1") { - unset($check, $service_status, $time, $status); - $service_status = $service['service_status']; - $service_type = strtolower($service['service_type']); - $service_param = $service['service_param']; - $checker_script = $config['install_dir'] . "/includes/services/" . $service_type . "/check.inc"; - if(is_file($checker_script)) { - include($checker_script); - } else { - $status = "2"; - $check = "Error : Script not found ($checker_script)"; - } - if($service_status != $status) { - $updated = ", `service_changed` = '" . time() . "' "; - if($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; } - if($status == "1") { + if (is_file($checker_script)) + { + include($checker_script); + } + else + { + $status = "2"; + $check = "Error : Script not found ($checker_script)"; + } + + if ($service_status != $status) + { + $updated = ", `service_changed` = '" . time() . "' "; + if ($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; } + if ($status == "1") + { $msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname']; $msg .= " at " . date($config['timestamp_format']); notify($device, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg); - } elseif ($status == "0") { - $msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname']; + } + elseif ($status == "0") + { + $msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname']; $msg .= " at " . date($config['timestamp_format']); notify($device, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg); - } + } + } else { unset($updated); } + + $update_sql = "UPDATE `services` SET `service_status` = '$status', `service_message` = '" . addslashes($check) . "', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '" . $service['service_id']. "'"; + mysql_query($update_sql); + } else { + $status = "0"; + } - } else { unset($updated); } - $update_sql = "UPDATE `services` SET `service_status` = '$status', `service_message` = '" . addslashes($check) . "', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '" . $service['service_id']. "'"; - mysql_query($update_sql); - } else { - $status = "0"; - } - - $rrd = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename("service-" . $service['service_type'] . "-" . $service['service_id'] . ".rrd"); - if (!is_file($rrd)) { - $create = $config['rrdtool'] . " create $rrd \ - --step 300 \ + if (!is_file($rrd)) + { + rrdtool_create($rrd,"--step 300 \ DS:status:GAUGE:600:0:1 \ RRA:AVERAGE:0.5:1:1200 \ - RRA:AVERAGE:0.5:12:2400"; - shell_exec($create); + RRA:AVERAGE:0.5:12:2400"); } - if($status == "1" || $status == "0") { + if ($status == "1" || $status == "0") + { rrdtool_update($rrd,"N:".$status); } -} +} # while ?> diff --git a/html/includes/authentication/http-auth.inc.php b/html/includes/authentication/http-auth.inc.php index d417fdd29a..35c32c4658 100644 --- a/html/includes/authentication/http-auth.inc.php +++ b/html/includes/authentication/http-auth.inc.php @@ -4,18 +4,18 @@ function authenticate($username,$password) { global $config; - if(isset($_SERVER['REMOTE_USER'])) + if(isset($_SERVER['REMOTE_USER'])) { $_SESSION['username'] = mres($_SERVER['REMOTE_USER']); - + $sql = "SELECT username FROM `users` WHERE `username`='".$_SESSION['username'] . "'";; $query = mysql_query($sql); $row = @mysql_fetch_array($query); - if($row['username'] && $row['username'] == $_SESSION['username']) + if($row['username'] && $row['username'] == $_SESSION['username']) { return 1; - } - else + } + else { $_SESSION['username'] = $config['http_auth_guest']; return 1; @@ -33,19 +33,19 @@ function changepassword($username,$newpassword) { # Not supported } - + function auth_usermanagement() { return 1; } - + function adduser($username, $password, $level, $email = "", $realname = "") { mysql_query("INSERT INTO `users` (`username`,`password`,`level`, `email`, `realname`) VALUES ('".mres($username)."',MD5('".mres($password)."'),'".mres($level)."','".mres($email)."','".mres($realname)."')"); - + return mysql_affected_rows(); } - + function user_exists($username) { return mysql_result(mysql_query("SELECT * FROM users WHERE username = '".mres($username)."'"),0); diff --git a/html/includes/authentication/ldap.inc.php b/html/includes/authentication/ldap.inc.php index cb178e3f44..597c76ed88 100644 --- a/html/includes/authentication/ldap.inc.php +++ b/html/includes/authentication/ldap.inc.php @@ -58,12 +58,12 @@ function adduser($username, $password, $level, $email = "", $realname = "") # Not supported return 0; } - + function user_exists($username) { return 0; # FIXME to be implemented } - + function get_userlevel($username) { # FIXME should come from LDAP diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php index 151b94510e..9885c45fb3 100644 --- a/html/includes/authentication/mysql.inc.php +++ b/html/includes/authentication/mysql.inc.php @@ -6,7 +6,7 @@ function authenticate($username,$password) $sql = "SELECT username FROM `users` WHERE `username`='".$username."' AND `password`='".$encrypted."'"; $query = mysql_query($sql); $row = @mysql_fetch_array($query); - if($row['username'] && $row['username'] == $username) + if($row['username'] && $row['username'] == $username) { return 1; } @@ -29,11 +29,11 @@ function auth_usermanagement() { return 1; } - + function adduser($username, $password, $level, $email = "", $realname = "") { mysql_query("INSERT INTO `users` (`username`,`password`,`level`, `email`, `realname`) VALUES ('".mres($username)."',MD5('".mres($password)."'),'".mres($level)."','".mres($email)."','".mres($realname)."')"); - + return mysql_affected_rows(); } @@ -41,19 +41,19 @@ function user_exists($username) { return mysql_result(mysql_query("SELECT * FROM users WHERE username = '".mres($username)."'"),0); } - + function get_userlevel($username) { $sql = "SELECT level FROM `users` WHERE `username`='".mres($username)."'"; $row = mysql_fetch_array(mysql_query($sql)); return $row['level']; } - + function get_userid($username) { $sql = "SELECT user_id FROM `users` WHERE `username`='".mres($username)."'"; $row = mysql_fetch_array(mysql_query($sql)); return $row['user_id']; } - + ?> diff --git a/html/includes/graphs/device/bits.inc.php b/html/includes/graphs/device/bits.inc.php index 9a5b638d82..0363233a9b 100644 --- a/html/includes/graphs/device/bits.inc.php +++ b/html/includes/graphs/device/bits.inc.php @@ -5,31 +5,40 @@ $device = device_by_id_cache($id); $query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$id."'"); -while($int = mysql_fetch_assoc($query)) { +while ($int = mysql_fetch_assoc($query)) +{ $ignore = 0; - if(is_array($config['device_traffic_iftype'])) { - foreach($config['device_traffic_iftype'] as $iftype) { - if (preg_match($iftype ."i", $int['ifType'])) { + if (is_array($config['device_traffic_iftype'])) + { + foreach ($config['device_traffic_iftype'] as $iftype) + { + if (preg_match($iftype ."i", $int['ifType'])) + { $ignore = 1; - } + } } } - if(is_array($config['device_traffic_descr'])) { - foreach($config['device_traffic_descr'] as $ifdescr) { - if (preg_match($ifdescr."i", $int['ifDescr']) || preg_match($ifdescr."i", $int['ifName']) || preg_match($ifdescr."i", $int['portName'])) { + if (is_array($config['device_traffic_descr'])) + { + foreach ($config['device_traffic_descr'] as $ifdescr) + { + if (preg_match($ifdescr."i", $int['ifDescr']) || preg_match($ifdescr."i", $int['ifName']) || preg_match($ifdescr."i", $int['portName'])) + { $ignore = 1; } } } - if(is_file($config['rrd_dir'] . "/" . $device['hostname'] . "/port-" . safename($int['ifIndex'] . ".rrd")) && $ignore != 1) { + if (is_file($config['rrd_dir'] . "/" . $device['hostname'] . "/port-" . safename($int['ifIndex'] . ".rrd")) && $ignore != 1) + { $rrd_filenames[] = $config['rrd_dir'] . "/" . $device['hostname'] . "/port-" . safename($int['ifIndex'] . ".rrd"); } + unset($ignore); } $rra_in = "INOCTETS"; -$rra_out = "OUTOCTETS"; +$rra_out = "OUTOCTETS"; $colour_line_in = "006600"; $colour_line_out = "000099"; @@ -38,4 +47,4 @@ $colour_area_out = "C3D9FF"; include ("includes/graphs/generic_multi_bits.inc.php"); -?> +?> \ No newline at end of file diff --git a/html/includes/graphs/device/current.inc.php b/html/includes/graphs/device/current.inc.php index ba115bb28e..ac720dffa4 100644 --- a/html/includes/graphs/device/current.inc.php +++ b/html/includes/graphs/device/current.inc.php @@ -8,37 +8,37 @@ $rrd_options .= " -l 0 -E "; $iter = "1"; $sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='current' AND device_id = '$id'"); $rrd_options .= " COMMENT:' Cur Min Max\\n'"; -while($current = mysql_fetch_array($sql)) +while($current = mysql_fetch_array($sql)) { switch ($iter) { case "1": - $colour= "CC0000"; - break; + $colour= "CC0000"; + break; case "2": - $colour= "008C00"; - break; + $colour= "008C00"; + break; case "3": - $colour= "4096EE"; - break; + $colour= "4096EE"; + break; case "4": - $colour= "73880A"; + $colour= "73880A"; break; case "5": - $colour= "D01F3C"; + $colour= "D01F3C"; break; case "6": - $colour= "36393D"; - break; - case "7": + $colour= "36393D"; + break; + case "7": default: - $colour= "FF0084"; + $colour= "FF0084"; unset($iter); break; } $hostname = gethostbyid($current['device_id']); - + $descr = substr(str_pad($current['sensor_descr'], 15),0,15); $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("current-" . $current['sensor_descr'] . ".rrd"); diff --git a/html/includes/graphs/device/fanspeeds.inc.php b/html/includes/graphs/device/fanspeeds.inc.php index 05758be16d..2385689858 100644 --- a/html/includes/graphs/device/fanspeeds.inc.php +++ b/html/includes/graphs/device/fanspeeds.inc.php @@ -9,31 +9,31 @@ $rrd_options .= " -l 0 -E "; $iter = "1"; $sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '$id'"); $rrd_options .= " COMMENT:'RPM Cur Min Max\\n'"; -while($fanspeed = mysql_fetch_array($sql)) +while($fanspeed = mysql_fetch_array($sql)) { switch ($iter) { case "1": - $colour= "CC0000"; - break; + $colour= "CC0000"; + break; case "2": - $colour= "008C00"; - break; + $colour= "008C00"; + break; case "3": - $colour= "4096EE"; - break; + $colour= "4096EE"; + break; case "4": - $colour= "73880A"; + $colour= "73880A"; break; case "5": - $colour= "D01F3C"; + $colour= "D01F3C"; break; case "6": - $colour= "36393D"; - break; - case "7": + $colour= "36393D"; + break; + case "7": default: - $colour= "FF0084"; + $colour= "FF0084"; unset($iter); break; } diff --git a/html/includes/graphs/device/frequencies.inc.php b/html/includes/graphs/device/frequencies.inc.php index e7a4ea21f1..357bc58502 100644 --- a/html/includes/graphs/device/frequencies.inc.php +++ b/html/includes/graphs/device/frequencies.inc.php @@ -8,37 +8,37 @@ $rrd_options .= " -l 0 -E "; $iter = "1"; $sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='freq' AND device_id = '$id'"); $rrd_options .= " COMMENT:' Cur Min Max\\n'"; -while($frequency = mysql_fetch_array($sql)) +while($frequency = mysql_fetch_array($sql)) { switch ($iter) { case "1": - $colour= "CC0000"; - break; + $colour= "CC0000"; + break; case "2": - $colour= "008C00"; - break; + $colour= "008C00"; + break; case "3": - $colour= "4096EE"; - break; + $colour= "4096EE"; + break; case "4": - $colour= "73880A"; + $colour= "73880A"; break; case "5": - $colour= "D01F3C"; + $colour= "D01F3C"; break; case "6": - $colour= "36393D"; - break; - case "7": + $colour= "36393D"; + break; + case "7": default: - $colour= "FF0084"; + $colour= "FF0084"; unset($iter); break; } $hostname = gethostbyid($frequency['device_id']); - + $descr = substr(str_pad($frequency['sensor_descr'], 15),0,15); $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("freq-" . $frequency['sensor_descr'] . ".rrd"); $sensor_id = $frequency['sensor_id']; diff --git a/html/includes/graphs/device/humidity.inc.php b/html/includes/graphs/device/humidity.inc.php index 1544dd6b04..735cb3e541 100644 --- a/html/includes/graphs/device/humidity.inc.php +++ b/html/includes/graphs/device/humidity.inc.php @@ -8,35 +8,35 @@ $rrd_options .= " -l 0 -E "; $iter = "1"; $sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='humidity' AND device_id = '$id' ORDER BY sensor_index"); $rrd_options .= " COMMENT:' Cur Min Max\\n'"; -while($humidity = mysql_fetch_array($sql)) +while($humidity = mysql_fetch_array($sql)) { switch ($iter) { case "1": - $colour= "CC0000"; - break; + $colour= "CC0000"; + break; case "2": - $colour= "008C00"; - break; + $colour= "008C00"; + break; case "3": - $colour= "4096EE"; - break; + $colour= "4096EE"; + break; case "4": - $colour= "73880A"; + $colour= "73880A"; break; case "5": - $colour= "D01F3C"; + $colour= "D01F3C"; break; case "6": - $colour= "36393D"; - break; - case "7": + $colour= "36393D"; + break; + case "7": default: - $colour= "FF0084"; + $colour= "FF0084"; unset($iter); break; } - + $humidity['sensor_descr_fixed'] = substr(str_pad($humidity['sensor_descr'], 22),0,22); $humidityrrd = $config['rrd_dir'] . "/".$device['hostname']."/".safename("humidity-" . safename($humidity['sensor_type']."-".$humidity['sensor_index']) . ".rrd"); $rrd_options .= " DEF:sensor" . $humidity['sensor_id'] . "=$humidityrrd:sensor:AVERAGE "; diff --git a/html/includes/graphs/device/temperatures.inc.php b/html/includes/graphs/device/temperatures.inc.php index eae9759eab..fe5d93962d 100644 --- a/html/includes/graphs/device/temperatures.inc.php +++ b/html/includes/graphs/device/temperatures.inc.php @@ -9,35 +9,35 @@ $rrd_options .= " -l 0 -E "; $iter = "1"; $sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='temperature' AND device_id = '$id' ORDER BY sensor_index"); $rrd_options .= " COMMENT:'".str_pad('',$descr_len)." Cur Min Max\\n'"; -while($temperature = mysql_fetch_array($sql)) +while($temperature = mysql_fetch_array($sql)) { switch ($iter) { case "1": - $colour= "CC0000"; - break; + $colour= "CC0000"; + break; case "2": - $colour= "008C00"; - break; + $colour= "008C00"; + break; case "3": - $colour= "4096EE"; - break; + $colour= "4096EE"; + break; case "4": - $colour= "73880A"; + $colour= "73880A"; break; case "5": - $colour= "D01F3C"; + $colour= "D01F3C"; break; case "6": - $colour= "36393D"; - break; - case "7": + $colour= "36393D"; + break; + case "7": default: - $colour= "FF0084"; + $colour= "FF0084"; unset($iter); break; } - + $temperature['sensor_descr_fixed'] = substr(str_pad($temperature['sensor_descr'], $descr_len),0,$descr_len); $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/temperature-" . safename($temperature['sensor_type']."-".$temperature['sensor_index']) . ".rrd"; $rrd_options .= " DEF:sensor" . $temperature['sensor_id'] . "=$rrd_file:sensor:AVERAGE "; diff --git a/html/includes/graphs/device/toner.inc.php b/html/includes/graphs/device/toner.inc.php index f5098a82b1..755b68ce21 100644 --- a/html/includes/graphs/device/toner.inc.php +++ b/html/includes/graphs/device/toner.inc.php @@ -8,41 +8,42 @@ $rrd_options .= " -l 0 -E "; $iter = "1"; $sql = mysql_query("SELECT * FROM toner where device_id = '$id'"); $rrd_options .= " COMMENT:'Toner level Cur Min Max\\n'"; -while($toner = mysql_fetch_array($sql)) +while($toner = mysql_fetch_array($sql)) { switch ($iter) { case "1": - $colour= "000000"; - break; + $colour= "000000"; + break; case "2": - $colour= "008C00"; - break; + $colour= "008C00"; + break; case "3": - $colour= "4096EE"; - break; + $colour= "4096EE"; + break; case "4": - $colour= "73880A"; + $colour= "73880A"; break; case "5": - $colour= "D01F3C"; + $colour= "D01F3C"; break; case "6": - $colour= "36393D"; - break; - case "7": + $colour= "36393D"; + break; + case "7": default: - $colour= "FF0000"; + $colour= "FF0000"; unset($iter); break; } + if (stripos($toner['toner_descr'],"cyan" ) !== false || substr($toner['toner_descr'],-1) == 'C') { $colour = "55D6D3"; } if (stripos($toner['toner_descr'],"magenta") !== false || substr($toner['toner_descr'],-1) == 'M') { $colour = "F24AC8"; } if (stripos($toner['toner_descr'],"yellow" ) !== false || substr($toner['toner_descr'],-1) == 'Y') { $colour = "FFF200"; } if (stripos($toner['toner_descr'],"black" ) !== false || substr($toner['toner_descr'],-1) == 'K') { $colour = "000000"; } - + $hostname = gethostbyid($toner['device_id']); - + $descr = substr(str_pad($toner['toner_descr'], 16),0,16); $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("toner-" . $toner['toner_descr'] . ".rrd"); $toner_id = $toner['toner_id']; @@ -56,5 +57,4 @@ while($toner = mysql_fetch_array($sql)) $iter++; } - ?> diff --git a/html/includes/graphs/device/voltages.inc.php b/html/includes/graphs/device/voltages.inc.php index d2d7a9c1b8..db1b08fd47 100644 --- a/html/includes/graphs/device/voltages.inc.php +++ b/html/includes/graphs/device/voltages.inc.php @@ -10,36 +10,36 @@ $rrd_options .= " COMMENT:'".str_pad('',$descr_len)." Cur Min Max\\ $iter = "1"; $sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='voltage' AND device_id = '$id'"); -while($sensor = mysql_fetch_array($sql)) +while($sensor = mysql_fetch_array($sql)) { switch ($iter) { case "1": - $colour= "CC0000"; - break; + $colour= "CC0000"; + break; case "2": - $colour= "008C00"; - break; + $colour= "008C00"; + break; case "3": - $colour= "4096EE"; - break; + $colour= "4096EE"; + break; case "4": - $colour= "73880A"; + $colour= "73880A"; break; case "5": - $colour= "D01F3C"; + $colour= "D01F3C"; break; case "6": - $colour= "36393D"; - break; - case "7": + $colour= "36393D"; + break; + case "7": default: - $colour= "FF0084"; + $colour= "FF0084"; unset($iter); break; } - + $sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], $descr_len),0,$descr_len); $sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed'])); diff --git a/html/includes/graphs/generic_multi_seperated.inc.php b/html/includes/graphs/generic_multi_seperated.inc.php index 0e28fbabc2..363b3d242d 100644 --- a/html/includes/graphs/generic_multi_seperated.inc.php +++ b/html/includes/graphs/generic_multi_seperated.inc.php @@ -1,54 +1,60 @@ diff --git a/html/includes/hostbox.inc b/html/includes/hostbox.inc.php similarity index 100% rename from html/includes/hostbox.inc rename to html/includes/hostbox.inc.php diff --git a/html/includes/ifbox.inc b/html/includes/ifbox.inc index d5f57cba4c..73948f0e11 100644 --- a/html/includes/ifbox.inc +++ b/html/includes/ifbox.inc @@ -1,22 +1,32 @@ $inf
"); - if($ifalias && $ifalias != "") { echo("$ifalias$inf
"); + +if (isset($ifalias) && $ifalias != "") { echo(''.$ifalias.'