2010-08-09 11:14:46 +02:00
< ? php
2019-03-27 12:29:15 +01:00
/**
2021-04-29 13:28:03 +02:00
* Agents / Modules Monitoring view .
*
* @ category Operations
* @ package Pandora FMS
* @ subpackage Opensource
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
2023-06-08 12:42:10 +02:00
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
2021-04-29 13:28:03 +02:00
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
2023-06-08 11:53:13 +02:00
* Copyright ( c ) 2005 - 2023 Pandora FMS
2023-06-08 13:19:01 +02:00
* Please see https :// pandorafms . com / community / for full contribution list
2021-04-29 13:28:03 +02:00
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* ============================================================================
2019-03-27 12:29:15 +01:00
*/
2019-11-21 18:21:46 +01:00
// Begin.
2011-03-23 Raul Mateos <raulofpandora@gmail.com>
* extensions/ssh_console.php, extensions/vnc_view.php,
extensions/update_manager.php, extensions/users_connected.php,
extensions/extension_uploader.php, extensions/insert_data.php,
extensions/module_groups.php, extensions/plugin_registration.php,
extensions/agent_modules.php, extensions/resource_registration.php,
extensions/resource_exportation.php, extensions/dbmanager.php,
extensions/pandora_logs.php, general/*.php, ajax.php,
operation/search_*.php, operation/menu.php, operation/extensions.php,
godmode/menu.php, godmode/extensions.php, godmode/admin_access_logs.php:
CReverted unwanted license changes.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4126 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-03-23 17:13:28 +01:00
2019-11-21 18:21:46 +01:00
/**
* Extra JS .
*
* @ return void
*/
function agents_modules_load_js ()
{
$ignored_params [ 'refresh' ] = '' ;
?>
< script type = 'text/javascript' >
$ ( document ) . ready ( function () {
//Get max width of name of modules
max_width = 0 ;
$ . each ( $ ( '.th_class_module_r' ), function ( i , elem ) {
id = $ ( elem ) . attr ( 'id' ) . replace ( 'th_module_r_' , '' );
width = $ ( " #div_module_r_ " + id ) . width ();
if ( max_width < width ) {
max_width = width ;
}
});
2023-12-26 09:16:12 +01:00
loadRecursionGroups ();
2019-11-21 18:21:46 +01:00
$ . each ( $ ( '.th_class_module_r' ), function ( i , elem ) {
id = $ ( elem ) . attr ( 'id' ) . replace ( 'th_module_r_' , '' );
$ ( " #th_module_r_ " + id ) . height (( $ ( " #div_module_r_ " + id ) . width () + 10 ) + 'px' );
$ ( " #div_module_r_ " + id ) . css ( 'margin-top' , ( max_width - 20 ) + 'px' );
$ ( " #div_module_r_ " + id ) . show ();
});
var refr = '<?php echo get_parameter(' refresh ', 0); ?>' ;
var pure = '<?php echo get_parameter(' pure ', 0); ?>' ;
var href = ' <?php echo ui_get_url_refresh($ignored_params); ?>' ;
if ( pure ) {
var startCountDown = function ( duration , cb ) {
$ ( 'div.vc-countdown' ) . countdown ( 'destroy' );
if ( ! duration ) return ;
var t = new Date ();
t . setTime ( t . getTime () + duration * 1000 );
$ ( 'div.vc-countdown' ) . countdown ({
until : t ,
format : 'MS' ,
layout : '(%M%nn%M:%S%nn%S <?php echo __(' Until next '); ?>) ' ,
alwaysExpire : true ,
onExpiry : function () {
$ ( 'div.vc-countdown' ) . countdown ( 'destroy' );
url = js_html_entity_decode ( href ) + duration ;
$ ( document ) . attr ( " location " , url );
}
});
}
if ( refr > 0 ){
startCountDown ( refr , false );
}
var controls = document . getElementById ( 'vc-controls' );
autoHideElement ( controls , 1000 );
2021-12-07 09:05:50 +01:00
2019-11-21 18:21:46 +01:00
$ ( 'select#refresh' ) . change ( function ( event ) {
refr = Number . parseInt ( event . target . value , 10 );
startCountDown ( refr , false );
});
}
else {
var agentes_id = $ ( " #id_agents2 " ) . val ();
var id_agentes = getQueryParam ( " full_agents_id " );
if ( agentes_id === null && id_agentes !== null ) {
id_agentes = id_agentes . split ( " ; " )
id_agentes . forEach ( function ( element ) {
$ ( " #id_agents2 option[value= " + element + " ] " ) . attr ( " selected " , true );
});
2021-12-07 09:05:50 +01:00
2019-11-21 18:21:46 +01:00
selection_agent_module ();
}
2021-12-07 09:05:50 +01:00
2019-11-21 18:21:46 +01:00
$ ( '#refresh' ) . change ( function () {
$ ( '#hidden-vc_refr' ) . val ( $ ( '#refresh option:selected' ) . val ());
});
}
2021-12-07 09:05:50 +01:00
2019-11-21 18:21:46 +01:00
$ ( " #group_id " ) . change ( function () {
jQuery . post ( " ajax.php " ,
{ " page " : " operation/agentes/ver_agente " ,
" get_agents_group_json " : 1 ,
" id_group " : this . value ,
" privilege " : " AW " ,
" keys_prefix " : " _ " ,
" recursion " : $ ( '#checkbox-recursion' ) . is ( ':checked' )
},
function ( data , status ) {
$ ( " #id_agents2 " ) . html ( '' );
$ ( " #module " ) . html ( '' );
jQuery . each ( data , function ( id , value ) {
// Remove keys_prefix from the index
id = id . substring ( 1 );
option = $ ( " <option></option> " )
. attr ( " value " , value [ " id_agente " ])
. html ( value [ " alias " ]);
$ ( " #id_agents " ) . append ( option );
$ ( " #id_agents2 " ) . append ( option );
});
},
" json "
);
});
2021-12-07 09:05:50 +01:00
2019-11-21 18:21:46 +01:00
$ ( " #checkbox-recursion " ) . change ( function () {
2023-12-26 09:16:12 +01:00
loadRecursionGroups ();
2019-11-21 18:21:46 +01:00
});
2021-12-07 09:05:50 +01:00
2019-11-21 18:21:46 +01:00
$ ( " #modulegroup " ) . change ( function () {
jQuery . post ( " ajax.php " ,
{ " page " : " operation/agentes/ver_agente " ,
" get_modules_group_json " : 1 ,
" id_module_group " : this . value ,
" id_agents " : $ ( " #id_agents2 " ) . val (),
" selection " : $ ( " #selection_agent_module " ) . val ()
},
function ( data , status ) {
$ ( " #module " ) . html ( '' );
if ( data ){
jQuery . each ( data , function ( id , value ) {
option = $ ( " <option></option> " )
2021-12-07 09:05:50 +01:00
. attr ( " value " , id )
. html ( value );
2019-11-21 18:21:46 +01:00
$ ( " #module " ) . append ( option );
});
}
},
" json "
);
});
$ ( " #id_agents2 " ) . click ( function (){
selection_agent_module ();
});
$ ( " #selection_agent_module " ) . change ( function () {
jQuery . post ( " ajax.php " ,
{ " page " : " operation/agentes/ver_agente " ,
" get_modules_group_json " : 1 ,
" id_module_group " : $ ( " #modulegroup " ) . val (),
" id_agents " : $ ( " #id_agents2 " ) . val (),
" selection " : $ ( " #selection_agent_module " ) . val ()
},
function ( data , status ) {
$ ( " #module " ) . html ( '' );
if ( data ){
jQuery . each ( data , function ( id , value ) {
option = $ ( " <option></option> " )
2021-12-07 09:05:50 +01:00
. attr ( " value " , id )
. html ( value );
2019-11-21 18:21:46 +01:00
$ ( " #module " ) . append ( option );
});
}
},
" json "
);
});
});
function selection_agent_module () {
jQuery . post ( " ajax.php " ,
{ " page " : " operation/agentes/ver_agente " ,
" get_modules_group_json " : 1 ,
" id_module_group " : $ ( " #modulegroup " ) . val (),
" id_agents " : $ ( " #id_agents2 " ) . val (),
" selection " : $ ( " #selection_agent_module " ) . val ()
},
function ( data , status ) {
$ ( " #module " ) . html ( '' );
if ( data ){
jQuery . each ( data , function ( id , value ) {
option = $ ( " <option></option> " )
2021-12-07 09:05:50 +01:00
. attr ( " value " , id )
. html ( value );
2019-11-21 18:21:46 +01:00
$ ( " #module " ) . append ( option );
});
2021-12-07 09:05:50 +01:00
2019-11-21 18:21:46 +01:00
var id_modules = getQueryParam ( " full_modules_selected " );
if ( id_modules !== null ) {
id_modules = id_modules . split ( " ; " );
id_modules . forEach ( function ( element ) {
$ ( " #module option[value= " + element + " ] " ) . attr ( " selected " , true );
});
}
}
},
" json "
);
}
2021-12-07 09:05:50 +01:00
function getQueryParam ( key ) {
key = key . replace ( / [[] / , '[' );
key = key . replace ( / []] / , ']' );
var pattern = " [?&] " + key + " =([^&#]*) " ;
2019-11-21 18:21:46 +01:00
var regex = new RegExp ( pattern );
var url = unescape ( window . location . href );
var results = regex . exec ( url );
2021-12-07 09:05:50 +01:00
if ( results === null ) {
return null ;
} else {
return results [ 1 ];
}
2019-11-21 18:21:46 +01:00
}
2023-03-30 13:56:53 +02:00
function select_selected () {
2023-08-21 11:33:26 +02:00
var f = document . forms . filter_form ;
f . action = " index.php?sec=view&sec2=extensions/agents_modules " ;
$ ( '#filter_form' ) . submit ();
2023-03-30 13:56:53 +02:00
}
2023-12-26 09:16:12 +01:00
function loadRecursionGroups () {
jQuery . post ( " ajax.php " ,
{ " page " : " operation/agentes/ver_agente " ,
" get_agents_group_json " : 1 ,
" id_group " : $ ( " #group_id " ) . val (),
" privilege " : " AW " ,
" keys_prefix " : " _ " ,
" recursion " : $ ( '#checkbox-recursion' ) . is ( ':checked' )
},
function ( data , status ) {
$ ( " #id_agents2 " ) . html ( '' );
$ ( " #module " ) . html ( '' );
jQuery . each ( data , function ( id , value ) {
// Remove keys_prefix from the index
id = id . substring ( 1 );
option = $ ( " <option></option> " )
. attr ( " value " , value [ " id_agente " ])
. html ( value [ " alias " ]);
$ ( " #id_agents " ) . append ( option );
$ ( " #id_agents2 " ) . append ( option );
});
},
" json "
);
}
2023-07-13 13:12:43 +02:00
/* <![CDATA[ */
function export_csv () {
let group_id = $ ( '#group_id option:selected' ) . val ();
let module_group_id = $ ( '#modulegroup option:selected' ) . val ();
let agent_id = $ ( '#id_agents2 option:selected' ) . map (( _ , e ) => e . value ) . get ();
let module_id = $ ( '#module option:selected' ) . map (( _ , e ) => e . value ) . get ();
let filters_array = { group_id : group_id , module_group_id : module_group_id , agent_id : agent_id , module_id : module_id }
let jsonFilters = JSON . stringify ( filters_array )
let filters = window . btoa ( jsonFilters )
var f = document . forms . filter_form ;
blockResubmit ( $ ( this ));
f . action = " extensions/agents_modules_csv.php?get_agents_module_csv=1&filters= " + filters ;
$ ( " #filter_form " ) . submit ();
}
/* ]]> */
2019-11-21 18:21:46 +01:00
</ script >
< ? php
}
/**
* Main method .
*
* @ return void
*/
2019-01-30 16:18:44 +01:00
function mainAgentsModules ()
{
global $config ;
2019-03-27 12:29:15 +01:00
// Load global vars.
2019-01-30 16:18:44 +01:00
include_once 'include/config.php' ;
include_once 'include/functions_reporting.php' ;
include_once $config [ 'homedir' ] . '/include/functions_agents.php' ;
include_once $config [ 'homedir' ] . '/include/functions_modules.php' ;
include_once $config [ 'homedir' ] . '/include/functions_users.php' ;
check_login ();
2019-03-27 12:29:15 +01:00
// ACL Check.
2019-01-30 16:18:44 +01:00
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'AR' )) {
db_pandora_audit (
2022-01-20 10:55:23 +01:00
AUDIT_LOG_ACL_VIOLATION ,
2019-01-30 16:18:44 +01:00
'Trying to access Agent view (Grouped)'
);
include 'general/noaccess.php' ;
exit ;
}
2019-11-21 18:21:46 +01:00
// JS.
agents_modules_load_js ();
2019-01-30 16:18:44 +01:00
// Update network modules for this group
// Check for Network FLAG change request
2019-03-27 12:29:15 +01:00
// Made it a subquery, much faster on both the database and server side.
2019-01-30 16:18:44 +01:00
if ( isset ( $_GET [ 'update_netgroup' ])) {
$group = get_parameter_get ( 'update_netgroup' , 0 );
if ( check_acl ( $config [ 'id_user' ], $group , 'AW' )) {
$where = [ 'id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = ' . $group ];
db_process_sql_update ( 'tagente_modulo' , [ 'flag' => 1 ], $where );
} else {
2022-01-20 10:55:23 +01:00
db_pandora_audit (
AUDIT_LOG_ACL_VIOLATION ,
'Trying to set flag for groups'
);
2019-01-30 16:18:44 +01:00
include '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 = ( int ) get_parameter ( 'refresh' , 0 );
2019-03-27 12:29:15 +01:00
// By default 30 seconds.
2019-01-30 16:18:44 +01:00
$recursion = get_parameter ( 'recursion' , 0 );
$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' ];
2021-09-06 17:16:49 +02:00
if ( intval ( $block ) > 15 ) {
$block = '15' ;
}
2019-01-30 16:18:44 +01:00
if ( get_parameter ( 'modulegroup' ) != null ) {
$agents_id = ( array ) get_parameter ( 'id_agents2' , null );
}
$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 );
$full_modules_selected = explode ( ';' , get_parameter ( 'full_modules_selected' , 0 ));
$full_agents_id = explode ( ';' , get_parameter ( 'full_agents_id' , 0 ));
2022-03-17 14:48:01 +01:00
$show_type = ( int ) get_parameter ( 'show_type' , 0 );
2019-01-30 16:18:44 +01:00
2019-06-18 14:54:40 +02:00
// In full screen there is no pagination neither filters.
if (( ( $config [ 'pure' ] == 0 && $save_serialize ) && $update_item == '' ) || ( ( $config [ 'pure' ] == 1 && $save_serialize == 0 ) && $update_item == '' )) {
2019-01-30 16:18:44 +01:00
$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 );
}
2022-03-17 14:48:01 +01:00
if ( isset ( $modules_selected [ 0 ]) === true && $modules_selected [ 0 ]) {
2019-01-30 16:18:44 +01:00
serialize_in_temp ( $modules_selected , $config [ 'id_user' ] . '_agent_module' , 1 );
}
2022-03-17 14:48:01 +01:00
if ( isset ( $agents_id [ 0 ]) === true && $agents_id [ 0 ] != - 1 ) {
2019-01-30 16:18:44 +01:00
serialize_in_temp ( $agents_id , $config [ 'id_user' ] . '_agents' , 1 );
}
if ( $config [ 'pure' ] == 0 ) {
if ( $modules_selected [ 0 ] && $agents_id [ 0 ]) {
$full_modules = urlencode ( implode ( ';' , $modules_selected ));
$full_agents = urlencode ( implode ( ';' , $agents_id ));
$fullscreen [ 'text' ] = ' < a href = " index.php?extension_in_menu=estado&sec=extensions&sec2=extensions/agents_modules&pure=1&
2022-03-17 14:48:01 +01:00
offset = '.$offset.' & group_id = '.$group_id.' & modulegroup = '.$modulegroup.' & refresh = '.$refr.' & full_modules_selected = '.$full_modules.' & show_type = '.$show_type.'
2023-03-07 15:59:10 +01:00
& full_agents_id = '.$full_agents.' & selection_agent_module = '.$selection_a_m.' " >'.html_print_image('images/fullscreen@svg.svg', true, ['title' => __('Full screen mode'), 'class' => 'invert_filter']).'</a>';
2019-01-30 16:18:44 +01:00
} else if ( $full_modules_selected [ 0 ] && $full_agents_id [ 0 ]) {
$full_modules = urlencode ( implode ( ';' , $full_modules_selected ));
$full_agents = urlencode ( implode ( ';' , $full_agents_id ));
$fullscreen [ 'text' ] = ' < a href = " index.php?extension_in_menu=estado&sec=extensions&sec2=extensions/agents_modules&pure=1&
2022-03-17 14:48:01 +01:00
offset = '.$offset.' & group_id = '.$group_id.' & modulegroup = '.$modulegroup.' & refresh = '.$refr.' & full_modules_selected = '.$full_modules.' & show_type = '.$show_type.'
2023-03-07 15:59:10 +01:00
& full_agents_id = '.$full_agents.' & selection_agent_module = '.$selection_a_m.' " >'.html_print_image('images/fullscreen@svg.svg', true, ['title' => __('Full screen mode'), 'class' => 'invert_filter']).'</a>';
2019-01-30 16:18:44 +01:00
} else {
$fullscreen [ 'text' ] = ' < a href = " index.php?extension_in_menu=estado&sec=extensions&sec2=extensions/agents_modules&pure=1&
2023-03-07 15:59:10 +01:00
offset = '.$offset.' & group_id = '.$group_id.' & modulegroup = '.$modulegroup.' & refresh = '.$refr.' & show_type = '.$show_type.' " >'.html_print_image('images/fullscreen@svg.svg', true, ['title' => __('Full screen mode'), 'class' => 'invert_filter']).'</a>';
2019-01-30 16:18:44 +01:00
}
}
2022-03-17 14:48:01 +01:00
// Type show.
$show_select = [
0 => __ ( 'Show module status' ),
1 => __ ( 'Show module data' ),
];
2023-02-24 13:09:03 +01:00
$filter_type = html_print_label_input_block (
__ ( 'Information to be shown' ),
html_print_select (
$show_select ,
'show_type' ,
$show_type ,
'' ,
'' ,
0 ,
true ,
false ,
false ,
'' ,
false ,
'width: 100%;'
)
);
$filter_groups = html_print_label_input_block (
__ ( 'Group' ),
html_print_select_groups (
false ,
'AR' ,
true ,
'group_id' ,
$group_id ,
'' ,
'' ,
'' ,
true ,
false ,
true ,
'' ,
false ,
'width: 100%;'
)
);
$filter_groups .= html_print_label_input_block (
__ ( 'Recursion' ),
2023-12-26 09:16:12 +01:00
html_print_checkbox_switch ( 'recursion' , 1 , $recursion , true ),
2023-02-24 13:09:03 +01:00
[
'div_class' => 'add-input-reverse' ,
'label_class' => 'label-thin' ,
]
);
$filter_module_groups = html_print_label_input_block (
__ ( 'Module group' ),
html_print_select_from_sql (
'SELECT * FROM tmodule_group ORDER BY name' ,
'modulegroup' ,
$modulegroup ,
'' ,
__ ( 'All' ),
0 ,
true ,
false ,
true ,
false ,
'width: 100%;'
)
2019-01-30 16:18:44 +01:00
);
$agents = agents_get_group_agents ( $group_id );
if (( empty ( $agents )) || $agents == - 1 ) {
$agents = [];
}
2024-02-09 13:51:56 +01:00
if ( isset ( $agents_id ) === false ) {
$agents_id = '' ;
}
2023-02-24 13:09:03 +01:00
$filter_agents = html_print_label_input_block (
__ ( 'Agents' ),
html_print_select (
$agents ,
'id_agents2[]' ,
$agents_id ,
'' ,
'' ,
0 ,
true ,
true ,
true ,
'' ,
false ,
'width: 100%;'
)
);
2019-01-30 16:18:44 +01:00
2019-03-27 12:29:15 +01:00
// Type show.
2019-01-30 16:18:44 +01:00
$selection = [
0 => __ ( 'Show common modules' ),
1 => __ ( 'Show all modules' ),
];
2023-02-24 13:09:03 +01:00
$filter_type_show = html_print_label_input_block (
__ ( 'Show common modules' ),
html_print_select (
$selection ,
'selection_agent_module' ,
$selection_a_m ,
'' ,
'' ,
0 ,
true ,
false ,
true ,
'' ,
false ,
'width: 100%;'
)
);
2019-01-30 16:18:44 +01:00
2019-03-27 12:29:15 +01:00
// Modules.
2019-01-30 16:18:44 +01:00
$all_modules = select_modules_for_agent_group ( $group_id , $agents_id , $selection_a_m , false );
2023-02-24 13:09:03 +01:00
$filter_modules = html_print_label_input_block (
__ ( 'Module' ),
html_print_select (
$all_modules ,
'module[]' ,
$modules_selected ,
'' ,
'' ,
0 ,
true ,
true ,
false ,
'' ,
false ,
'width: 100%;'
)
);
2019-01-30 16:18:44 +01:00
$onheader = [
2023-02-24 10:46:46 +01:00
'updated_time' => $updated_time ,
'fullscreen' => $fullscreen ,
2019-01-30 16:18:44 +01:00
];
2019-03-27 12:29:15 +01:00
/*
* Old style table , we need a lot of special formatting , don ' t use table function .
* Prepare old - style table .
*/
2019-01-30 16:18:44 +01:00
if ( $config [ 'pure' ] == 0 ) {
2019-03-27 12:29:15 +01:00
// Header.
2021-04-29 13:28:03 +02:00
ui_print_standard_header (
2019-04-24 13:53:18 +02:00
__ ( 'Agents/Modules' ),
2021-03-11 15:40:23 +01:00
'images/module.png' ,
2019-04-24 13:53:18 +02:00
false ,
2020-05-29 11:37:06 +02:00
'' ,
2019-04-24 13:53:18 +02:00
false ,
2023-02-24 10:46:46 +01:00
$onheader ,
2021-04-29 13:28:03 +02:00
[
[
'link' => '' ,
'label' => __ ( 'Monitoring' ),
],
[
'link' => '' ,
'label' => __ ( 'Views' ),
],
]
2019-04-24 13:53:18 +02:00
);
2019-01-30 16:18:44 +01:00
} else {
if ( $full_agents_id [ 0 ]) {
$full_modules = urlencode ( implode ( ';' , $full_modules_selected ));
$full_agents = urlencode ( implode ( ';' , $full_agents_id ));
2022-03-17 14:48:01 +01:00
$url = sprintf (
' index . php ? sec = view & sec2 = extensions / agents_modules & pure = 0 & offset =% s
& group_id =% s & modulegroup =% s & refresh =% s & full_modules_selected =% s
& full_agents_id =% s & selection_agent_module =% s & show_type =% s ' ,
$offset ,
$group_id ,
$modulegroup ,
$refr ,
$full_modules ,
$full_agents ,
$selection_a_m ,
$show_type
);
2019-01-30 16:18:44 +01:00
} else {
2022-03-17 14:48:01 +01:00
$url = sprintf (
' index . php ? sec = view & sec2 = extensions / agents_modules & pure = 0 & offset =% s & group_id =% s
& modulegroup =% s & refresh =% s & show_type =% s ' ,
$offset ,
$group_id ,
$modulegroup ,
$refr ,
$show_type
);
2019-01-30 16:18:44 +01:00
}
2019-03-27 12:29:15 +01:00
// Floating menu - Start.
2021-03-11 15:40:23 +01:00
echo '<div id="vc-controls" class="zindex999">' ;
2019-01-30 16:18:44 +01:00
echo '<div id="menu_tab">' ;
echo '<ul class="mn">' ;
2019-03-27 12:29:15 +01:00
// Quit fullscreen.
2019-01-30 16:18:44 +01:00
echo '<li class="nomn">' ;
echo '<a target="_top" href="' . $url . '">' ;
2021-03-11 15:40:23 +01:00
echo html_print_image (
2023-03-07 15:59:10 +01:00
'images/exit_fullscreen@svg.svg' ,
2021-03-11 15:40:23 +01:00
true ,
[
'title' => __ ( 'Back to normal mode' ),
2023-03-07 15:59:10 +01:00
'class' => 'main_menu_icon invert_filter' ,
2021-03-11 15:40:23 +01:00
]
);
2019-01-30 16:18:44 +01:00
echo '</a>' ;
echo '</li>' ;
2019-03-27 12:29:15 +01:00
// Countdown.
2019-01-30 16:18:44 +01:00
echo '<li class="nomn">' ;
echo '<div class="vc-refr">' ;
2021-03-11 15:40:23 +01:00
echo '<div class="vc-countdown inline_line"></div>' ;
2019-01-30 16:18:44 +01:00
echo '<div id="vc-refr-form">' ;
echo __ ( 'Refresh' ) . ':' ;
2019-03-27 12:29:15 +01:00
echo html_print_select (
get_refresh_time_array (),
'refresh' ,
$refr ,
'' ,
'' ,
0 ,
true ,
false ,
false ,
'' ,
false ,
'margin-top: 3px;'
);
2019-01-30 16:18:44 +01:00
echo '</div>' ;
echo '</div>' ;
echo '</li>' ;
2019-03-27 12:29:15 +01:00
// Console name.
2019-01-30 16:18:44 +01:00
echo '<li class="nomn">' ;
echo '<div class="vc-title">' . __ ( 'Agent/module view' ) . '</div>' ;
echo '</li>' ;
echo '</ul>' ;
echo '</div>' ;
echo '</div>' ;
2019-03-27 12:29:15 +01:00
// Floating menu - End.
2019-01-30 16:18:44 +01:00
ui_require_jquery_file ( 'countdown' );
}
if ( $config [ 'pure' ] != 1 ) {
2023-07-13 13:12:43 +02:00
$show_filters = '<form id="filter_form" method="post" action="index.php?sec=view&sec2=extensions/agents_modules" class="w100p">' ;
2023-02-24 13:09:03 +01:00
$show_filters .= '<table class="filter-table-adv w100p no-border" cellpadding="4" cellspacing="4">' ;
2022-03-17 14:48:01 +01:00
$show_filters .= '<tr>' ;
2023-02-24 13:09:03 +01:00
$show_filters .= '<td width="33%">' . $filter_type . '</td>' ;
$show_filters .= '<td width="33%">' . $filter_groups . '</td>' ;
$show_filters .= '<td width="33%">' . $filter_module_groups . '</td>' ;
2022-03-17 14:48:01 +01:00
$show_filters .= '</tr>' ;
2019-06-11 17:34:13 +02:00
$show_filters .= '<tr>' ;
$show_filters .= '<td>' . $filter_agents . '</td>' ;
$show_filters .= '<td>' . $filter_type_show . '</td>' ;
$show_filters .= '<td>' . $filter_modules . '</td>' ;
$show_filters .= '</tr>' ;
$show_filters .= '</table>' ;
2023-02-24 13:09:03 +01:00
$show_filters .= html_print_div (
[
'class' => 'action-buttons' ,
'content' => html_print_submit_button (
__ ( 'Filter' ),
'srcbutton' ,
false ,
[
2023-03-30 13:56:53 +02:00
'icon' => 'search' ,
'mode' => 'mini' ,
'onclick' => 'select_selected()' ,
2023-02-24 13:09:03 +01:00
],
true
2023-07-13 13:12:43 +02:00
) . html_print_button (
__ ( 'Export to CSV' ),
2023-08-21 11:33:26 +02:00
'srcbutton_csv' ,
2023-07-13 13:12:43 +02:00
false ,
'export_csv()' ,
[ 'class' => 'secondary mini' ],
true ,
2023-02-24 13:09:03 +01:00
),
],
true
);
2019-06-11 17:34:13 +02:00
$show_filters .= '</form>' ;
2023-02-24 10:46:46 +01:00
2020-05-29 11:37:06 +02:00
ui_toggle (
$show_filters ,
2023-02-24 13:09:03 +01:00
'<span class="subsection_header_title">' . __ ( 'Filters ' ) . '</span>' . ui_print_help_tip ( __ ( 'Secondary groups and agent subgroups will be taken into account.' ), true ),
2023-02-24 10:18:52 +01:00
'filter_form' ,
'' ,
true ,
false ,
'' ,
'white-box-content' ,
'box-flat white_table_graph fixed_filter_bar'
2020-05-29 11:37:06 +02:00
);
2019-01-30 16:18:44 +01:00
}
2023-12-26 09:16:12 +01:00
$group_id_for_agents_search = $group_id ;
if ( $group_id > 0 ) {
if ( $recursion ) {
$group_id_for_agents_search = groups_get_children_ids ( $group_id , true );
}
}
2022-03-17 14:48:01 +01:00
if ( isset ( $agents_id [ 0 ]) === true && $agents_id [ 0 ] != - 1 ) {
2019-01-30 16:18:44 +01:00
$agents = $agents_id ;
} else {
2022-03-17 14:48:01 +01:00
if ( isset ( $full_agents_id [ 0 ]) === true && $full_agents_id [ 0 ]) {
2019-01-30 16:18:44 +01:00
$agents = $full_agents_id ;
} else {
$agents = '' ;
2023-12-26 09:16:12 +01:00
$agents = agents_get_group_agents ( $group_id_for_agents_search , [ 'disabled' => 0 ]);
2019-01-30 16:18:44 +01:00
$agents = array_keys ( $agents );
}
}
$filter_module_group = [ 'disabled' => 0 ];
if ( $modulegroup > 0 ) {
$filter_module_group [ 'id_module_group' ] = $modulegroup ;
}
$count = 0 ;
foreach ( $agents as $agent ) {
2019-03-27 12:29:15 +01:00
// TODO TAGS agents_get_modules.
2019-01-30 16:18:44 +01:00
$module = agents_get_modules (
$agent ,
false ,
$filter_module_group ,
true ,
true
);
if ( $module == false ) {
unset ( $agents [ $count ]);
}
$count ++ ;
}
$total_pagination = count ( $agents );
2022-03-17 14:48:01 +01:00
if ( isset ( $agents_id [ 0 ]) === true && $agents_id [ 0 ] != - 1 ) {
if ( isset ( $modules_selected [ 0 ]) === true && $modules_selected [ 0 ]) {
$all_modules = [];
foreach ( $modules_selected as $key => $value ) {
2023-03-30 13:56:53 +02:00
if (( int ) $value > 0 ) {
2023-03-29 11:02:57 +02:00
$name = modules_get_agentmodule_name ( $value );
$sql = " SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre = '".$name."' ; " ;
2022-03-17 14:48:01 +01:00
2023-03-29 11:02:57 +02:00
$result_sql = db_get_all_rows_sql ( $sql );
2022-03-17 14:48:01 +01:00
2023-03-29 11:02:57 +02:00
if ( is_array ( $result_sql )) {
foreach ( $result_sql as $key => $value ) {
$all_modules [ $value [ 'id_agente_modulo' ]] = io_safe_output ( $name );
}
}
} else {
$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 );
}
2022-03-17 14:48:01 +01:00
}
2019-01-30 16:18:44 +01:00
}
}
2022-03-17 14:48:01 +01:00
} else {
$all_modules = agents_get_modules (
$agents ,
false ,
$filter_module_group ,
true ,
true
);
2019-01-30 16:18:44 +01:00
}
} else {
2022-03-17 14:48:01 +01:00
if ( isset ( $full_modules_selected [ 0 ]) === true && $full_modules_selected [ 0 ]) {
2019-01-30 16:18:44 +01:00
foreach ( $full_modules_selected as $key => $value ) {
$name = modules_get_agentmodule_name ( $value );
$sql = " SELECT id_agente_modulo
2017-05-04 17:12:32 +02:00
FROM tagente_modulo
2019-01-30 16:18:44 +01:00
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 {
2019-03-27 12:29:15 +01:00
// TODO TAGS agents_get_modules.
2019-01-30 16:18:44 +01:00
$all_modules = agents_get_modules (
$agents ,
false ,
$filter_module_group ,
true ,
true
);
}
}
$modules_by_name = [];
$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 ;
2021-10-26 14:21:40 +02:00
$cont ++ ;
2019-01-30 16:18:44 +01:00
}
}
if ( $config [ 'pure' ] == 1 ) {
$block = count ( $modules_by_name );
}
if ( $update_item == '' ) {
$filter_groups = [
'offset' => ( int ) $offset ,
'limit' => ( int ) $config [ 'block_size' ],
'disabled' => 0 ,
'id_agente' => $agents ,
];
} else {
$filter_groups = [
'offset' => 0 ,
'limit' => ( int ) $config [ 'block_size' ],
'disabled' => 0 ,
'id_agente' => $agents ,
];
}
if ( $group_id > 0 ) {
if ( $recursion ) {
2023-12-26 09:16:12 +01:00
$filter_groups [ 'id_grupo' ] = groups_get_children_ids ( $group_id , true );
2019-01-30 16:18:44 +01:00
} else {
$filter_groups [ 'id_grupo' ] = $group_id ;
}
}
if ( ! empty ( $filter_groups [ 'id_agente' ])) {
$agents = agents_get_agents ( $filter_groups );
}
$nagents = count ( $agents );
if ( $all_modules == false || $agents == false ) {
ui_print_info_message ([ 'no_close' => true , 'message' => __ ( 'There are no agents with modules' ) ]);
return ;
}
2023-11-24 12:54:19 +01:00
echo '<table cellpadding="4" cellspacing="4" border="0" class="info_table mrgn_btn_20px" id="agents_modules_table">' ;
2019-01-30 16:18:44 +01:00
echo '<tr>' ;
2023-03-29 11:02:57 +02:00
echo " <th width='40px' class='pdd_r_10px align_left'> " . __ ( 'Agents' ) . ' / ' . __ ( 'Modules' ) . '</th>' ;
2019-01-30 16:18:44 +01:00
if ( $hor_offset > 0 ) {
$new_hor_offset = ( $hor_offset - $block );
2022-03-17 14:48:01 +01:00
echo " <th width='20px' class='vertical_middle center' rowspan=' " . ( $nagents + 1 ) . " '><a href='index.php? " . 'extension_in_menu=estado&sec=extensions&sec2=extensions/agents_modules&refr=0&save_serialize=1&show_type=' . $show_type . '&selection_a_m=' . $selection_a_m . '&hor_offset=' . $new_hor_offset . '&offset=' . $offset . " '> " . html_print_image (
2019-06-11 17:34:13 +02:00
'images/arrow_left_green.png' ,
2019-01-30 16:18:44 +01:00
true ,
[ 'title' => __ ( 'Previous modules' )]
2019-03-27 12:29:15 +01:00
) . '</a></th>' ;
2019-01-30 16:18:44 +01:00
}
$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 '<th align="center" width="20px" id="th_module_r_' . $nmodules . ' " class= " th_class_module_r " >
2021-03-11 15:40:23 +01:00
< div class = " w30px " >
< div id = " div_module_r_'. $nmodules .' " class = " rotate_text_module invisible padding-lft-10 " > '.$text.' </ div >
2013-04-25 17:34:53 +02:00
</ div >
</ th > ' ;
2019-01-30 16:18:44 +01:00
}
if (( $hor_offset + $block ) < $nmodules ) {
$new_hor_offset = ( $hor_offset + $block );
2022-03-17 14:48:01 +01:00
echo " <th width='20px' class='vertical_middle center' rowspan=' " . ( $nagents + 1 ) . " '><a href='index.php? " . 'extension_in_menu=estado&sec=extensions&sec2=extensions/agents_modules&save_serialize=1&show_type=' . $show_type . '&selection_a_m=' . $selection_a_m . '&hor_offset=' . $new_hor_offset . '&offset=' . $offset . " '> " . html_print_image (
2019-06-11 17:34:13 +02:00
'images/arrow_right_green.png' ,
2019-01-30 16:18:44 +01:00
true ,
[ 'title' => __ ( 'More modules' )]
2019-03-27 12:29:15 +01:00
) . '</a></th>' ;
2019-01-30 16:18:44 +01:00
}
echo '</tr>' ;
$filter_agents = [
'offset' => ( int ) $offset ,
'disabled' => 0 ,
];
if ( $group_id > 0 ) {
$filter_agents [ 'id_grupo' ] = $group_id ;
}
2019-03-27 12:29:15 +01:00
// 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 ;
2023-02-24 13:09:03 +01:00
$tablePagination = ui_pagination (
$total_pagination ,
$url ,
0 ,
0 ,
true ,
'offset' ,
false
);
html_print_action_buttons (
'' ,
[ 'right_content' => $tablePagination ]
);
2019-01-30 16:18:44 +01:00
foreach ( $agents as $agent ) {
2019-03-27 12:29:15 +01:00
// Get stats for this group.
2019-01-30 16:18:44 +01:00
$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 :
2019-03-27 12:29:15 +01:00
// Alert fired status.
2019-01-30 16:18:44 +01:00
$rowcolor = 'group_view_alrm' ;
break ;
case 1 :
2019-03-27 12:29:15 +01:00
// Critical status.
2019-01-30 16:18:44 +01:00
$rowcolor = 'group_view_crit' ;
break ;
case 2 :
2019-03-27 12:29:15 +01:00
// Warning status.
2019-01-30 16:18:44 +01:00
$rowcolor = 'group_view_warn' ;
break ;
case 0 :
2019-03-27 12:29:15 +01:00
// Normal status.
2019-01-30 16:18:44 +01:00
$rowcolor = 'group_view_ok' ;
break ;
case 3 :
case - 1 :
default :
2019-03-27 12:29:15 +01:00
// Unknown status.
2019-01-30 16:18:44 +01:00
$rowcolor = 'group_view_unk' ;
break ;
}
2021-03-11 15:40:23 +01:00
echo " <tr class='height_25px'> " ;
2019-01-30 16:18:44 +01:00
echo " <td class=' $rowcolor '>
< a class = '$rowcolor' href = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=".$agent[' id_agente ']."' > " . $alias['alias'] .'</a></td>';
2019-03-27 12:29:15 +01:00
// TODO TAGS agents_get_modules.
2019-01-30 16:18:44 +01:00
$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 )) {
2023-03-29 11:02:57 +02:00
echo " <td class='center' style='text-align:left;'> " ;
2019-01-30 16:18:44 +01:00
$win_handle = dechex ( crc32 ( $module_id . $module [ 'name' ]));
$graph_type = return_graphtype ( modules_get_agentmodule_type ( $module_id ));
2023-10-18 12:49:47 +02:00
$link = " winopeng_var(' " . 'operation/agentes/stat_win.php?' . " type= $graph_type & " . 'period=' . SECONDS_1DAY . '&id=' . $module_id . '&period_graph=0&refresh=' . SECONDS_10MINUTES . " ', 'day_ " . $win_handle . " ', 800, 480) " ;
2019-01-30 16:18:44 +01:00
echo '<a href="javascript:' . $link . '">' ;
2020-02-03 16:17:46 +01:00
$module_last_value = modules_get_last_value ( $module_id );
if ( ! is_numeric ( $module_last_value )) {
$module_last_value = htmlspecialchars ( $module_last_value );
}
2022-03-17 14:48:01 +01:00
if ( $show_type === 0 ) {
$status = modules_get_agentmodule_status ( $module_id );
switch ( $status ) {
case AGENT_MODULE_STATUS_NORMAL :
ui_print_status_image ( 'module_ok.png' , $module_last_value , false );
break ;
case AGENT_MODULE_STATUS_CRITICAL_BAD :
ui_print_status_image ( 'module_critical.png' , $module_last_value , false );
break ;
case AGENT_MODULE_STATUS_WARNING :
ui_print_status_image ( 'module_warning.png' , $module_last_value , false );
break ;
case AGENT_MODULE_STATUS_UNKNOWN :
ui_print_status_image ( 'module_unknown.png' , $module_last_value , false );
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' , $module_last_value , false );
break ;
case 4 :
ui_print_status_image ( 'module_no_data.png' , $module_last_value , false );
break ;
}
} else {
$module = modules_get_agentmodule ( $module_id );
$module [ 'datos' ] = $module_last_value ;
2019-01-30 16:18:44 +01:00
2022-03-17 14:48:01 +01:00
$module_last_value = modules_get_agentmodule_data_for_humans ( $module );
2019-01-30 16:18:44 +01:00
2022-03-17 14:48:01 +01:00
echo $module_last_value ;
2019-01-30 16:18:44 +01:00
}
echo '</a>' ;
echo '</td>' ;
$match = true ;
}
}
if ( ! $match ) {
echo '<td></td>' ;
}
}
echo '</tr>' ;
}
echo '</table>' ;
2022-03-17 14:48:01 +01:00
if ( $show_type === 0 ) {
$show_legend = " <div class='legend_white'> " ;
$show_legend .= " <div class='center flex'>
< div class = 'legend_square_simple' >< div style = 'background-color: ".COL_ALERTFIRED.";' ></ div ></ div > " .__('Orange cell when the module has fired alerts').'</div>';
$show_legend .= " <div class='center flex'>
< div class = 'legend_square_simple' >< div style = 'background-color: ".COL_CRITICAL.";' ></ div ></ div > " .__('Red cell when the module has a critical status').'
</ div > ' ;
$show_legend .= " <div class='center flex'>
< div class = 'legend_square_simple' >< div style = 'background-color: ".COL_WARNING.";' ></ div ></ div > " .__('Yellow cell when the module has a warning status').'</div>';
$show_legend .= " <div class='center flex'>
< div class = 'legend_square_simple' >< div style = 'background-color: ".COL_NORMAL.";' ></ div ></ div > " .__('Green cell when the module has a normal status').'</div>';
$show_legend .= " <div class='center flex'>
< div class = 'legend_square_simple' >< div style = 'background-color: ".COL_UNKNOWN.";' ></ div ></ div > " .__('Grey cell when the module has an unknown status').'</div>';
$show_legend .= " <div class='center flex'>
< div class = 'legend_square_simple' >< div style = 'background-color: ".COL_NOTINIT.";' ></ div ></ div > " .__( " Cell turns blue when the module is in 'not initialize' status " ).'</div>';
$show_legend .= '</div>' ;
ui_toggle ( $show_legend , __ ( 'Legend' ));
}
2019-01-30 16:18:44 +01:00
$pure_var = $config [ 'pure' ];
if ( $pure_var ) {
$pure_var = 1 ;
} else {
$pure_var = 0 ;
}
2018-02-20 11:36:30 +01:00
}
2019-01-30 16:18:44 +01:00
extensions_add_operation_menu_option ( __ ( 'Agents/Modules view' ), 'estado' , 'agents_modules/icon_menu.png' , 'v1r1' , 'view' );
2018-02-20 11:36:30 +01:00
extensions_add_main_function ( 'mainAgentsModules' );