user = $user; $this->system = $system; $this->filterText = $this->system->getRequest('filter_text', ''); $this->filterGroup = $this->system->getRequest('filter_group', 0);; } private function showForm() { echo "
"; html_print_input_hidden('page', 'agents'); global $config; $config['text_char_long'] = 12; html_print_select_groups($this->user->getIdUser(), "AR", true, 'filter_group', $this->filterGroup); html_print_input_text('filter_text', $this->filterText, __('Free text search'), 5, 20); echo ""; echo ""; } public function show() { $this->showForm(); // Show only selected groups if ($this->filterGroup > 0) { $groups = $this->filterGroup; $agent_names = agents_get_group_agents ($this->filterGroup, array('string' => $this->filterText), "upper"); // Not selected any specific group } else { $user_group = users_get_groups ($this->user->getIdUser(), "AR"); $groups = array_keys ($user_group); $agent_names = agents_get_group_agents (array_keys ($user_group), array('string' => $this->filterText), "upper"); } $total_agents = agents_get_agents (array('id_agente' => array_keys ($agent_names), 'order' => 'nombre ASC', 'disabled' => 0, 'id_grupo' => $groups), array ('COUNT(*) as total')); $total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0; $agents = agents_get_agents(array('id_agente' => array_keys ($agent_names), 'order' => 'nombre ASC', 'id_grupo' => $groups, 'offset' => (int) get_parameter ('offset'), 'limit' => (int) $this->system->getPageSize()), array('id_agente', 'nombre', 'id_grupo')); $table = null; $table->width = '100%'; $table->align = array(); $table->align[0] = 'center'; $table->align[2] = 'center'; $table->align[3] = 'center'; $table->align[4] = 'center'; $table->head = array(); $table->head[0] = '' . __('G') . ''; $table->head[1] = __('Name'); $table->head[2] = '' . __('M') . ''; $table->head[3] = '' . __('S') . ''; $table->head[4] = '' . __('A') . ''; $table->data = array(); if ($agents === false) $agents = array(); $iterator = 0; $rowPair = false; foreach ($agents as $agent) { if ($rowPair) $table->rowclass[$iterator] = 'rowPair'; else $table->rowclass[$iterator] = 'rowOdd'; $rowPair = !$rowPair; $iterator++; $agent_info = reporting_get_agent_module_info ($agent["id_agente"]); //$this->system->debug($agent_info); $data = array(); $truncName = ui_print_truncate_text($agent['nombre'], 25, true, true); $data[] = ui_print_group_icon_path($agent["id_grupo"], true, "../images/groups_small", '', false); $data[] = '' . $truncName . ''; $moduleInfo = ''; $moduleInfo .= $agent_info["modules"]; if ($agent_info["monitor_alertsfired"] > 0) $moduleInfo .= ' : '.$agent_info["monitor_alertsfired"].''; if ($agent_info["monitor_critical"] > 0) $moduleInfo .= ' : '.$agent_info["monitor_critical"].''; if ($agent_info["monitor_warning"] > 0) $moduleInfo .= ' : '.$agent_info["monitor_warning"].''; if ($agent_info["monitor_unknown"] > 0) $moduleInfo .= ' : '.$agent_info["monitor_unknown"].''; if ($agent_info["monitor_normal"] > 0) $moduleInfo .= ' : '.$agent_info["monitor_normal"].''; $moduleInfo .= ''; $data[] = $moduleInfo; $data[] = ''; $data[] = ''; $table->data[] = $data; } html_print_table($table); $pagination = pagination ($total_agents, ui_get_url_refresh (array ('filter_group' => $this->filterGroup, 'filter_group' => $this->filterGroup)), 0, 0, true); $pagination = str_replace('images/go_first.png', '../images/go_first.png', $pagination); $pagination = str_replace('images/go_previous.png', '../images/go_previous.png', $pagination); $pagination = str_replace('images/go_next.png', '../images/go_next.png', $pagination); $pagination = str_replace('images/go_last.png', '../images/go_last.png', $pagination); echo $pagination; } } class ViewAgent { private $idAgent; private $sytem; private $agent; private $name; private $os; private $ips; private $modules; public function __construct() { global $system; $this->system = $system; $this->idAgent = $this->system->getRequest('id', 0); $this->agent = db_get_row_filter('tagente', array('id_agente' => $this->idAgent)); $this->ips = agents_get_addresses($this->idAgent); } public function show() { $idGroup = $this->agent['id_grupo']; if (! check_acl ($this->system->getConfig('id_user'), $idGroup, "AR")) { db_pandora_audit("ACL Violation", "Trying to access (read) to agent ".agents_get_name($this->idAgent)); include ("../general/noaccess.php"); return; } $table = null; $table->width = '100%'; $table->style[0] = 'font-weight: bolder;'; $table->data[0][0] = __('Name:'); $table->data[0][1] = $this->agent['nombre']; $table->data[1][0] = __('IP:'); $table->data[1][1] = implode(',', $this->ips); $table->data[2][0] = __('OS:'); $table->data[2][1] = str_replace('images/os_icons/', '../images/os_icons/', ui_print_os_icon($this->agent['id_os'], true, true)); $table->data[3][0] = __('Last contact'); $table->data[3][1] = $this->agent['ultimo_contacto']; html_print_table($table); $sql = sprintf (" SELECT * FROM tagente_estado, tagente_modulo LEFT JOIN tmodule_group ON tmodule_group.id_mg = tagente_modulo.id_module_group WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_agente = %d AND tagente_modulo.disabled = 0 AND tagente_modulo.delete_pending = 0 AND tagente_estado.utimestamp != 0 ORDER BY tagente_modulo.id_module_group , tagente_modulo.nombre ASC ", $this->idAgent); $modules = db_get_all_rows_sql ($sql); if (empty ($modules)) { $modules = array (); } echo "

" . __('Modules') . "

"; $table = null; //$table->width = '100%'; $table->head = array(); $table->head[0] = __('Module'); $table->head[1] = '' . __('S') . ''; $table->head[2] = __('Data'); $table->head[3] = '' . __('L') . ''; $table->data = array(); $iterator = 0; $rowPair = false; foreach ($modules as $module) { if ($rowPair) $table->rowclass[$iterator] = 'rowPair'; else $table->rowclass[$iterator] = 'rowOdd'; $rowPair = !$rowPair; $iterator++; $data = array(); $data[] = '' . ui_print_truncate_text($module["nombre"], 20, true, true) . ''; $status = STATUS_MODULE_WARNING; $title = ""; if ($module["estado"] == 1) { $status = STATUS_MODULE_CRITICAL; $title = __('CRITICAL'); } elseif ($module["estado"] == 2) { $status = STATUS_MODULE_WARNING; $title = __('WARNING'); } elseif ($module["estado"] == 0) { $status = STATUS_MODULE_OK; $title = __('NORMAL'); } elseif ($module["estado"] == 3) { $last_status = modules_get_agentmodule_last_status($module['id_agente_modulo']); switch($last_status) { case 0: $status = STATUS_MODULE_OK; $title = __('UNKNOWN')." - ".__('Last status')." ".__('NORMAL'); break; case 1: $status = STATUS_MODULE_CRITICAL; $title = __('UNKNOWN')." - ".__('Last status')." ".__('CRITICAL'); break; case 2: $status = STATUS_MODULE_WARNING; $title = __('UNKNOWN')." - ".__('Last status')." ".__('WARNING'); break; } } if (is_numeric($module["datos"])) { $title .= ": " . format_for_graph($module["datos"]); } else { $title .= ": " . substr(io_safe_output($module["datos"]),0,42); } $data[] = str_replace(array('images/status_sets', '".substr(io_safe_output($module["datos"]),0,12).""; } } $data[] = $salida; if ($module['estado'] == 3) { $lastTime = ''; } else { $lastTime = ''; } $lastTime .= ui_print_timestamp ($module["utimestamp"], true, array('units' => 'tiny')); $lastTime .= ''; $data[] = $lastTime; $table->data[] = $data; } html_print_table($table); $table->head = array(); $table->head[0] = __('Module'); $table->head[1] = __('Template'); $table->head[2] = '' . __('Last') . ''; $table->head[3] = '' . __('S') . ''; $table->align = array(); $table->align[3] = 'right'; $table->align[2] = 'center'; $table->data = array(); $table->rowclass = array(); echo "

" . __('Alerts') . "

"; $alertsSimple = agents_get_alerts_simple (array($this->idAgent)); $rowPair = false; $iterator = 0; foreach ($alertsSimple as $alert) { if ($rowPair) $table->rowclass[$iterator] = 'rowPair'; else $table->rowclass[$iterator] = 'rowOdd'; $rowPair = !$rowPair; $iterator++; $data = array(); $data[] = ui_print_truncate_text(modules_get_agentmodule_name($alert["id_agent_module"]), 20, true, true); $template = io_safe_output(alerts_get_alert_template ($alert['id_alert_template'])); $data[] = ui_print_truncate_text(io_safe_output($template['name']), 20, true, true); $data[] = ui_print_timestamp ($alert["last_fired"], true, array('units' => 'tiny')); $status = STATUS_ALERT_NOT_FIRED; $title = ""; if ($alert["times_fired"] > 0) { $status = STATUS_ALERT_FIRED; $title = __('Alert fired').' '.$alert["times_fired"].' '.__('times'); } elseif ($alert["disabled"] > 0) { $status = STATUS_ALERT_DISABLED; $title = __('Alert disabled'); } else { $status = STATUS_ALERT_NOT_FIRED; $title = __('Alert not fired'); } $data[] = str_replace(array('images/status_sets', 'data[] = $data; } html_print_table($table); } } class viewGraph { private $system; private $idAgentModule; function __construct($idAgentModule = 0) { global $system; $this->system = $system; $this->idAgentModule = $idAgentModule; $this->agentModule = db_get_row_filter('tagente_modulo', array('id_agente_modulo' => $this->idAgentModule)); $this->period = $this->system->getRequest('period', 86400); $this->offset = $this->system->getRequest("offset", 0); $this->agent = db_get_row_filter('tagente', array('id_agente' => $this->agentModule['id_agente'])); } function show() { $idGroup = $this->agent['id_grupo']; if (! check_acl ($this->system->getConfig('id_user'), $idGroup, "AR")) { db_pandora_audit("ACL Violation", "Trying to access (read) to agent ".agents_get_name($this->idAgent)); include ("../general/noaccess.php"); return; } echo "

" . modules_get_agentmodule_agent_name($this->idAgentModule)." / ".io_safe_output($this->agentModule['nombre']) . "

"; echo "

" . __('Graph') . "

"; echo grafico_modulo_sparse($this->idAgentModule, $this->period, 0, 240, 120, io_safe_output($this->agentModule['nombre']), null, true, 0, true, 0, true, true, true, true); echo "

" . __('Data') . "

"; echo ""; echo __("Choose period:"); $intervals = array (); $intervals[3600] = human_time_description_raw (3600); // 1 hour $intervals[86400] = human_time_description_raw (86400); // 1 day $intervals[604800] = human_time_description_raw (604800); // 1 week $intervals[2592000] = human_time_description_raw (2592000); // 1 month echo html_print_extended_select_for_time ($intervals, 'period', $this->period, 'this.form.submit();', '', '0', 5) . __(" secs"); echo "
"; $moduletype_name = modules_get_moduletype_name (modules_get_agentmodule_type ($this->idAgentModule)); if ($moduletype_name == "log4x") { $sql_body = sprintf ("FROM tagente_datos_log4x WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $this->idAgentModule, (get_system_time () - $this->period)); $columns = array( //"Timestamp" => array("utimestamp", "modules_format_timestamp", "align" => "center" ), "Sev" => array("severity", "format_data", "align" => "center", "width" => "70px"), "Message" => array("message", "modules_format_verbatim", "align" => "left", "width" => "45%"), "StackTrace" => array("stacktrace", "modules_format_verbatim", "align" => "left", "width" => "50%") ); } else if (preg_match ("/string/", $moduletype_name)) { $sql_body = sprintf (" FROM tagente_datos_string WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $this->idAgentModule, (get_system_time () - $this->period)); $columns = array( //"Timestamp" => array("utimestamp", "modules_format_timestamp", "align" => "center"), "Data" => array("datos", "format_data", "align" => "center"), "Time" => array("utimestamp", "modules_format_time", "align" => "center") ); } else { $sql_body = sprintf (" FROM tagente_datos WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY utimestamp DESC", $this->idAgentModule, (get_system_time () - $this->period)); $columns = array( "Data" => array("datos", "format_data", "align" => "center"), "Time" => array("utimestamp", "modules_format_time", "align" => "center") ); } $sql_count = 'SELECT COUNT(*) ' . $sql_body; $count = db_get_value_sql($sql_count); switch ($config["dbtype"]) { case "mysql": $sql = 'SELECT * ' . $sql_body . ' LIMIT ' . $this->offset . ',' . $this->system->getPageSize(); break; case "postgresql": $sql = 'SELECT * ' . $sql_body . ' LIMIT ' . $this->system->getPageSize() . ' OFFSET ' . $this->offset; break; case "oracle": $set = array(); $set['limit'] = $this->system->getPageSize(); $set['offset'] = $this->offset; $sql = oracle_recode_query ('SELECT * ' . $sql_body, $set); break; } $result = db_get_all_rows_sql ($sql); if (($config["dbtype"] == 'oracle') && ($result !== false)) { // Delete rnum row generated by oracle_recode_query() function for ($i=0; $i < count($result); $i++) { unset($result[$i]['rnum']); } } $table = null; $table->width = '100%'; $table->head = 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++; } $table->data = array(); //$this->system->debug($result); $rowPair = false; $iterator = 0; foreach ($result as $row) { if ($rowPair) $table->rowclass[$iterator] = 'rowPair'; else $table->rowclass[$iterator] = 'rowOdd'; $rowPair = !$rowPair; $iterator++; $data = array (); foreach($columns as $col => $attr){ $data[] = $attr[1] ($row[$attr[0]]); } array_push ($table->data, $data); } html_print_table($table); $pagination = ui_pagination ($count, ui_get_url_refresh (array ('period' => $this->period)), 0, 0, true); $pagination = str_replace('images/go_first.png', '../images/go_first.png', $pagination); $pagination = str_replace('images/go_previous.png', '../images/go_previous.png', $pagination); $pagination = str_replace('images/go_next.png', '../images/go_next.png', $pagination); $pagination = str_replace('images/go_last.png', '../images/go_last.png', $pagination); echo $pagination; } } ?>