"ANY(SELECT id_agente FROM tagente WHERE id_grupo = " . $group);
db_process_sql_update('tagente_modulo', array("flag" => 1), $where);
}
else {
db_pandora_audit("ACL Violation", "Trying to set flag for groups");
require ("general/noaccess.php");
exit;
}
}
if ($config["realtimestats"] == 0) {
$updated_info = __('Last update'). " : ". ui_print_timestamp (db_get_sql ("SELECT min(utimestamp) FROM tgroup_stat"), true);
}
else {
// $updated_info = __("Updated at realtime");
$updated_info = "";
}
$updated_time = $updated_info;
$modulegroup = get_parameter('modulegroup', 0);
$refr = get_parameter('refr', 30); // By default 30 seconds
$group_id = (int)get_parameter('group_id', 0);
$offset = (int)get_parameter('offset', 0);
$hor_offset = (int)get_parameter('hor_offset', 0);
$block = $config['block_size'];
$agents_id = (array)get_parameter('id_agents2', -1);
$selection_a_m = (int)get_parameter('selection_agent_module');
$modules_selected = (array)get_parameter('module', 0);
$update_item = (string)get_parameter('edit_item','');
$save_serialize = (int)get_parameter('save_serialize', 0);
if($save_serialize && $update_item == ''){
$unserialize_modules_selected = unserialize_in_temp($config['id_user']."_agent_module", true, 1);
$unserialize_agents_id = unserialize_in_temp($config['id_user']."_agents", true, 1);
if($unserialize_modules_selected){
$modules_selected = $unserialize_modules_selected;
}
if($unserialize_agents_id){
$agents_id = $unserialize_agents_id;
}
}
else{
unserialize_in_temp($config['id_user']."_agent_module", true, 1);
unserialize_in_temp($config['id_user']."_agents", true, 1);
}
if($modules_selected[0]){
serialize_in_temp($modules_selected, $config['id_user']."_agent_module", 1);
}
if($agents_id[0] != -1 ){
serialize_in_temp($agents_id, $config['id_user']."_agents", 1);
}
$comborefr = '
";
if ($config["pure"] == 0) {
$fullscreen['text'] = ''
. html_print_image ("images/full_screen.png", true, array ("title" => __('Full screen mode')))
. "";
}
else {
$fullscreen['text'] = ''
. html_print_image ("images/normal_screen.png", true, array ("title" => __('Back to normal mode')))
. "";
$config['refr'] = $refr;
}
$groups = users_get_groups ();
//groups
$filter_groups_label = ''.__('Group').'';
$filter_groups = html_print_select_groups(false, "AR", true, 'group_id', $group_id, '', '', '', true, false, true, '', false , 'width: auto;');
//groups module
$filter_module_groups_label = ''.__('Module group').'';
$filter_module_groups = html_print_select_from_sql ("SELECT * FROM tmodule_group ORDER BY name",
'modulegroup', $modulegroup, '',__('All'), 0, true, false, true, false, 'width: auto;');
$agents_select = array();
if (is_array($id_agents) || is_object($id_agents)){
foreach ($id_agents as $id) {
foreach ($agents as $key => $a) {
if ($key == (int)$id) {
$agents_select[$key] = $key;
}
}
}
}
//agent
$agents = agents_get_group_agents($group_id);
if ((empty($agents)) || $agents == -1) $agents = array();
$filter_agents_label = ''.__('Agents').'';
$filter_agents = html_print_select($agents, 'id_agents2[]', $agents_id, '', '', 0, true, true, true, '', false, "min-width: 180px; max-width: 200px;");
//type show
$selection = array(0 => __('Show common modules'),
1=> __('Show all modules'));
$filter_type_show_label = ''.__('Show common modules').'';
$filter_type_show = html_print_select($selection, 'selection_agent_module', $selection_a_m, '', "", 0, true, false, true, '', false, "min-width: 180px;");
//modules
$all_modules = select_modules_for_agent_group($group_id, $agents_id, $selection_a_m, false);
$filter_modules_label = ''.__('Module').'';
$filter_modules = html_print_select($all_modules, 'module[]', $modules_selected, '', '', 0, true, true, true, '', false, "min-width: 180px; max-width: 200px;");
//update
$filter_update = html_print_submit_button(__('Update item'), 'edit_item', false, 'class="sub upd"', true);
$onheader = array('updated_time' => $updated_time, 'fullscreen' => $fullscreen,
'combo_module_groups' => $filter_module_groups,
'combo_groups' => $filter_groups);
if ($config['pure'] == 1) {
$onheader['combo_refr'] = $comborefr;
}
// Header
ui_print_page_header (__("Agents/Modules"), "images/module_mc.png", false, "", false, $updated_time);
// Old style table, we need a lot of special formatting,don't use table function
// Prepare old-style table
echo '';
echo "";
if ($config['pure'] == 1){
echo "" . $comborefr . " | ";
echo "" . $fullscreen['text'] . " | ";
}
else{
echo " " . $fullscreen['text'] . " | ";
}
echo "
";
echo "
";
if($config['pure'] != 1){
echo '';
}
if($agents_id[0] != -1){
$agents = $agents_id;
}
else {
$agents = '';
$agents = agents_get_group_agents($group_id,array('disabled' => 0));
$agents = array_keys($agents);
}
$filter_module_group = array('disabled' => 0);
if ($modulegroup > 0) {
$filter_module_group['id_module_group'] = $modulegroup;
}
$count = 0;
foreach ($agents as $agent) {
$module = agents_get_modules($agent, false,
$filter_module_group, true, true);
if ($module == false) {
unset($agents[$count]);
}
$count++;
}
$total_pagination = count($agents);
if($agents_id[0] != -1){
$all_modules = array();
foreach ($modules_selected as $key => $value) {
//$all_modules[$value] = io_safe_output(modules_get_agentmodule_name($value));
$name = modules_get_agentmodule_name($value);
$sql = "SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre = '". $name ."';";
$result_sql = db_get_all_rows_sql($sql);
if(is_array($result_sql)){
foreach ($result_sql as $key => $value) {
$all_modules[$value['id_agente_modulo']] = io_safe_output($name);
}
}
}
}
else{
$all_modules = agents_get_modules($agents, false,
$filter_module_group, true, true);
}
$modules_by_name = array();
$name = '';
$cont = 0;
foreach ($all_modules as $key => $module) {
if ($module == $name) {
$modules_by_name[$cont-1]['id'][] = $key;
}
else {
$name = $module;
$modules_by_name[$cont]['name'] = $name;
$modules_by_name[$cont]['id'][] = $key;
$cont ++;
}
}
if ($config["pure"] == 1) {
$block = count($modules_by_name);
}
if($update_item == ''){
$filter_groups = array ('offset' => (int) $offset,
'limit' => (int) $config['block_size'], 'disabled' => 0,'id_agente'=>$agents);
}
else{
$filter_groups = array ('offset' => 0,
'limit' => (int) $config['block_size'], 'disabled' => 0,'id_agente'=>$agents);
}
if ($group_id > 0) {
$filter_groups['id_grupo'] = $group_id;
}
$agents = agents_get_agents ($filter_groups);
$nagents = count($agents);
if ($all_modules == false || $agents == false) {
ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no agents with modules') ) );
return;
}
echo '';
echo "";
echo "" . __("Agents") . " / " . __("Modules") . " | ";
if ($hor_offset > 0) {
$new_hor_offset = $hor_offset-$block;
echo "" .
"" .
html_print_image("images/arrow_left.png", true,
array('title' => __('Previous modules'))) .
"" .
" | ";
}
$nmodules = 0;
foreach ($modules_by_name as $module) {
$nmodules++;
if ($nmodules <= $hor_offset || $nmodules > ($hor_offset+$block)) {
continue;
}
$text = ui_print_truncate_text(io_safe_output($module['name']), 'module_small');
echo '
| ';
}
if (($hor_offset + $block) < $nmodules) {
$new_hor_offset = $hor_offset+$block;
echo "" .
"" .
html_print_image(
"images/arrow.png", true,
array('title' => __('More modules'))) .
"" .
" | ";
}
echo "
";
$filter_agents = array('offset' => (int) $offset, 'disabled' => 0);
if ($group_id > 0) {
$filter_agents['id_grupo'] = $group_id;
}
// Prepare pagination
$url = 'index.php?extension_in_menu=estado&sec=extensions&sec2=extensions/agents_modules&save_serialize=1&' . "hor_offset=" . $hor_offset ."&selection_a_m=" . $selection_a_m;
ui_pagination ($total_pagination, $url);
foreach ($agents as $agent) {
// Get stats for this group
$agent_status = agents_get_status($agent['id_agente']);
$alias = db_get_row ("tagente", "id_agente", $agent['id_agente']);
if (empty($alias['alias'])){
$alias['alias'] = $agent['nombre'];
}
switch($agent_status) {
case 4: // Alert fired status
$rowcolor = 'group_view_alrm';
break;
case 1: // Critical status
$rowcolor = 'group_view_crit';
break;
case 2: // Warning status
$rowcolor = 'group_view_warn';
break;
case 0: // Normal status
$rowcolor = "group_view_ok";
break;
case 3:
case -1:
default: // Unknown status
$rowcolor = 'group_view_unk';
break;
}
echo "";
echo "
" .
$alias['alias'] .
" | ";
$agent_modules = agents_get_modules($agent['id_agente'], false, $filter_module_group, true, true);
$nmodules = 0;
foreach ($modules_by_name as $module) {
$nmodules++;
if ($nmodules <= $hor_offset || $nmodules > ($hor_offset+$block)) {
continue;
}
$match = false;
foreach ($module['id'] as $module_id) {
if (!$match && array_key_exists($module_id,$agent_modules)) {
$status = modules_get_agentmodule_status($module_id);
echo "";
$win_handle = dechex(crc32($module_id.$module["name"]));
$graph_type = return_graphtype (modules_get_agentmodule_type($module_id));
$link ="winopeng('" .
"operation/agentes/stat_win.php?" .
"type=$graph_type&" .
"period=" . SECONDS_1DAY . "&" .
"id=" . $module_id . "&" .
"label=" . rawurlencode(
urlencode(
base64_encode($module["name"]))) . "&" .
"refresh=" . SECONDS_10MINUTES . "', 'day_".$win_handle."')";
echo '';
switch ($status) {
case AGENT_MODULE_STATUS_NORMAL:
ui_print_status_image ('module_ok.png', modules_get_last_value($module_id), false, array('width' => '20px', 'height' => '20px'));
break;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
ui_print_status_image ('module_critical.png', modules_get_last_value($module_id), false, array('width' => '20px', 'height' => '20px'));
break;
case AGENT_MODULE_STATUS_WARNING:
ui_print_status_image ('module_warning.png', modules_get_last_value($module_id), false, array('width' => '20px', 'height' => '20px'));
break;
case AGENT_MODULE_STATUS_UNKNOWN:
ui_print_status_image ('module_unknown.png', modules_get_last_value($module_id), false, array('width' => '20px', 'height' => '20px'));
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
ui_print_status_image ('module_alertsfired.png', modules_get_last_value($module_id), false, array('width' => '20px', 'height' => '20px'));
break;
case 4:
ui_print_status_image ('module_no_data.png', modules_get_last_value($module_id), false, array('width' => '20px', 'height' => '20px'));
break;
}
echo '';
echo " | ";
$match = true;
}
}
if (!$match) {
echo " | ";
}
}
echo "
";
}
echo "
";
echo "";
echo "
";
echo "" . __('Legend') . " |
";
echo " | " . __("Orange cell when the module has fired alerts") . " |
";
echo " | " . __("Red cell when the module has a critical status") . " |
";
echo " | " . __("Yellow cell when the module has a warning status") . " |
";
echo " | " . __("Green cell when the module has a normal status") . " |
";
echo " | " . __("Grey cell when the module has an unknown status") . " |
";
echo " | " . __("Cell turns grey when the module is in 'not initialize' status") . " |
";
echo "
";
echo "
";
echo "
";
}
extensions_add_operation_menu_option(__("Agents/Modules view"), 'estado', 'agents_modules/icon_menu.png', "v1r1","view");
extensions_add_main_function('mainAgentsModules');
?>