notify() test + indent cleanup + html cleanup

git-svn-id: http://www.observium.org/svn/observer/trunk@677 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans 2010-01-13 15:54:03 +00:00
parent 507b1fbc18
commit c9bd48c9d2
2 changed files with 46 additions and 38 deletions

View File

@ -336,17 +336,17 @@ function devclass($device)
function getImage($host)
{
global $config;
$sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'";
$data = mysql_fetch_array(mysql_query($sql));
$type = strtolower($data['os']);
if(file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = "<img src='".$config['base_url']."/images/os/$type.png' />";
} elseif(file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = "<img src='".$config['base_url']."/images/os/$type.gif' />"; }
global $config;
$sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'";
$data = mysql_fetch_array(mysql_query($sql));
$type = strtolower($data['os']);
if(file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$type.'.png" />';
} elseif(file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$type.'.gif" />'; }
if($type == "linux") {
$features = strtolower(trim($data['features']));
list($distro) = split(" ", $features);
if(file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = "<img src='".$config['base_url']."/images/os/$distro" . ".png' />";
} elseif(file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = "<img src='".$config['base_url']."/images/os/$distro" . ".gif' />"; }
if(file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$distro.'.png" />';
} elseif(file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$distro.'.gif" />'; }
}
return $image;
}
@ -483,8 +483,7 @@ function netmask2cidr($netmask)
function cidr2netmask()
{
return (long2ip(ip2long("255.255.255.255")
<< (32-$netmask)));
return (long2ip(ip2long("255.255.255.255") << (32-$netmask)));
}
function formatUptime($diff, $format="long")
@ -522,11 +521,10 @@ function isSNMPable($hostname, $community, $snmpver, $port)
global $config;
$pos = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysDescr.0");
if($pos == '') {
$status='0';
return false;
} else {
$status='1';
return true;
}
return $status;
}
function isPingable($hostname) {
@ -570,7 +568,8 @@ function ifclass($ifOperStatus, $ifAdminStatus)
return $ifclass;
}
function utime() {
function utime()
{
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
@ -645,11 +644,13 @@ function createHost ($host, $community, $snmpver, $port = 161){
}
}
function isDomainResolves($domain){
function isDomainResolves($domain)
{
return gethostbyname($domain) != $domain;
}
function hoststatus($id) {
function hoststatus($id)
{
$sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
@ -762,4 +763,12 @@ function eventlog($eventtext,$device_id = "", $interface_id = "")
mysql_query($event_query);
}
function notify($device,$title,$message)
{
global $config;
if ($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
mail($email, $title, $message, $config['email_headers']);
}
?>

View File

@ -157,8 +157,7 @@ while ($device = mysql_fetch_array($device_query)) {
if ($uptime)
{
if ( $uptime < $device['uptime'] ) {
if ($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
mail($email, "Device Rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.", $config['email_headers']);
notify($device,"Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.");
eventlog('Device rebooted', $device['device_id']);
}