$filter) + $other_filter));
if ($modules === false) $modules = array();
$modules = array_unique($modules);
$modules = io_safe_output($modules);
echo json_encode($modules);
return;
}
if ($get_module_detail) {
// This script is included manually to be included after jquery and avoid error
ui_include_time_picker();
ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/");
$module_id = (int)get_parameter('id_module');
$period = get_parameter("period", SECONDS_1DAY);
if ($period === 'undefined') {
$period = SECONDS_1DAY;
}
else {
$period = (int)$period;
}
$group = agents_get_agentmodule_group ($module_id);
$agentId = (int) get_parameter("id_agent");
$server_name = (string) get_parameter('server_name');
if (is_metaconsole()) {
$server = metaconsole_get_connection ($server_name);
if (metaconsole_connect($server) != NOERR)
return;
$conexion = false;
}
else {
$conexion = false;
}
$freesearch = (string) get_parameter ('freesearch', '');
$free_checkbox = (bool) get_parameter ('free_checkbox', false);
$selection_mode = get_parameter('selection_mode', 'fromnow');
$utimestamp = get_system_time();
$date_from = (string) get_parameter ('date_from', date(DATE_FORMAT, $utimestamp - SECONDS_1DAY));
$time_from = (string) get_parameter ('time_from', date(TIME_FORMAT, $utimestamp - SECONDS_1DAY));
$date_to = (string) get_parameter ('date_to', date(DATE_FORMAT, $utimestamp));
$time_to = (string) get_parameter ('time_to', date(TIME_FORMAT, $utimestamp));
$formtable->width = '98%';
$formtable->class = "databox";
$formtable->data = array ();
$formtable->size = array ();
$moduletype_name = modules_get_moduletype_name(
modules_get_agentmodule_type($module_id));
$periods = array(SECONDS_5MINUTES =>__('5 minutes'),
SECONDS_30MINUTES =>__('30 minutes'),
SECONDS_1HOUR =>__('1 hour'),
SECONDS_6HOURS =>__('6 hours'),
SECONDS_12HOURS =>__('12 hours'),
SECONDS_1DAY =>__('1 day'),
SECONDS_1WEEK =>__('1 week'),
SECONDS_15DAYS =>__('15 days'),
SECONDS_1MONTH =>__('1 month'),
SECONDS_3MONTHS =>__('3 months'),
SECONDS_6MONTHS =>__('6 months'),
SECONDS_1YEAR =>__('1 year'),
SECONDS_2YEARS =>__('2 years'),
SECONDS_3YEARS =>__('3 years'));
$formtable->data[0][0] = html_print_radio_button_extended (
"selection_mode", 'fromnow', '', $selection_mode, false, '',
'style="margin-right: 15px;"', true) . __("Choose a time from now");
$formtable->data[0][1] = html_print_select ($periods, 'period', $period, '', '', 0, true, false, false);
$formtable->data[0][2] = '';
$formtable->data[0][3] = "" .
html_print_image ("images/refresh.png", true, array ("style" => 'vertical-align: middle;', "border" => "0" )) .
"";
$formtable->rowspan[0][3] = 2;
$formtable->cellstyle[0][3] = 'vertical-align: middle;';
$formtable->data[1][0] = html_print_radio_button_extended(
"selection_mode", 'range','', $selection_mode, false, '',
'style="margin-right: 15px;"', true) . __("Specify time range");
$formtable->data[1][1] = __('Timestamp from:');
$formtable->data[1][2] = html_print_input_text('date_from',
$date_from, '', 10, 10, true);
$formtable->data[1][2] .= html_print_input_text('time_from',
$time_from, '', 9, 7, true);
$formtable->data[1][1] .= '
';
$formtable->data[1][1] .= __('Timestamp to:');
$formtable->data[1][2] .= '
';
$formtable->data[1][2] .= html_print_input_text('date_to', $date_to,
'', 10, 10, true);
$formtable->data[1][2] .= html_print_input_text('time_to', $time_to,
'', 9, 7, true);
$freesearch_object = '';
if (preg_match("/_string/", $moduletype_name)) {
$formtable->data[2][0] = __('Free search') . ' ';
$formtable->data[2][1] = html_print_input_text ('freesearch', $freesearch, '', 20, null, true);
$formtable->data[2][2] = html_print_checkbox('free_checkbox', 1, $free_checkbox, true);
$formtable->data[2][2] .= ' ' . __('Exact phrase');
$freesearch_object = json_encode( array(
'value' => io_safe_output($freesearch),
'exact' => (bool)$free_checkbox
));
}
html_print_table($formtable);
$offset = (int) get_parameter("offset");
$block_size = (int) $config["block_size"];
$columns = array ();
$datetime_from = strtotime ($date_from . ' ' . $time_from);
$datetime_to = strtotime ($date_to . ' ' . $time_to);
$columns = array(
"Data" => array(
"data",
"modules_format_data",
"align" => "center",
"width" => "230px"),
);
if($config['prominent_time']=='comparation') {
$columns["Time"] = array(
"utimestamp",
"modules_format_time",
"align" => "center",
"width" => "50px");
}
else {
$columns["Timestamp"] = array(
"utimestamp",
"modules_format_timestamp",
"align" => "center",
"width" => "50px");
}
if ($selection_mode == "fromnow") {
$date = get_system_time();
$period = $period;
}
else {
$period = $datetime_to - $datetime_from;
$date = $datetime_from + $period;
}
$count = modules_get_agentmodule_data ($module_id, $period,
$date, true, $conexion, 'ASC', $freesearch_object);
$module_data = modules_get_agentmodule_data ($module_id, $period,
$date, false, $conexion, 'DESC', $freesearch_object);
if (empty($module_data)) {
$result = array();
}
else {
// Paginate the result
$result = array_slice($module_data, $offset, $block_size);
}
$table->width = '100%';
$table->class = 'databox data';
$table->data = array();
$index = 0;
foreach($columns as $col => $attr) {
$table->head[$index] = $col;
if (isset($attr["align"]))
$table->align[$index] = $attr["align"];
if (isset($attr["width"]))
$table->size[$index] = $attr["width"];
$index++;
}
$id_type_web_content_string = db_get_value('id_tipo',
'ttipo_modulo', 'nombre', 'web_content_string');
$post_process = db_get_value_filter('post_process','tagente_modulo',array('id_agente_modulo' => $module_id));
$unit = db_get_value_filter('unit','tagente_modulo',array('id_agente_modulo' =>$module_id));
foreach ($result as $row) {
$data = array ();
$is_web_content_string = (bool)db_get_value_filter('id_agente_modulo',
'tagente_modulo',
array('id_agente_modulo' => $row['id_agente_modulo'],
'id_tipo_modulo' => $id_type_web_content_string));
foreach ($columns as $col => $attr) {
if ($attr[1] != "modules_format_data") {
$data[] = date('d F Y h:i:s A', $row['utimestamp']);
}
elseif(is_snapshot_data($row[$attr[0]])){
if($config['command_snapshot']){
$data[] = "
";
}
else{
$data[] = "".wordwrap(io_safe_input($row[$attr[0]]),60,"
\n",true)."";
}
}
elseif (($config['command_snapshot'] == '0') && (preg_match ("/[\n]+/i", $row[$attr[0]]))) {
// Its a single-data, multiline data (data snapshot) ?
// I dont why, but using index (value) method, data is automatically converted to html entities ¿?
$data[] = html_print_result_div($row[$attr[0]]);
}
elseif ($is_web_content_string) {
//Fixed the goliat sends the strings from web
//without HTML entities
$data[] = io_safe_input($row[$attr[0]]);
}
else {
//Fixed the data from Selenium Plugin
if ($row[$attr[0]] != strip_tags($row[$attr[0]])) {
$data[] = html_print_result_div($row[$attr[0]]);
}
else if (is_numeric($row[$attr[0]]) && !modules_is_string_type($row['module_type']) ) {
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'){
if($post_process > 0){
$data[] = human_milliseconds_to_string($row['data'] / $post_process);
} else {
$data[] = human_milliseconds_to_string($row['data']);
}
}else{
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
}
break;
default:
$data_macro = modules_get_unit_macro($row[$attr[0]],$unit);
if($data_macro){
$data[] = $data_macro;
} else {
$data[] = remove_right_zeros(number_format($row[$attr[0]], $config['graph_precision']));
}
break;
}
}
else {
if ($row[$attr[0]] == '') {
$data[] = 'No data';
}
else {
$data_macro = modules_get_unit_macro($row[$attr[0]],$unit);
if($data_macro){
$data[] = $data_macro;
} else {
$data[] = html_print_result_div($row[$attr[0]]);
}
}
}
}
}
array_push ($table->data, $data);
if (count($table->data) > 200)
break;
}
if (empty ($table->data)) {
ui_print_error_message(__('No available data to show'));
}
else {
ui_pagination (count($count), false, $offset, 0, false, 'offset', true, 'binary_dialog');
html_print_table($table);
}
if (is_metaconsole())
metaconsole_restore_db();
return;
}
if ($get_module_autocomplete_input) {
$id_agent = (int) get_parameter("id_agent");
ob_clean();
if ($id_agent > 0) {
html_print_autocomplete_modules(
'autocomplete_module_name', '', array($id_agent));
return;
}
return;
}
if ($add_module_relation) {
$result = false;
$id_module_a = (int) get_parameter("id_module_a");
$id_module_b = (int) get_parameter("id_module_b");
if ($id_module_a < 1) {
$name_module_a = get_parameter("name_module_a", "");
if ($name_module_a) {
$id_module_a = (int) db_get_value('id_agente_modulo', 'tagente_modulo', 'nombre', $name_module_a);
}
else {
echo json_encode($result);
return;
}
}
if ($id_module_b < 1) {
$name_module_b = get_parameter("name_module_b", "");
if ($name_module_b) {
$id_module_b = (int) db_get_value('id_agente_modulo', 'tagente_modulo', 'nombre', $name_module_b);
}
else {
echo json_encode($result);
return;
}
}
if ($id_module_a > 0 && $id_module_b > 0) {
$result = modules_add_relation($id_module_a, $id_module_b);
}
echo json_encode($result);
return;
}
if ($remove_module_relation) {
$id_relation = (int) get_parameter("id_relation");
if ($id_relation > 0) {
$result = (bool) modules_delete_relation($id_relation);
}
echo json_encode($result);
return;
}
if ($change_module_relation_updates) {
$id_relation = (int) get_parameter("id_relation");
if ($id_relation > 0) {
$result = (bool) modules_change_relation_lock($id_relation);
}
echo json_encode($result);
return;
}
if ($get_id_tag) {
$tag_name = get_parameter('tag_name');
if ($tag_name) {
$tag_id = db_get_value('id_tag', 'ttag', 'name', $tag_name);
}
else {
$tag_id = 0;
}
echo $tag_id;
return;
}
if ($list_modules) {
include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_servers.php");
include_once($config['homedir'] . "/include/functions_tags.php");
include_once($config['homedir'] . "/include/functions_clippy.php");
$agent_a = check_acl ($config['id_user'], 0, "AR");
$agent_w = check_acl ($config['id_user'], 0, "AW");
$access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR');
$id_agente = $id_agent = (int)get_parameter('id_agente', 0);
$show_notinit = (int)get_parameter('show_notinit', 0);
$cluster_list = (int)get_parameter('cluster_list', 0);
$url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $id_agent;
$selectTypeUp = '';
$selectTypeDown = '';
$selectNameUp = '';
$selectNameDown = '';
$selectStatusUp = '';
$selectStatusDown = '';
$selectDataUp = '';
$selectDataDown = '';
$selectLastContactUp = '';
$selectLastContactDown = '';
$sortField = get_parameter('sort_field');
$sort = get_parameter('sort', 'none');
$selected = 'border: 1px solid black;';
switch ($sortField) {
case 'type':
switch ($sort) {
case 'up':
$selectTypeUp = $selected;
$order = array('field' => 'tagente_modulo.id_modulo', 'order' => 'ASC');
break;
case 'down':
$selectTypeDown = $selected;
$order = array('field' => 'tagente_modulo.id_modulo', 'order' => 'DESC');
break;
}
break;
case 'name':
switch ($sort) {
case 'up':
$selectNameUp = $selected;
$order = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC');
break;
case 'down':
$selectNameDown = $selected;
$order = array('field' => 'tagente_modulo.nombre', 'order' => 'DESC');
break;
}
break;
case 'status':
switch ($sort) {
case 'up':
$selectStatusUp = $selected;
$order = array('field' => 'tagente_estado.estado=0 DESC,tagente_estado.estado=3 DESC,tagente_estado.estado=2 DESC,tagente_estado.estado=1 DESC', 'order' => '');
break;
case 'down':
$selectStatusDown = $selected;
$order = array('field' => 'tagente_estado.estado=1 DESC,tagente_estado.estado=2 DESC,tagente_estado.estado=3 DESC,tagente_estado.estado=0 DESC', 'order' => '');
break;
}
break;
case 'last_contact':
switch ($sort) {
case 'up':
$selectLastContactUp = $selected;
$order = array('field' => 'tagente_estado.utimestamp', 'order' => 'ASC');
break;
case 'down':
$selectLastContactDown = $selected;
$order = array('field' => 'tagente_estado.utimestamp', 'order' => 'DESC');
break;
}
break;
default:
$selectTypeUp = '';
$selectTypeDown = '';
$selectNameUp = $selected;
$selectNameDown = '';
$selectStatusUp = '';
$selectStatusDown = '';
$selectDataUp = '';
$selectDataDown = '';
$selectLastContactUp = '';
$selectLastContactDown = '';
$order = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC');
break;
}
// Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!)
$groups = users_get_groups($config["id_user"], $access);
$tags_join = "";
$tags_sql = "";
if($cluster_list != 1) {
$tags = tags_get_user_applied_agent_tags ($id_agent, $access);
if ($tags === false) {
$tags_sql = " AND 1=0";
}
elseif (is_array($tags)) {
$tags_sql = " AND ttag_module.id_tag IN (" . implode(',', $tags) . ")";
$tags_join = "LEFT JOIN ttag_module
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
}
}
$status_filter_monitor = (int)get_parameter('status_filter_monitor', -1);
$status_text_monitor = get_parameter('status_text_monitor', '');
$filter_monitors = (bool)get_parameter('filter_monitors', false);
$status_module_group = get_parameter('status_module_group', -1);
$monitors_change_filter = (bool)get_parameter('monitors_change_filter', false);
$status_filter_sql = '1 = 1';
if ($status_filter_monitor == AGENT_MODULE_STATUS_NOT_NORMAL) { //Not normal
$status_filter_sql = " tagente_estado.estado <> 0";
}
elseif ($status_filter_monitor != -1) {
$status_filter_sql = 'tagente_estado.estado = ' . $status_filter_monitor;
}
if ($status_module_group != -1) {
$status_module_group_filter = 'tagente_modulo.id_module_group = ' . $status_module_group;
}
else {
$status_module_group_filter = 'tagente_modulo.id_module_group >= 0';
}
$status_text_monitor_sql = '%';
if (!empty($status_text_monitor)) {
$status_text_monitor_sql .= $status_text_monitor . '%';
}
if(!$show_notinit){
$monitor_filter = AGENT_MODULE_STATUS_NO_DATA;
}
else{
$monitor_filter = -15;
}
//Count monitors/modules
$order_sql = $order['field'] . " " . $order['order'];
$sql_condition = "FROM tagente_modulo
$tags_join
INNER JOIN tagente_estado
ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE tagente_modulo.id_agente = $id_agente
AND nombre LIKE '$status_text_monitor_sql'
AND delete_pending = 0
AND disabled = 0
AND $status_filter_sql
AND $status_module_group_filter
$tags_sql
AND tagente_estado.estado != $monitor_filter
";
$count_modules = db_get_all_rows_sql('SELECT COUNT(DISTINCT tagente_modulo.id_agente_modulo)' . $sql_condition);
if (isset($count_modules[0]))
$count_modules = reset($count_modules[0]);
else
$count_modules = 0;
//Get monitors/modules
// Get all module from agent
$sql_modules_info = "SELECT tagente_estado.*, tagente_modulo.*, tmodule_group.*
$sql_condition
GROUP BY tagente_modulo.id_agente_modulo ORDER BY $order_sql";
if ($monitors_change_filter) {
$limit = " LIMIT " . $config['block_size'] . " OFFSET 0";
}
else {
$limit = " LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
}
$paginate_module = false;
if (isset($config['paginate_module']))
$paginate_module = $config['paginate_module'];
if ($paginate_module) {
$modules = db_get_all_rows_sql ($sql_modules_info . $limit);
}
else {
$modules = db_get_all_rows_sql ($sql_modules_info);
}
if (empty ($modules)) {
$modules = array ();
}
$table = new stdClass();
$table->width = "100%";
$table->cellpadding = 4;
$table->cellspacing = 4;
$table->class = "databox data";
$table->head = array ();
$table->data = array ();
$isFunctionPolicies = enterprise_include_once ('include/functions_policies.php');
if ($agent_w)
$table->head[0] = "" . __('F.') . "";
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) {
$table->head[1] = "" . __('P.') . "";
}
$table->head[2] = __('Type') . ' ' .
'' . html_print_image("images/sort_up.png", true, array("style" => $selectTypeUp, "alt" => "up")) . '' .
'' . html_print_image("images/sort_down.png", true, array("style" => $selectTypeDown, "alt" => "down")) . '';
$table->head[3] = __('Module name') . ' ' .
'' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp, "alt" => "up")) . '' .
'' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown, "alt" => "down")) . '';
$table->head[4] = __('Description');
$table->head[5] = __('Status') . ' ' .
'' . html_print_image("images/sort_up.png", true, array("style" => $selectStatusUp, "alt" => "up")) . '' .
'' . html_print_image("images/sort_down.png", true, array("style" => $selectStatusDown, "alt" => "down")) . '';
$table->head[6] = __('Thresholds');
$table->head[7] = __('Data');
$table->head[8] = __('Graph');
$table->headstyle[8] = 'min-width: 60px';
$table->head[9] = __('Last contact') . ' ' .
'' . html_print_image("images/sort_up.png", true, array("style" => $selectLastContactUp, "alt" => "up")) . '' .
'' . html_print_image("images/sort_down.png", true, array("style" => $selectLastContactDown, "alt" => "down")) . '';
$table->align = array("left", "left", "left", "left", "left", "left","left","left","left");
$last_modulegroup = 0;
$rowIndex = 0;
$id_type_web_content_string = db_get_value('id_tipo', 'ttipo_modulo',
'nombre', 'web_content_string');
$show_context_help_first_time = false;
$hierachy_mode = get_parameter('hierachy_mode', false);
if ($hierachy_mode == "true") {
$modules_hierachy = array();
$modules_hierachy = get_hierachy_modules_tree($modules);
$modules_dt = get_dt_from_modules_tree($modules_hierachy);
$modules = $modules_dt;
}
foreach ($modules as $module) {
if ($hierachy_mode !== "true") {
//The code add the row of 1 cell with title of group for to be more organice the list.
if ($module["id_module_group"] != $last_modulegroup)
{
$table->colspan[$rowIndex][0] = count($table->head);
$table->rowclass[$rowIndex] = 'datos4';
array_push ($table->data, array (''.$module['name'].''));
$rowIndex++;
$last_modulegroup = $module["id_module_group"];
}
//End of title of group
}
$data = array ();
if (($module["id_modulo"] != 1) && ($module["id_tipo_modulo"] != 100)) {
if ($agent_w) {
if ($module["flag"] == 0) {
$data[0] = '' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . '';
}
else {
$data[0] = '' . html_print_image("images/refresh.png", true, array("border" => "0", "title" => __("Refresh"))) . '';
}
}
}
else {
if ($agent_w)
$data[0] = '';
}
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) {
if ($module["id_policy_module"] != 0) {
$linked = policies_is_module_linked($module['id_agente_modulo']);
$id_policy = db_get_value_sql('SELECT id_policy FROM tpolicy_modules WHERE id = '.$module["id_policy_module"]);
if ($id_policy != "")
$name_policy = db_get_value_sql('SELECT name FROM tpolicies WHERE id = '.$id_policy);
else
$name_policy = __("Unknown");
$policyInfo = policies_info_module_policy($module["id_policy_module"]);
$adopt = false;
if (policies_is_module_adopt($module['id_agente_modulo'])) {
$adopt = true;
}
if ($linked) {
if ($adopt) {
$img = 'images/policies_brick.png';
$title = '(' . __('Adopted') . ') ' . $name_policy;
}
else {
$img = 'images/policies.png';
$title = $name_policy;
}
}
else {
if ($adopt) {
$img = 'images/policies_not_brick.png';
$title = '(' . __('Unlinked') . ') (' . __('Adopted') . ') ' . $name_policy;
}
else {
$img = 'images/unlinkpolicy.png';
$title = '(' . __('Unlinked') . ') ' . $name_policy;
}
}
$data[1] = '' .
html_print_image($img,true, array('title' => $title)) .
'';
}
else {
$data[1] = "";
}
}
$data[2] = servers_show_type ($module['id_modulo']) . ' ';
if (check_acl ($config['id_user'], $id_grupo, "AW"))
$data[2] .= '' . html_print_image("images/config.png", true, array("alt" => '0', "border" => "", "title" => __('Edit'))) . '';
$data[3] = "";
if (isset($module['deep']) && ($module['deep'] != 0)) {
$data[3] .= str_repeat(' ', $module['deep']);
$data[3] .= html_print_image("images/icono_escuadra.png", true, array("style" => 'padding-bottom: inherit;')) . " ";
}
if ($module['quiet']) {
$data[3] .= html_print_image("images/dot_blue.png", true,
array("border" => '0', "title" => __('Quiet'), "alt" => ""))
. " ";
}
$data[3] .= ui_print_truncate_text($module["nombre"], 'module_medium');
if (!empty($module["extended_info"])) {
if ($module["extended_info"] != "") {
$data[3] .= ui_print_help_tip ($module["extended_info"], true, '/images/default_list.png');
}
}
//Adds tag context information
if (tags_get_modules_tag_count($module['id_agente_modulo']) > 0) {
$data[3] .= ' ' .
html_print_image("images/tag_red.png", true, array("id" => 'tag-details-'.$module['id_agente_modulo'], "class" => "img_help")) . ' ';
}
//Adds relations context information
if (modules_relation_exists($module['id_agente_modulo'])) {
$data[3] .= ' ' .
html_print_image("images/link2.png", true, array("id" => 'relations-details-'.$module['id_agente_modulo'], "class" => "img_help")) . ' ';
}
$data[4] = ui_print_string_substr ($module["descripcion"], 60, true, 8);
if ($module["datos"] != strip_tags($module["datos"])) {
$module_value = io_safe_input($module["datos"]);
}
else {
$module_value = io_safe_output($module["datos"]);
}
modules_get_status($module['id_agente_modulo'], $module['estado'],
$module_value, $status, $title);
$data[5] = ui_print_status_image($status, $title, true);
if (!$show_context_help_first_time) {
$show_context_help_first_time = true;
if ($module['estado'] == AGENT_MODULE_STATUS_UNKNOWN) {
$data[5] .= clippy_context_help("module_unknow");
}
}
if ($module["id_tipo_modulo"] == 24) {
// log4x
switch($module["datos"]) {
case 10:
$salida = "TRACE";
$style="font-weight:bold; color:darkgreen;";
break;
case 20:
$salida = "DEBUG";
$style="font-weight:bold; color:darkgreen;";
break;
case 30:
$salida = "INFO";
$style="font-weight:bold; color:darkgreen;";
break;
case 40:
$salida = "WARN";
$style="font-weight:bold; color:darkorange;";
break;
case 50:
$salida = "ERROR";
$style="font-weight:bold; color:red;";
break;
case 60:
$salida = "FATAL";
$style="font-weight:bold; color:red;";
break;
}
$salida = "$salida";
}
else {
if (is_numeric($module["datos"]) && !modules_is_string_type($module['id_tipo_modulo'])) {
if ( $config["render_proc"] ) {
switch($module["id_tipo_modulo"]) {
case 2:
case 6:
case 9:
case 18:
case 21:
case 31:
if ($module["datos"]>=1)
$salida = $config["render_proc_ok"];
else
$salida = $config["render_proc_fail"];
break;
default:
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'){
if($module['post_process']>0){
$salida = human_milliseconds_to_string($module['datos'] / $module['post_process']);
} else {
$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 {
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'){
if($module['post_process']>0){
$salida = human_milliseconds_to_string($module['datos'] / $module['post_process']);
} else {
$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"])) {
$data_macro = modules_get_unit_macro($module["datos"],$module["unit"]);
if($data_macro){
$salida = $data_macro;
} else {
$salida .= " " . ''. io_safe_output($module["unit"]) . '';
}
}
}
else {
$data_macro = modules_get_unit_macro($module["datos"],$module["unit"]);
if($data_macro){
$salida = $data_macro;
} else {
$salida = ui_print_module_string_value(
$module["datos"], $module["id_agente_modulo"],
$module["current_interval"], $module["module_name"]);
}
}
}
if($module["id_tipo_modulo"] != 25){
$data[6] = ui_print_module_warn_value ($module["max_warning"], $module["min_warning"], $module["str_warning"], $module["max_critical"], $module["min_critical"], $module["str_critical"]);
}
else{
$data[6] = "";
}
$data[7] = $salida;
$graph_type = return_graphtype ($module["id_tipo_modulo"]);
$data[8] = " ";
if ($module['history_data'] == 1) {
$nombre_tipo_modulo = modules_get_moduletype_name ($module["id_tipo_modulo"]);
$handle = "stat".$nombre_tipo_modulo."_".$module["id_agente_modulo"];
$url = 'include/procesos.php?agente='.$module["id_agente_modulo"];
$win_handle=dechex(crc32($module["id_agente_modulo"].$module["nombre"]));
// Try to display the SNMP module realtime graph
$rt_button = get_module_realtime_link_graph($module);
if (!empty($rt_button)) $data[8] = $rt_button . " ";
# Show events for boolean modules by default.
if ($graph_type == 'boolean') {
$draw_events = 1;
} else {
$draw_events = 0;
}
$link ="winopeng('" .
"operation/agentes/stat_win.php?" .
"type=$graph_type&" .
"period=" . SECONDS_1DAY . "&" .
"id=" . $module["id_agente_modulo"] . "&" .
"label=" . rawurlencode(
urlencode(
base64_encode($module["nombre"]))) . "&" .
"refresh=" . SECONDS_10MINUTES . "&" .
"draw_events=$draw_events', 'day_".$win_handle."')";
if(!is_snapshot_data($module['datos'])){
$data[8] .= '' . html_print_image("images/chart_curve.png", true, array("border" => '0', "alt" => "")) . ' ';
}
$server_name = '';
$data[8] .= "". html_print_image ("images/binary.png", true, array ("border" => "0", "alt" => "")) . "";
}
if ($module['estado'] == 3) {
$data[9] = '';
}
else {
$data[9] = '';
}
$data[9] .= ui_print_timestamp ($module["utimestamp"], true, array('style' => 'font-size: 7pt'));
$data[9] .= '';
array_push ($table->data, $data);
$rowIndex++;
}
?>
data)) {
if ($filter_monitors) {
ui_print_info_message(array( 'no_close'=>true, "message" => __('Any monitors aren\'t with this filter.') ) );
}
else {
ui_print_info_message( array( 'no_close'=>true, "message" => __('This agent doesn\'t have any active monitors.') ) );
}
}
else {
$url = "index.php?" .
"sec=estado&" .
"sec2=operation/agentes/ver_agente&" .
"id_agente=" . $id_agente . "&" .
"refr=&filter_monitors=1&" .
"status_filter_monitor=" . $status_filter_monitor . "&" .
"status_text_monitor=" . $status_text_monitor . "&".
"status_module_group=" . $status_module_group;
if ($paginate_module) {
ui_pagination ($count_modules, false, 0, 0, false, 'offset',
true, '',
"pagination_list_modules(offset_param)",
array('count' => '', 'offset' => 'offset_param'));
}
html_print_table ($table);
if ($paginate_module) {
ui_pagination ($count_modules, false, 0, 0, false, 'offset',
true, '',
"pagination_list_modules(offset_param)",
array('count' => '', 'offset' => 'offset_param'));
}
}
unset ($table);
unset ($table_data);
}
if ($get_type) {
$id_module = (int) get_parameter("id_module");
$module = modules_get_agentmodule($id_module);
$graph_type = return_graphtype ($module["id_tipo_modulo"]);
echo $graph_type;
return;
}
if ($get_custom_fields_data){
$name_custom_fields = get_parameter("name_custom_fields", 0);
$array_custom_fields_data = get_custom_fields_data($name_custom_fields);
echo json_encode($array_custom_fields_data);
return;
}
if($build_table_custom_fields){
$order = get_parameter("order", '');
$length = get_parameter("length", 20);
$start = get_parameter("start", 0);
$draw = get_parameter("draw", 0);
$search = get_parameter("search", '');
$indexed_descriptions = json_decode(io_safe_output(get_parameter("indexed_descriptions", '')), true);
//order query
$order_column = $order[0]['column'];
$type_order = $order[0]['dir'];
switch ($order_column) {
default:
case '1':
$order_by = "ORDER BY temp.name_custom_fields " . $type_order;
break;
case '2':
$order_by = "ORDER BY tma.server_name " . $type_order;
break;
case '3':
$order_by = "ORDER BY tma.alias " . $type_order;
break;
case '4':
$order_by = "ORDER BY tma.direccion " . $type_order;
break;
}
//table temporary for save array in table by order and search custom_field data
$table_temporary = "CREATE TEMPORARY TABLE temp_custom_fields (
id_server int(10),
id_agent int(10),
name_custom_fields varchar(2048),
KEY `data_index_temp_1` (`id_server`, `id_agent`)
)";
db_process_sql($table_temporary);
//insert values array in table temporary
$values_insert = array();
foreach ($indexed_descriptions as $key => $value) {
$values_insert[] = "(".$value['id_server'].", ".$value['id_agente'].", '".$value['description']."')";
}
$values_insert_implode = implode(",", $values_insert);
$query_insert ="INSERT INTO temp_custom_fields VALUES ". $values_insert_implode;
db_process_sql($query_insert);
//search table for alias, custom field data, server_name, direction
$search_query = "";
if($search['value'] != ''){
$search_query = ' AND (tma.alias LIKE "%' . $search['value']. '%"';
$search_query .= ' OR tma.server_name LIKE "%' . $search['value']. '%"';
$search_query .= ' OR tma.direccion LIKE "%' . $search['value']. '%"';
$search_query .= ' OR temp.name_custom_fields LIKE "%' . $search['value']. '%" ) ';
}
//query all fields result
$query = sprintf("SELECT
tma.id_agente,
tma.id_tagente,
tma.id_tmetaconsole_setup,
tma.alias,
tma.direccion,
tma.server_name,
temp.name_custom_fields,
(CASE
WHEN tma.critical_count > 0
THEN 1
WHEN tma.critical_count = 0
AND tma.warning_count > 0
THEN 2
WHEN tma.critical_count = 0
AND tma.warning_count = 0
AND tma.unknown_count > 0
THEN 3
WHEN tma.critical_count = 0
AND tma.warning_count = 0
AND tma.unknown_count = 0
AND tma.notinit_count <> tma.total_count
THEN 0
WHEN tma.total_count = tma.notinit_count
THEN 5
ELSE 0
END) AS `status`
FROM tmetaconsole_agent tma
INNER JOIN temp_custom_fields temp
ON temp.id_agent = tma.id_tagente
AND temp.id_server = tma.id_tmetaconsole_setup
WHERE tma.disabled = 0
%s
%s
LIMIT %d OFFSET %d
",
$search_query,
$order_by,
$length,
$start
);
$result = db_get_all_rows_sql($query);
//query count
$query_count = sprintf("SELECT
COUNT(tma.id_agente) AS `count`
FROM tmetaconsole_agent tma
INNER JOIN temp_custom_fields temp
ON temp.id_agent = tma.id_tagente
AND temp.id_server = tma.id_tmetaconsole_setup
WHERE tma.disabled = 0
%s
",
$search_query
);
$count = db_get_sql($query_count);
//prepare rows for table dinamic
$data = array();
foreach ($result as $values) {
switch ($values['status']) {
case AGENT_STATUS_NORMAL:
$image_status = html_print_image(
'images/status_sets/default/agent_ok.png',
true,
array(
'title' => __('Agents ok')
)
);
break;
case AGENT_STATUS_CRITICAL:
$image_status = html_print_image(
'images/status_sets/default/agent_critical.png',
true,
array(
'title' => __('Agents critical')
)
);
break;
case AGENT_STATUS_WARNING:
$image_status = html_print_image(
'images/status_sets/default/agent_warning.png',
true,
array(
'title' => __('Agents warning')
)
);
break;
case AGENT_STATUS_UNKNOWN:
$image_status = html_print_image(
'images/status_sets/default/agent_down.png',
true,
array(
'title' => __('Agents unknown')
)
);
break;
case AGENT_STATUS_ALERT_FIRED:
$image_status = 'alert';
break;
case AGENT_STATUS_NOT_INIT:
$image_status = html_print_image(
'images/status_sets/default/agent_no_data.png',
true,
array(
'title' => __('Agents not init')
)
);
break;
default:
$image_status= html_print_image(
'images/status_sets/default/agent_ok.png',
true,
array(
'title' => __('Agents ok')
)
);
break;
}
$data[] = array(
"ref" => $referencia,
"data_custom_field" => $values['name_custom_fields'],
"server" => $values['server_name'],
"agent" => $values['alias'],
"IP" => $values['direccion'],
"status" => $image_status,
"id_agent" => $values['id_tagente'],
"id_server" => $values['id_tmetaconsole_setup']
);
}
$result = array(
"draw" => $draw,
"recordsTotal" => count($data),
"recordsFiltered" => $count,
"data" => $data
);
echo json_encode($result);
return;
}
if($build_table_child_custom_fields){
$id_agent = get_parameter("id_agent", 0);
$id_server = get_parameter("id_server", 0);
$module_search = str_replace('amp;', '',get_parameter("module_search", ''));
if(!$id_server || !$id_agent){
return false;
}
if($module_search != ''){
$name_where = " AND tam.nombre LIKE '%" . $module_search . "%'";
}
if (is_metaconsole()) {
$server = metaconsole_get_connection_by_id ($id_server);
metaconsole_connect($server);
}
$query = sprintf("SELECT tam.nombre,
tam.min_warning, tam.max_warning,
tam.min_critical, tam.max_critical,
tae.estado, tae.current_interval,
tae.utimestamp, tae.datos
FROM tagente_modulo tam
INNER JOIN tagente_estado tae
ON tam.id_agente_modulo = tae.id_agente_modulo
WHERE tam.id_agente = %d
%s",
$id_agent,
$name_where
);
hd($query, true, true);
$modules = db_get_all_rows_sql ($query);
$table_modules = new stdClass();
$table_modules->width = "100%";
$table_modules->class="databox data";
$table_modules->head = array();
$table_modules->head[0] = __('Name');
$table_modules->head[1] = __('Data');
$table_modules->head[2] = __('Min Warning');
$table_modules->head[3] = __('Max Warning');
$table_modules->head[4] = __('Min Critical');
$table_modules->head[5] = __('Max Critical');
$table_modules->head[6] = __('Current interval');
$table_modules->head[7] = __('Date');
$table_modules->head[8] = __('Status');
$table_modules->data = array();
if(isset($modules) && is_array($modules)){
foreach ($modules as $key => $value) {
$table_modules->data[$key][0] = $value['nombre'];
$table_modules->data[$key][1] = $value['datos'];
$table_modules->data[$key][2] = $value['min_warning'];
$table_modules->data[$key][3] = $value['max_warning'];
$table_modules->data[$key][4] = $value['min_critical'];
$table_modules->data[$key][5] = $value['max_critical'];
$table_modules->data[$key][6] = $value['current_interval'];
$table_modules->data[$key][7] = date('d/m/Y h:i:s', $value['utimestamp']);
switch ($value['estado']) {
case 0:
case 300:
$table_modules->data[$key][8] = html_print_image(
'images/status_sets/default/severity_normal.png',
true,
array(
'title' => __('Modules normal')
)
);
break;
case 1:
case 100:
$table_modules->data[$key][8] = html_print_image(
'images/status_sets/default/severity_critical.png',
true,
array(
'title' => __('Modules critical')
)
);
break;
case 2:
case 200:
$table_modules->data[$key][8] = html_print_image(
'images/status_sets/default/severity_warning.png',
true,
array(
'title' => __('Modules warning')
)
);
break;
case 3:
$table_modules->data[$key][8] = html_print_image(
'images/status_sets/default/severity_maintenance.png',
true,
array(
'title' => __('Modules unknown')
)
);
break;
case 4:
case 5:
$table_modules->data[$key][8] = html_print_image(
'images/status_sets/default/severity_informational.png',
true,
array(
'title' => __('Modules no init')
)
);
break;
default:
$table_modules->data[$key][8] = html_print_image(
'images/status_sets/default/severity_normal.png',
true,
array(
'title' => __('Modules normal')
)
);
break;
}
}
}
if (is_metaconsole()) {
metaconsole_restore_db();
}
html_print_table ($table_modules);
return;
}
}
?>