mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
add service history RRD and graph
git-svn-id: http://www.observium.org/svn/observer/trunk@926 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
parent
d54df316ac
commit
de075546b0
@ -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);
|
||||
|
||||
}
|
||||
?>
|
||||
|
@ -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
|
||||
|
29
html/includes/graphs/service.inc.php
Executable file
29
html/includes/graphs/service.inc.php
Executable file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
$scale_min = "0";
|
||||
$scale_max = "1";
|
||||
|
||||
include("common.inc.php");
|
||||
|
||||
$iter = "1";
|
||||
|
||||
$sql = "SELECT * FROM `services` AS S, `devices` AS D where S.`service_id` = '".mres($_GET['id'])."' AND S.device_id = D.device_id";
|
||||
$query = mysql_query($sql);
|
||||
$service = mysql_fetch_array($query);
|
||||
|
||||
$rrd = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename("service-" . $service['service_type'] . "-" . $service['service_id'] . ".rrd");
|
||||
|
||||
$rrd_options .= " COMMENT:' Cur Max\\n'";
|
||||
$rrd_options .= " DEF:status=$rrd:status:AVERAGE";
|
||||
$rrd_options .= " CDEF:down=status,1,LT,status,UNKN,IF";
|
||||
$rrd_options .= " AREA:status#CCFFCC";
|
||||
$rrd_options .= " AREA:down#FFCCCC";
|
||||
$rrd_options .= " LINE1.5:status#009900:'" . $service['service_type'] . "'"; # Ugly hack :(
|
||||
$rrd_options .= " LINE1.5:down#cc0000";
|
||||
$rrd_options .= " GPRINT:status:LAST:%3.0lf";
|
||||
$rrd_options .= " GPRINT:status:MAX:%3.0lf\\\\l";
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
@ -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";
|
||||
|
@ -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) {
|
||||
|
@ -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("
|
||||
<tr style=\"background-color: $bg; padding: 5px;\">");
|
||||
@ -35,10 +37,11 @@ if($device_id) {
|
||||
}
|
||||
}
|
||||
|
||||
echo("
|
||||
echo("
|
||||
<td valign=top class=list-bold>
|
||||
$status
|
||||
</td>
|
||||
<td><img src='$mini_url'></td>
|
||||
<td valign=top width=175>
|
||||
$since
|
||||
</td>
|
||||
|
@ -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')";
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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)){
|
||||
|
||||
|
||||
|
@ -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 .= "<option value='" . $device[service_id] . "'>" . $device['service_id'] . "." . $device['hostname'] . " - " . $device['service_type'] . "</option>";
|
||||
}
|
||||
|
@ -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('<li class="' . $select['srv'] . '">
|
||||
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/srv/">
|
||||
<img src="images/16/server_cog.png" align="absmiddle" border="0" /> Services
|
||||
|
@ -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("<div style='padding: 8px; font-size: 11px; font-weight: bold;'>");
|
||||
|
||||
$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"; }
|
||||
|
@ -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("<div style='margin: 5px;'><table cellpadding=7 border=0 cellspacing=0 width=100%>");
|
||||
$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");
|
||||
|
@ -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", "<center><strong>".generatedevicelink($service, shorthost($service['hostname']))."</strong><br />
|
||||
<span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Service Down</span>
|
||||
|
@ -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("<div style='border: solid 2px #D0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>
|
||||
|
@ -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("<div style='border: solid 2px #D0D0D0; float: left; padding: 5px; width: 120px; height: 90px; background: #ffddaa; margin: 4px;'>
|
||||
|
@ -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("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>
|
||||
|
@ -6,15 +6,15 @@ echo("<div style='margin: 5px;'><table cellpadding=7 border=0 cellspacing=0 widt
|
||||
//echo("<tr class=interface-desc bgcolor='#e5e5e5'><td>Device</td><td>Service</td><td>Status</td><td>Changed</td><td>Checked</td><td>Message</td></tr>");
|
||||
|
||||
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;
|
||||
|
@ -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<br />");
|
||||
@ -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<br />");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user