Feature: Translate timestick of snmps to humen readable. Ticket: #2494

This commit is contained in:
m-lopez-f 2016-10-26 16:17:02 +02:00
parent cd179a8a20
commit 287c2a7477
3 changed files with 104 additions and 11 deletions

View File

@ -283,8 +283,20 @@ if ($get_module_detail) {
$data[] = io_safe_input($row[$attr[0]]);
}
else if (is_numeric($row[$attr[0]]) && !modules_is_string_type($row['module_type']) ) {
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
switch($row['module_type']) {
case 15:
$value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module_id);
if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0')
$data[] = human_milliseconds_to_string($row['data']);
else
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
break;
default:
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
break;
}
//~ $data[] = (double) $row[$attr[0]];
}
else {
if ($row[$attr[0]] == '') {
@ -909,12 +921,34 @@ if ($list_modules) {
$salida = $config["render_proc_fail"];
break;
default:
$salida = remove_right_zeros(number_format($module["datos"], $config['graph_precision']));
switch($module['id_tipo_modulo']) {
case 15:
$value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module['id_agente_modulo']);
if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0')
$salida = human_milliseconds_to_string($module['datos']);
else
$salida = remove_right_zeros(number_format($module["datos"], $config['graph_precision']));
break;
default:
$salida = remove_right_zeros(number_format($module["datos"], $config['graph_precision']));
break;
}
break;
}
}
else {
$salida = remove_right_zeros(number_format($module["datos"], $config['graph_precision']));
switch($module['id_tipo_modulo']) {
case 15:
$value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module['id_agente_modulo']);
if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0')
$salida = human_milliseconds_to_string($module['datos']);
else
$salida = remove_right_zeros(number_format($module["datos"], $config['graph_precision']));
break;
default:
$salida = remove_right_zeros(number_format($module["datos"], $config['graph_precision']));
break;
}
}
// Show units ONLY in numeric data types
if (isset($module["unit"])) {

View File

@ -247,6 +247,32 @@ function format_for_graph ($number , $decimals = 1, $dec_point = ".", $thousands
return format_numeric ($number, $decimals). $shorts[$pos]; //This will actually do the rounding and the decimals
}
function human_milliseconds_to_string($seconds) {
$ret = "";
/*** get the days ***/
$days = intval(intval($seconds) / (360000*24));
if($days > 0)
$ret .= "$days days ";
/*** get the hours ***/
$hours = (intval($seconds) / 360000) % 24;
if($hours > 0)
$ret .= "$hours hours ";
/*** get the minutes ***/
$minutes = (intval($seconds) / 6000) % 60;
if($minutes > 0)
$ret .= "$minutes minutes ";
/*** get the seconds ***/
$seconds = intval($seconds / 100) % 60;
if ($seconds > 0)
$ret .= "$seconds seconds";
return $ret;
}
/**
* Rounds an integer to a multiple of 5.
*

View File

@ -182,20 +182,53 @@ function treeview_printModuleTable($id_module, $server_data = false, $no_head =
$data = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" . $config["render_proc_fail"] . "</span>";
}
break;
default:
//~ if (is_numeric($last_data["datos"]))
//~ $data = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" . format_numeric($last_data["datos"]) . "</span>";
//~ else
//~ $data = "<span title='" . $last_data["datos"] . "' style='white-space: nowrap;'>" . substr(io_safe_output($last_data['datos']),0,12) . "</span>";
switch($module['id_tipo_modulo']) {
case 15:
$value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module['id_agente_modulo']);
if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0')
$data = "<span title='" . human_milliseconds_to_string($last_data['datos']) . "' style='white-space: nowrap;'>" . human_milliseconds_to_string($last_data['datos']) . "</span>";
else
if (is_numeric($last_data["datos"]))
$data = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" . format_numeric($last_data["datos"]) . "</span>";
else
$data = "<span title='" . $last_data["datos"] . "' style='white-space: nowrap;'>" . substr(io_safe_output($last_data['datos']),0,12) . "</span>";
break;
default:
if (is_numeric($last_data["datos"]))
$data = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" . format_numeric($last_data["datos"]) . "</span>";
else
$data = "<span title='" . $last_data["datos"] . "' style='white-space: nowrap;'>" . substr(io_safe_output($last_data['datos']),0,12) . "</span>";
break;
}
break;
}
}
else {
switch($module['id_tipo_modulo']) {
case 15:
$value = db_get_value('snmp_oid', 'tagente_modulo', 'id_agente_modulo', $module['id_agente_modulo']);
if ($value == '.1.3.6.1.2.1.1.3.0' || $value == '.1.3.6.1.2.1.25.1.1.0')
$data = "<span title='" . human_milliseconds_to_string($last_data['datos']) . "' style='white-space: nowrap;'>" . human_milliseconds_to_string($last_data['datos']) . "</span>";
else
if (is_numeric($last_data["datos"]))
$data = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" . format_numeric($last_data["datos"]) . "</span>";
else
$data = "<span title='" . $last_data["datos"] . "' style='white-space: nowrap;'>" . substr(io_safe_output($last_data['datos']),0,12) . "</span>";
break;
default:
if (is_numeric($last_data["datos"]))
$data = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" . format_numeric($last_data["datos"]) . "</span>";
else
$data = "<span title='" . $last_data["datos"] . "' style='white-space: nowrap;'>" . substr(io_safe_output($last_data['datos']),0,12) . "</span>";
break;
break;
}
}
else {
if (is_numeric($last_data["datos"]))
$data = "<span style='height: 20px; display: inline-table; vertical-align: top;'>" . format_numeric($last_data["datos"]) . "</span>";
else
$data = "<span title='" . $last_data["datos"] . "' style='white-space: nowrap;'>" . substr(io_safe_output($last_data['datos']),0,12) . "</span>";
}
if (!empty($last_data['utimestamp'])) {
$last_data_str = $data;