diff --git a/check-services.php b/check-services.php index 73b160ddc..65d02fae7 100755 --- a/check-services.php +++ b/check-services.php @@ -3,7 +3,7 @@ include("config.php"); include("includes/functions.php"); -$sql = "SELECT * FROM devices AS D, services AS S WHERE D.status = '1' AND S.service_host = D.device_id ORDER by D.device_id DESC"; +$sql = "SELECT * FROM devices AS D, services AS S WHERE D.status = '1' AND S.device_id = D.device_id ORDER by D.device_id DESC"; $query = mysql_query($sql); while ($service = mysql_fetch_array($query)) { @@ -34,6 +34,19 @@ while ($service = mysql_fetch_array($query)) { } 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); -# echo("$update_sql " . mysql_affected_rows() . " rows updated\n"); + + $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 \ + DS:status:GAUGE:600:0:1 \ + RRA:AVERAGE:0.5:1:1200 \ + RRA:AVERAGE:0.5:12:2400"; + shell_exec($create); + } + + rrdtool_update($rrd,"N:".$status); + } ?> diff --git a/database-update.sql b/database-update.sql index 13e7b4a72..74e946c7e 100644 --- a/database-update.sql +++ b/database-update.sql @@ -109,3 +109,4 @@ RENAME TABLE `interfaces_perms` TO `ports_perms` ; ALTER TABLE `temperature` CHANGE `temp_index` `temp_index` VARCHAR( 32 ) NOT NULL AFTER `device_id` , ADD `temp_type` VARCHAR( 16 ) NOT NULL AFTER `temp_index`; ALTER TABLE `processors` CHANGE `processor_oid` `processor_oid` VARCHAR( 128 ) NOT NULL ALTER TABLE eventlog CHANGE `type` `type` VARCHAR( 64 ) NOT NULL; +ALTER TABLE `services` CHANGE `service_host` `device_id` INT( 11 ) NOT NULL diff --git a/html/includes/graphs/service.inc.php b/html/includes/graphs/service.inc.php new file mode 100755 index 000000000..f3ce84b97 --- /dev/null +++ b/html/includes/graphs/service.inc.php @@ -0,0 +1,29 @@ + diff --git a/html/includes/graphs/temperature.inc.php b/html/includes/graphs/temperature.inc.php index 21e381f54..eb2a6aed7 100644 --- a/html/includes/graphs/temperature.inc.php +++ b/html/includes/graphs/temperature.inc.php @@ -18,8 +18,8 @@ include("common.inc.php"); $rrd_options .= " DEF:temp=$rrd_filename:temp:AVERAGE"; $rrd_options .= " CDEF:tempwarm=temp,".$temperature['temp_limit'].",GT,temp,UNKN,IF"; $rrd_options .= " CDEF:tempcold=temp,20,LT,temp,UNKN,IF"; - $rrd_options .= " AREA:temp#FFFF99"; - $rrd_options .= " AREA:tempwarm#FF9999"; + $rrd_options .= " AREA:temp#bbd392"; + $rrd_options .= " AREA:tempwarm#FFCCCC"; $rrd_options .= " AREA:tempcold#CCCCFF"; $rrd_options .= " LINE1.5:temp#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($temperature['temp_descr_fixed'])))."'"; # Ugly hack :( $rrd_options .= " LINE1.5:tempwarm#660000"; diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 98c296bfe..ad9bca95b 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -11,7 +11,7 @@ while($device = mysql_fetch_array($query_a)) { $this_alert = 0; if ($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif ($device['ignore'] == '0') { - if (mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_host = '".$device['device_id']."'"),0)) { $this_alert = "1"; } + if (mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0' AND device_id = '".$device['device_id']."'"),0)) { $this_alert = "1"; } if (mysql_result(mysql_query("SELECT count(*) FROM ports WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = '" . $device['device_id'] . "' AND `ignore` = '0'"),0)) { $this_alert = "1";} } if ($this_alert) { diff --git a/html/includes/print-service.inc b/html/includes/print-service.inc index 5809cf39a..8d7c10581 100644 --- a/html/includes/print-service.inc +++ b/html/includes/print-service.inc @@ -21,6 +21,8 @@ if(!$samehost) { $checked = formatUptime($checked); } else { $checked = "Never"; } + $mini_url = $config['base_url'] . "/graph.php?id=".$service['service_id']."&type=service&from=".$day."&to=".$now."&width=80&height=20&bg=efefef"; + echo(" "); @@ -35,10 +37,11 @@ if($device_id) { } } -echo(" +echo(" $status + $since diff --git a/html/includes/service-add.inc.php b/html/includes/service-add.inc.php index 1d2aa2c8e..cf7abc41a 100644 --- a/html/includes/service-add.inc.php +++ b/html/includes/service-add.inc.php @@ -2,7 +2,7 @@ $updated = '1'; - $sql = "INSERT INTO `services` (`service_host`,`service_ip`,`service_type`,`service_desc`,`service_param`,`service_ignore`) + $sql = "INSERT INTO `services` (`device_id`,`service_ip`,`service_type`,`service_desc`,`service_param`,`service_ignore`) VALUES ('" . mres($_POST['device']). "','" . mres($_POST['ip']) . "','" . mres($_POST['type']) . "', '" . mres($_POST['descr']) . "','" . mres($_POST['params']) . "','0')"; diff --git a/html/includes/topnav.inc b/html/includes/topnav.inc index d5ed2c7ad..8d382867b 100644 --- a/html/includes/topnav.inc +++ b/html/includes/topnav.inc @@ -35,10 +35,10 @@ $services['disabled'] = mysql_result(mysql_query("SELECT count(service_id) FROM $ports['disabled'] = mysql_result(mysql_query("SELECT count(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND I.device_id = D.device_id AND ifAdminStatus = 'down'"),0); $ports['errored'] = mysql_result(mysql_query("SELECT count(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND I.device_id = D.device_id AND (I.in_errors > '0' OR I.out_errors > '0')"),0); - $services['count'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.service_host = D.device_id"),0); - $services['up'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.service_host = D.device_id AND service_status = '1' AND service_ignore ='0'"),0); - $services['down'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.service_host = D.device_id AND service_status = '0' AND service_ignore = '0'"),0); - $services['disabled'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.service_host = D.device_id AND service_ignore = '1'"),0); + $services['count'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.device_id = D.device_id"),0); + $services['up'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.device_id = D.device_id AND service_status = '1' AND service_ignore ='0'"),0); + $services['down'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.device_id = D.device_id AND service_status = '0' AND service_ignore = '0'"),0); + $services['disabled'] = mysql_result(mysql_query("SELECT count(service_id) FROM services AS S, devices AS D, devices_perms AS P WHERE P.user_id = '" . $_SESSION['user_id'] . "' AND P.device_id = D.device_id AND S.device_id = D.device_id AND service_ignore = '1'"),0); } diff --git a/html/pages/default-jt.php b/html/pages/default-jt.php index 7c03f7336..fb3dec26f 100644 --- a/html/pages/default-jt.php +++ b/html/pages/default-jt.php @@ -50,7 +50,7 @@ while($interface = mysql_fetch_array($sql)){ } -$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); +$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); while($service = mysql_fetch_array($sql)){ diff --git a/html/pages/delsrv.php b/html/pages/delsrv.php index f063e0c45..ebed8890c 100644 --- a/html/pages/delsrv.php +++ b/html/pages/delsrv.php @@ -10,7 +10,7 @@ if($_POST['delsrv']) { } } -$query = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id ORDER BY hostname"); +$query = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname"); while($device = mysql_fetch_array($query)) { $servicesform .= ""; } diff --git a/html/pages/device.php b/html/pages/device.php index 480b7f817..ef66a4d08 100644 --- a/html/pages/device.php +++ b/html/pages/device.php @@ -148,7 +148,7 @@ if($config['enable_inventory'] && @mysql_result(mysql_query("SELECT * FROM `entP #} -if(mysql_result(mysql_query("select count(service_id) from services WHERE service_host = '" . $device['device_id'] . "'"), 0) > '0') { +if(mysql_result(mysql_query("select count(service_id) from services WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') { echo('
  • Services diff --git a/html/pages/device/overview.inc.php b/html/pages/device/overview.inc.php index c1f4b7db8..b36cc1258 100644 --- a/html/pages/device/overview.inc.php +++ b/html/pages/device/overview.inc.php @@ -11,10 +11,10 @@ $ports['up'] = mysql_result(mysql_query("SELECT count(*) FROM ports WHERE devic $ports['down'] = mysql_result(mysql_query("SELECT count(*) FROM ports WHERE device_id = '" . $device['device_id'] . "' AND ifOperStatus = 'down' AND ifAdminStatus = 'up'"),0); $ports['disabled'] = mysql_result(mysql_query("SELECT count(*) FROM ports WHERE device_id = '" . $device['device_id'] . "' AND ifAdminStatus = 'down'"),0); -$services['total'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "'"),0); -$services['up'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "' AND service_status = '1' AND service_ignore ='0'"),0); -$services['down'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "' AND service_status = '0' AND service_ignore = '0'"),0); -$services['disabled'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_host = '" . $device['device_id'] . "' AND service_ignore = '1'"),0); +$services['total'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE device_id = '" . $device['device_id'] . "'"),0); +$services['up'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE device_id = '" . $device['device_id'] . "' AND service_status = '1' AND service_ignore ='0'"),0); +$services['down'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE device_id = '" . $device['device_id'] . "' AND service_status = '0' AND service_ignore = '0'"),0); +$services['disabled'] = mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE device_id = '" . $device['device_id'] . "' AND service_ignore = '1'"),0); if($services['down']) { $services_colour = $warn_colour_a; } else { $services_colour = $list_colour_a; } if($ports['down']) { $ports_colour = $warn_colour_a; } else { $ports_colour = $list_colour_a; } @@ -48,7 +48,7 @@ echo(" echo("
    "); - $sql = "SELECT * FROM services WHERE service_host = '" . $device['device_id'] . "' ORDER BY service_type"; + $sql = "SELECT * FROM services WHERE device_id = '" . $device['device_id'] . "' ORDER BY service_type"; $query = mysql_query($sql); while($data = mysql_fetch_array($query)) { if ($data[service_status] == "0" && $data[service_ignore] == "1") { $status = "grey"; } diff --git a/html/pages/device/srv.inc.php b/html/pages/device/srv.inc.php index ed474cccc..b9d1db15e 100644 --- a/html/pages/device/srv.inc.php +++ b/html/pages/device/srv.inc.php @@ -2,11 +2,11 @@ $hostname = gethostbyid($_GET[id]); -if(mysql_result(mysql_query("select count(service_id) from services WHERE service_host = '$_GET[id]'"), 0) > '0') { +if(mysql_result(mysql_query("select count(service_id) from services WHERE device_id = '$_GET[id]'"), 0) > '0') { echo("
    "); $i = "1"; - $service_query = mysql_query("select * from services WHERE service_host = '$_GET[id]' ORDER BY service_type"); + $service_query = mysql_query("select * from services WHERE device_id = '$_GET[id]' ORDER BY service_type"); while($service = mysql_fetch_array($service_query)) { include("includes/print-service.inc"); diff --git a/html/pages/front/default.php b/html/pages/front/default.php index ec9b68b3c..4dfd12e3b 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -54,7 +54,7 @@ while($interface = mysql_fetch_array($sql)){ } /* FIXME service permissions? seem nonexisting now.. */ -$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); +$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); while($service = mysql_fetch_array($sql)){ generate_front_box("alert", "
    ".generatedevicelink($service, shorthost($service['hostname']))."
    Service Down diff --git a/html/pages/front/demo.php b/html/pages/front/demo.php index 89b808108..0e92f3f1a 100644 --- a/html/pages/front/demo.php +++ b/html/pages/front/demo.php @@ -30,7 +30,7 @@ while($interface = mysql_fetch_array($sql)){ } -$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id AND D.status = '1' AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); +$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND D.status = '1' AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); while($service = mysql_fetch_array($sql)){ echo("
    diff --git a/html/pages/front/example2.php b/html/pages/front/example2.php index 52cbe3cf5..239b6c453 100644 --- a/html/pages/front/example2.php +++ b/html/pages/front/example2.php @@ -48,7 +48,7 @@ while($interface = mysql_fetch_array($sql)){ } -$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); +$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); while($service = mysql_fetch_array($sql)){ echo("
    diff --git a/html/pages/front/jt.php b/html/pages/front/jt.php index 7156b4be3..20c32fffb 100644 --- a/html/pages/front/jt.php +++ b/html/pages/front/jt.php @@ -49,7 +49,7 @@ while($interface = mysql_fetch_array($sql)){ } -$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); +$sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"); while($service = mysql_fetch_array($sql)){ if(devicepermitted($service['device_id'])) { echo("
    diff --git a/html/pages/services.php b/html/pages/services.php index a3014fd33..9ddde875e 100644 --- a/html/pages/services.php +++ b/html/pages/services.php @@ -6,15 +6,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"; + $host_sql = "SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id 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_sql = "SELECT * FROM devices AS D, services AS S, devices_perms AS P WHERE D.device_id = S.device_id 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']; $device_hostname = $host_data['hostname']; - $service_query = mysql_query("SELECT * FROM `services` WHERE `service_host` = '" . $host_data['device_id'] . "' $where"); + $service_query = mysql_query("SELECT * FROM `services` WHERE `device_id` = '" . $host_data['device_id'] . "' $where"); while($service = mysql_fetch_array($service_query)) { include("includes/print-service.inc"); $samehost = 1; diff --git a/includes/functions.php b/includes/functions.php index a5d25914d..af51deb9c 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -430,7 +430,7 @@ function delHost($id) mysql_query("DELETE FROM `eventlog` WHERE `host` = '$id'"); mysql_query("DELETE FROM `syslog` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `ports` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `services` WHERE `service_host` = '$id'"); + mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); shell_exec("rm -rf ".$config['rrd_dir']."/$host"); echo("Removed device $host
    "); @@ -458,7 +458,7 @@ function retireHost($id) mysql_query("DELETE FROM `temperature` WHERE `device_id` = '$id'"); mysql_query("DELETE FROM `storage` WHERE `host_id` = '$id'"); mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'"); - mysql_query("DELETE FROM `services` WHERE `service_host` = '$id'"); + mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'"); shell_exec("rm -rf ".$config['rrd_dir']."/$host"); echo("Removed device $host
    "); }
    DeviceServiceStatusChangedCheckedMessage