2010-11-03 18:45:39 +01:00
< ? php
2019-05-28 12:13:29 +02:00
/**
* Module management .
*
* @ category Ajax library .
* @ package Pandora FMS
* @ subpackage Modules .
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
2023-06-08 12:42:10 +02:00
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
2019-05-28 12:13:29 +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
2019-05-28 12:13:29 +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 .
* ============================================================================
*/
2022-11-10 16:10:50 +01:00
use PandoraFMS\Enterprise\Metaconsole\Node ;
2019-05-28 12:13:29 +02:00
// Begin.
2019-01-30 16:18:44 +01:00
if ( check_login ()) {
global $config ;
include_once $config [ 'homedir' ] . '/include/functions_agents.php' ;
include_once $config [ 'homedir' ] . '/include/functions_modules.php' ;
include_once $config [ 'homedir' ] . '/include/functions_ui.php' ;
enterprise_include_once ( 'include/functions_metaconsole.php' );
$get_plugin_macros = get_parameter ( 'get_plugin_macros' );
2023-05-16 16:00:17 +02:00
$get_module_macros = get_parameter ( 'get_module_macros' );
2019-01-30 16:18:44 +01:00
$search_modules = get_parameter ( 'search_modules' );
$get_module_detail = get_parameter ( 'get_module_detail' , 0 );
2020-12-09 14:05:40 +01:00
$get_module_autocomplete_input = ( bool ) get_parameter (
'get_module_autocomplete_input'
);
2019-01-30 16:18:44 +01:00
$add_module_relation = ( bool ) get_parameter ( 'add_module_relation' );
$remove_module_relation = ( bool ) get_parameter ( 'remove_module_relation' );
2020-12-09 14:05:40 +01:00
$change_module_relation_updates = ( bool ) get_parameter (
'change_module_relation_updates'
);
2019-01-30 16:18:44 +01:00
$get_id_tag = ( bool ) get_parameter ( 'get_id_tag' , 0 );
$get_type = ( bool ) get_parameter ( 'get_type' , 0 );
$list_modules = ( bool ) get_parameter ( 'list_modules' , 0 );
2020-12-09 14:05:40 +01:00
$get_agent_modules_json_by_name = ( bool ) get_parameter (
'get_agent_modules_json_by_name' ,
0
);
$get_graph_module = ( bool ) get_parameter ( 'get_graph_module' , 0 );
$get_graph_module_interfaces = ( bool ) get_parameter (
'get_graph_module_interfaces' ,
0
);
2023-01-24 12:26:49 +01:00
$get_children_modules = ( bool ) get_parameter ( 'get_children_modules' , false );
2022-11-08 16:30:25 +01:00
$get_data_dataMatrix = ( bool ) get_parameter (
'get_data_dataMatrix' ,
0
);
2023-02-09 10:12:59 +01:00
$get_data_ModulesByStatus = ( bool ) get_parameter (
'get_data_ModulesByStatus' ,
0
);
2023-01-19 10:49:48 +01:00
$load_filter_modal = get_parameter ( 'load_filter_modal' , 0 );
$save_filter_modal = get_parameter ( 'save_filter_modal' , 0 );
$get_monitor_filters = get_parameter ( 'get_monitor_filters' , 0 );
$save_monitor_filter = get_parameter ( 'save_monitor_filter' , 0 );
$update_monitor_filter = get_parameter ( 'update_monitor_filter' , 0 );
2023-02-28 17:06:31 +01:00
$delete_monitor_filter = get_parameter ( 'delete_monitor_filter' , 0 );
2023-01-19 10:49:48 +01:00
2020-12-09 14:05:40 +01:00
if ( $get_agent_modules_json_by_name === true ) {
2019-01-30 16:18:44 +01:00
$agent_name = get_parameter ( 'agent_name' );
$agent_id = agents_get_agent_id ( $agent_name );
$agent_modules = db_get_all_rows_sql (
2020-12-09 14:05:40 +01:00
' SELECT id_agente_modulo as id_module ,
nombre as name FROM tagente_modulo
WHERE id_agente = ' . $agent_id
2019-01-30 16:18:44 +01:00
);
echo json_encode ( $agent_modules );
return ;
}
2023-07-12 16:05:55 +02:00
$id_plugin = get_parameter ( 'id_plugin' , 0 );
2023-07-17 09:34:57 +02:00
if ( $id_plugin !== 0 ) {
$id_module_plugin = db_get_value (
'id_plugin' ,
'tagente_modulo' ,
'id_agente_modulo' ,
$get_module_macros
);
if ( $id_plugin !== $id_module_plugin ) {
$get_plugin_macros = true ;
$get_module_macros = 0 ;
}
2023-07-12 16:05:55 +02:00
}
2019-01-30 16:18:44 +01:00
if ( $get_plugin_macros ) {
if ( https_is_running ()) {
header ( 'Content-type: application/json' );
}
$id_plugin = get_parameter ( 'id_plugin' , 0 );
$plugin_macros = db_get_value (
'macros' ,
'tplugin' ,
'id' ,
$id_plugin
);
$macros = [];
$macros [ 'base64' ] = base64_encode ( $plugin_macros );
$macros [ 'array' ] = json_decode ( $plugin_macros , true );
echo json_encode ( $macros );
return ;
}
2023-05-16 16:00:17 +02:00
if ( $get_module_macros && $get_module_macros > 0 ) {
if ( https_is_running ()) {
header ( 'Content-type: application/json' );
}
$module_id = $get_module_macros ;
$module_macros = db_get_value (
'macros' ,
'tagente_modulo' ,
'id_agente_modulo' ,
$module_id
);
$macros = [];
$macros [ 'base64' ] = base64_encode ( $module_macros );
$macros [ 'array' ] = json_decode ( $module_macros , true );
echo json_encode ( $macros );
return ;
}
2019-01-30 16:18:44 +01:00
if ( $search_modules ) {
if ( https_is_running ()) {
header ( 'Content-type: application/json' );
}
$id_agents = json_decode ( io_safe_output ( get_parameter ( 'id_agents' )));
$filter = '%' . get_parameter ( 'q' , '' ) . '%' ;
2020-12-09 14:05:40 +01:00
$other_filter = json_decode (
io_safe_output ( get_parameter ( 'other_filter' )),
true
);
2019-05-28 12:13:29 +02:00
// TODO TAGS agents_get_modules.
2019-01-30 16:18:44 +01:00
$modules = agents_get_modules (
$id_agents ,
false ,
([ 'tagente_modulo.nombre' => $filter ] + $other_filter )
);
if ( $modules === false ) {
$modules = [];
}
$modules = array_unique ( $modules );
$modules = io_safe_output ( $modules );
echo json_encode ( $modules );
return ;
}
if ( $get_module_detail ) {
2020-12-09 14:05:40 +01:00
// This script is included manually to be
// included after jquery and avoid error.
2019-01-30 16:18:44 +01:00
ui_include_time_picker ();
2020-12-09 14:05:40 +01:00
ui_require_jquery_file (
'ui.datepicker-' . get_user_language (),
'include/javascript/i18n/'
);
2019-01-30 16:18:44 +01:00
$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 ();
2020-12-09 14:05:40 +01:00
$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 )
);
2019-01-30 16:18:44 +01:00
2020-09-07 13:54:18 +02:00
// Definition of new table.
$formtable = new stdClass ();
2019-01-30 16:18:44 +01:00
$formtable -> width = '98%' ;
$formtable -> class = 'databox' ;
$formtable -> data = [];
$formtable -> size = [];
$moduletype_name = modules_get_moduletype_name (
modules_get_agentmodule_type ( $module_id )
);
$periods = [
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' ),
];
2023-02-17 11:54:48 +01:00
$formtable -> data [ 0 ][ 0 ] = '<div style="display:flex;align-items:center;font-weight:bold;">' . html_print_radio_button_extended (
2019-01-30 16:18:44 +01:00
'selection_mode' ,
'fromnow' ,
'' ,
$selection_mode ,
false ,
'' ,
2021-03-11 15:40:23 +01:00
'class="mrgn_right_15px"' ,
2019-01-30 16:18:44 +01:00
true
2023-02-17 11:54:48 +01:00
) . __ ( 'Choose a time from now' ) . '</div>' ;
$formtable -> colspan [ 0 ][ 0 ] = 2 ;
$formtable -> data [ 0 ][ 2 ] = html_print_select (
2020-12-09 14:05:40 +01:00
$periods ,
'period' ,
$period ,
'' ,
'' ,
0 ,
true ,
false ,
false
);
2023-03-10 12:48:31 +01:00
$formtable -> data [ 0 ][ 3 ] = " <a href='javascript: show_module_detail_dialog( " . $module_id . ', ' . $agentId . ', "' . $server_name . '", 0, -1,"' . modules_get_agentmodule_name ( $module_id ) . " \" )'> " . html_print_image ( 'images/refresh@svg.svg' , true , [ 'style' => 'vertical-align: middle;' , 'border' => '0' , 'class' => 'main_menu_icon invert_filter' ]) . '</a>' ;
2019-01-30 16:18:44 +01:00
$formtable -> rowspan [ 0 ][ 3 ] = 2 ;
$formtable -> cellstyle [ 0 ][ 3 ] = 'vertical-align: middle;' ;
2023-02-17 11:54:48 +01:00
$formtable -> data [ 1 ][ 0 ] = '<div style="display:flex;align-items:center;font-weight:bold;">' . html_print_radio_button_extended (
2019-01-30 16:18:44 +01:00
'selection_mode' ,
'range' ,
'' ,
$selection_mode ,
false ,
'' ,
2021-03-11 15:40:23 +01:00
'class="mrgn_right_15px"' ,
2019-01-30 16:18:44 +01:00
true
) . __ ( 'Specify time range' );
2023-02-17 11:54:48 +01:00
$formtable -> data [ 1 ][ 1 ] = '<span style="font-weight:bold">' . __ ( 'Timestamp from:' ) . '</span></div>' ;
2019-01-30 16:18:44 +01:00
2023-02-17 11:54:48 +01:00
$formtable -> data [ 1 ][ 2 ] = '<div class="inputs_date_details">' . html_print_input_text (
2019-01-30 16:18:44 +01:00
'date_from' ,
$date_from ,
'' ,
10 ,
10 ,
true
);
$formtable -> data [ 1 ][ 2 ] .= html_print_input_text (
'time_from' ,
$time_from ,
'' ,
9 ,
2023-02-17 11:54:48 +01:00
8 ,
2019-01-30 16:18:44 +01:00
true
);
$formtable -> data [ 1 ][ 1 ] .= '<br />' ;
2023-02-17 11:54:48 +01:00
$formtable -> data [ 1 ][ 1 ] .= '<span style="font-weight:bold">' . __ ( 'Timestamp to:' ) . '</span>' ;
2019-01-30 16:18:44 +01:00
$formtable -> data [ 1 ][ 2 ] .= '<br />' ;
$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 ,
2023-02-17 11:54:48 +01:00
8 ,
2019-01-30 16:18:44 +01:00
true
2023-02-17 11:54:48 +01:00
) . '</div>' ;
2019-01-30 16:18:44 +01:00
$freesearch_object = '' ;
if ( preg_match ( '/_string/' , $moduletype_name )) {
$formtable -> data [ 2 ][ 0 ] = __ ( 'Free search' ) . ' ' ;
2020-12-09 14:05:40 +01:00
$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
);
2019-01-30 16:18:44 +01:00
$formtable -> data [ 2 ][ 2 ] .= ' ' . __ ( 'Exact phrase' );
$freesearch_object = json_encode (
[
'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 = [];
$datetime_from = strtotime ( $date_from . ' ' . $time_from );
$datetime_to = strtotime ( $date_to . ' ' . $time_to );
$columns = [
'Data' => [
'data' ,
'modules_format_data' ,
'align' => 'center' ,
'width' => '230px'
],
];
if ( $config [ 'prominent_time' ] == 'comparation' ) {
$columns [ 'Time' ] = [
'utimestamp' ,
'modules_format_time' ,
'align' => 'center' ,
'width' => '50px'
];
} else {
$columns [ 'Timestamp' ] = [
'utimestamp' ,
'modules_format_timestamp' ,
'align' => 'center' ,
'width' => '50px'
];
}
2023-01-10 14:57:40 +01:00
if ( $selection_mode === 'fromnow' ) {
2019-01-30 16:18:44 +01:00
$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 = [];
} else {
2019-05-28 12:13:29 +02:00
// Paginate the result.
2019-01-30 16:18:44 +01:00
$result = array_slice ( $module_data , $offset , $block_size );
}
2020-09-07 13:54:18 +02:00
// Definition of new class.
$table = new stdClass ();
2019-01-30 16:18:44 +01:00
$table -> width = '100%' ;
$table -> class = 'databox data' ;
$table -> data = [];
$index = 0 ;
foreach ( $columns as $col => $attr ) {
$table -> head [ $index ] = $col ;
2021-03-04 11:29:52 +01:00
if ( $col === 'Data' ) {
$table -> head [ $index ] .= ui_print_help_tip (
2021-11-04 16:28:15 +01:00
__ ( 'In Pandora FMS, data is stored compressed. The data visualization in database, charts or CSV exported data won\'t match, because is interpreted at runtime. Please check \'Pandora FMS Engineering\' chapter from documentation.' ),
2021-03-04 11:29:52 +01:00
true
);
}
2019-01-30 16:18:44 +01:00
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'
);
2020-12-09 14:05:40 +01:00
$post_process = db_get_value_filter (
'post_process' ,
'tagente_modulo' ,
[ 'id_agente_modulo' => $module_id ]
);
$unit = db_get_value_filter (
'unit' ,
'tagente_modulo' ,
[ 'id_agente_modulo' => $module_id ]
);
2019-01-30 16:18:44 +01:00
foreach ( $result as $row ) {
$data = [];
$is_web_content_string = ( bool ) db_get_value_filter (
'id_agente_modulo' ,
'tagente_modulo' ,
[
'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' ]);
} else if ( is_snapshot_data ( $row [ $attr [ 0 ]])) {
if ( $config [ 'command_snapshot' ]) {
2021-03-11 15:40:23 +01:00
$imagetab = '<img class="w100p" src="' ;
2020-06-08 11:24:46 +02:00
$imagetab .= io_safe_input ( $row [ $attr [ 0 ]]);
$imagetab .= '">' ;
2021-03-11 15:40:23 +01:00
$image = '<img class="w300px" src="' ;
2020-06-08 11:24:46 +02:00
$image .= io_safe_input ( $row [ $attr [ 0 ]]);
$image .= '">' ;
$data [] = '<a style="cursor:pointer;" onclick="newTabjs(\'' . base64_encode ( $imagetab ) . '\')">' . $image . '</a>' ;
2019-01-30 16:18:44 +01:00
} else {
$data [] = '<span>' . wordwrap ( io_safe_input ( $row [ $attr [ 0 ]]), 60 , " <br> \n " , true ) . '</span>' ;
}
} else if (( $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 ]]);
} else if ( $is_web_content_string ) {
// Fixed the goliat sends the strings from web
2019-05-28 12:13:29 +02:00
// without HTML entities.
2019-01-30 16:18:44 +01:00
$data [] = io_safe_input ( $row [ $attr [ 0 ]]);
} else {
2019-05-28 12:13:29 +02:00
// Fixed the data from Selenium Plugin.
2019-01-30 16:18:44 +01:00
if ( $row [ $attr [ 0 ]] != strip_tags ( $row [ $attr [ 0 ]])) {
$data [] = html_print_result_div ( $row [ $attr [ 0 ]]);
2020-12-09 14:05:40 +01:00
} else if ( is_numeric ( $row [ $attr [ 0 ]])
&& ! modules_is_string_type ( $row [ 'module_type' ])
) {
2019-01-30 16:18:44 +01:00
switch ( $row [ 'module_type' ]) {
case 15 :
2020-12-09 14:05:40 +01:00
$value = db_get_value (
'snmp_oid' ,
'tagente_modulo' ,
'id_agente_modulo' ,
$module_id
);
2019-06-14 16:13:01 +02:00
// System Uptime:
2020-12-09 14:05:40 +01:00
// In case of System Uptime module,
// shows data in format
// "Days hours minutes seconds" if and only if
2019-06-14 16:13:01 +02:00
// selected module unit is "_timeticks_"
2020-12-09 14:05:40 +01:00
// Take notice that selected unit
// may not be postrocess unit.
if ( $value == '.1.3.6.1.2.1.1.3.0'
|| $value == '.1.3.6.1.2.1.25.1.1.0'
) {
$data_macro = modules_get_unit_macro (
$row [ $attr [ 0 ]],
$unit
);
2019-06-17 10:29:28 +02:00
if ( $data_macro ) {
$data [] = $data_macro ;
2019-01-30 16:18:44 +01:00
} else {
2020-12-09 14:05:40 +01:00
$data [] = remove_right_zeros (
number_format (
$row [ $attr [ 0 ]],
2022-10-26 18:25:16 +02:00
$config [ 'graph_precision' ],
$config [ 'decimal_separator' ],
$config [ 'thousand_separator' ]
2020-12-09 14:05:40 +01:00
)
);
2019-01-30 16:18:44 +01:00
}
} else {
2020-12-09 14:05:40 +01:00
$data [] = remove_right_zeros (
number_format (
$row [ $attr [ 0 ]],
2022-10-26 18:25:16 +02:00
$config [ 'graph_precision' ],
$config [ 'decimal_separator' ],
$config [ 'thousand_separator' ]
2020-12-09 14:05:40 +01:00
)
);
2019-01-30 16:18:44 +01:00
}
break ;
default :
2020-12-09 14:05:40 +01:00
$data_macro = modules_get_unit_macro (
$row [ $attr [ 0 ]],
$unit
);
2019-01-30 16:18:44 +01:00
if ( $data_macro ) {
$data [] = $data_macro ;
} else {
2020-12-09 14:05:40 +01:00
$data [] = remove_right_zeros (
number_format (
$row [ $attr [ 0 ]],
2022-10-26 18:25:16 +02:00
$config [ 'graph_precision' ],
$config [ 'decimal_separator' ],
$config [ 'thousand_separator' ]
2020-12-09 14:05:40 +01:00
)
);
2019-01-30 16:18:44 +01:00
}
break ;
}
} else {
if ( $row [ $attr [ 0 ]] == '' ) {
$data [] = 'No data' ;
} else {
2020-12-09 14:05:40 +01:00
$data_macro = modules_get_unit_macro (
$row [ $attr [ 0 ]],
$unit
);
2019-01-30 16:18:44 +01:00
if ( $data_macro ) {
$data [] = $data_macro ;
} else {
2020-12-09 14:05:40 +01:00
$data [] = html_print_result_div (
$row [ $attr [ 0 ]]
);
2019-01-30 16:18:44 +01:00
}
}
}
}
}
array_push ( $table -> data , $data );
if ( count ( $table -> data ) > 200 ) {
break ;
}
}
if ( empty ( $table -> data )) {
2023-07-24 14:54:38 +02:00
ui_print_empty_data ( __ ( 'No available data to show' ), '' , false );
2019-01-30 16:18:44 +01:00
} else {
2020-12-09 14:05:40 +01:00
ui_pagination (
count ( $count ),
false ,
$offset ,
0 ,
false ,
'offset' ,
true ,
'binary_dialog'
);
2019-01-30 16:18:44 +01:00
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' ,
'' ,
[ $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' );
2019-07-03 17:51:47 +02:00
$type = ( string ) get_parameter ( 'relation_type' );
2019-01-30 16:18:44 +01:00
if ( $id_module_a < 1 ) {
$name_module_a = get_parameter ( 'name_module_a' , '' );
if ( $name_module_a ) {
2019-07-03 17:51:47 +02:00
$id_module_a = ( int ) db_get_value (
'id_agente_modulo' ,
'tagente_modulo' ,
'nombre' ,
$name_module_a
);
2019-01-30 16:18:44 +01:00
} else {
echo json_encode ( $result );
return ;
}
}
if ( $id_module_b < 1 ) {
$name_module_b = get_parameter ( 'name_module_b' , '' );
if ( $name_module_b ) {
2019-07-03 17:51:47 +02:00
$id_module_b = ( int ) db_get_value (
'id_agente_modulo' ,
'tagente_modulo' ,
'nombre' ,
$name_module_b
);
2019-01-30 16:18:44 +01:00
} else {
echo json_encode ( $result );
return ;
}
}
if ( $id_module_a > 0 && $id_module_b > 0 ) {
2019-07-03 17:51:47 +02:00
$result = modules_add_relation ( $id_module_a , $id_module_b , $type );
2019-01-30 16:18:44 +01:00
}
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' ;
2020-05-21 19:28:24 +02:00
// Disable module edition in cluster module list.
$cluster_view = ( bool ) preg_match (
'/operation\/cluster\/cluster/' ,
$_SERVER [ 'HTTP_REFERER' ]
);
2023-01-04 15:46:32 +01:00
$agent_a = ( bool ) check_acl ( $config [ 'id_user' ], 0 , 'AR' );
$agent_w = ( bool ) check_acl ( $config [ 'id_user' ], 0 , 'AW' );
$access = ( $agent_a === true ) ? 'AR' : (( $agent_w === true ) ? 'AW' : 'AR' );
$id_agent = ( int ) get_parameter ( 'id_agente' );
2019-05-28 12:13:29 +02:00
$id_agente = $id_agent ;
2023-01-04 15:46:32 +01:00
$show_notinit = ( bool ) get_parameter ( 'show_notinit' );
$cluster_list = ( int ) get_parameter ( 'cluster_list' );
$sortField = ( string ) get_parameter ( 'sort_field' );
$sort = ( string ) get_parameter ( 'sort' , 'none' );
2019-01-30 16:18:44 +01:00
$url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $id_agent ;
2019-04-05 13:18:38 +02:00
$selectTypeUp = false ;
$selectTypeDown = false ;
$selectNameUp = false ;
$selectNameDown = false ;
$selectStatusUp = false ;
$selectStatusDown = false ;
$selectDataUp = false ;
$selectDataDown = false ;
$selectLastContactUp = false ;
$selectLastContactDown = false ;
$selected = true ;
2019-01-30 16:18:44 +01:00
$order [] = [
'field' => 'tmodule_group.name' ,
'order' => 'ASC' ,
];
switch ( $sortField ) {
case 'type' :
switch ( $sort ) {
case 'up' :
2019-05-28 12:13:29 +02:00
default :
2019-01-30 16:18:44 +01:00
$selectTypeUp = $selected ;
$order [] = [
'field' => 'tagente_modulo.id_modulo' ,
'order' => 'ASC' ,
];
break ;
case 'down' :
$selectTypeDown = $selected ;
$order [] = [
'field' => 'tagente_modulo.id_modulo' ,
'order' => 'DESC' ,
];
break ;
}
break ;
case 'name' :
switch ( $sort ) {
case 'up' :
$selectNameUp = $selected ;
$order [] = [
'field' => 'tagente_modulo.nombre' ,
'order' => 'ASC' ,
];
break ;
case 'down' :
$selectNameDown = $selected ;
$order [] = [
'field' => 'tagente_modulo.nombre' ,
'order' => 'DESC' ,
];
break ;
2019-05-28 12:13:29 +02:00
default :
// Ignore.
break ;
2019-01-30 16:18:44 +01:00
}
break ;
case 'status' :
switch ( $sort ) {
case 'up' :
$selectStatusUp = $selected ;
$order [] = [
'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 [] = [
'field' => 'tagente_estado.estado=1 DESC,tagente_estado.estado=2 DESC,tagente_estado.estado=3 DESC,tagente_estado.estado=0 DESC' ,
'order' => '' ,
];
break ;
2019-05-28 12:13:29 +02:00
default :
// Ignore.
break ;
2019-01-30 16:18:44 +01:00
}
break ;
case 'last_contact' :
switch ( $sort ) {
case 'up' :
$selectLastContactUp = $selected ;
$order [] = [
'field' => 'tagente_estado.utimestamp' ,
'order' => 'ASC' ,
];
break ;
case 'down' :
$selectLastContactDown = $selected ;
$order [] = [
'field' => 'tagente_estado.utimestamp' ,
'order' => 'DESC' ,
];
break ;
2019-05-28 12:13:29 +02:00
default :
// Ignore.
break ;
2019-01-30 16:18:44 +01:00
}
break ;
default :
2019-04-05 13:18:38 +02:00
$selectTypeUp = false ;
$selectTypeDown = false ;
2019-01-30 16:18:44 +01:00
$selectNameUp = $selected ;
2019-04-05 13:18:38 +02:00
$selectNameDown = false ;
$selectStatusUp = false ;
$selectStatusDown = false ;
$selectDataUp = false ;
$selectDataDown = false ;
$selectLastContactUp = false ;
$selectLastContactDown = false ;
2019-01-30 16:18:44 +01:00
$order [] = [
'field' => 'tagente_modulo.nombre' ,
'order' => 'ASC' ,
];
break ;
}
2019-05-28 12:13:29 +02:00
// Fix: for tag functionality groups have to be all user_groups
// (propagate ACL funct!).
2019-01-30 16:18:44 +01:00
$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' ;
} else if ( 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 ' ;
}
}
2023-01-04 15:46:32 +01:00
$status_filter_monitor = ( int ) get_parameter ( 'status_filter_monitor' , - 1 );
$status_text_monitor = ( string ) get_parameter ( 'status_text_monitor' );
$filter_monitors = ( bool ) get_parameter ( 'filter_monitors' );
$status_module_group = ( int ) get_parameter ( 'status_module_group' , - 1 );
$monitors_change_filter = ( bool ) get_parameter ( 'monitors_change_filter' );
2019-01-30 16:18:44 +01:00
$status_filter_sql = '1 = 1' ;
2023-01-04 15:46:32 +01:00
if ( $status_filter_monitor === AGENT_MODULE_STATUS_NOT_NORMAL ) {
2019-05-28 12:13:29 +02:00
// Not normal.
2019-01-30 16:18:44 +01:00
$status_filter_sql = ' tagente_estado.estado <> 0' ;
2023-01-04 15:46:32 +01:00
} else if ( $status_filter_monitor !== - 1 ) {
2019-01-30 16:18:44 +01:00
$status_filter_sql = 'tagente_estado.estado = ' . $status_filter_monitor ;
}
2023-01-04 15:46:32 +01:00
if ( $status_module_group !== - 1 ) {
2019-01-30 16:18:44 +01:00
$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 = '%' ;
2023-01-04 15:46:32 +01:00
if ( empty ( $status_text_monitor ) === false ) {
2019-01-30 16:18:44 +01:00
$status_text_monitor_sql .= $status_text_monitor . '%' ;
}
2023-01-04 15:46:32 +01:00
$monitor_filter = (( $show_notinit === false ) ? AGENT_MODULE_STATUS_NO_DATA : - 15 );
2019-01-30 16:18:44 +01:00
// Count monitors/modules
2019-05-28 12:13:29 +02:00
// Build the order sql.
2019-01-30 16:18:44 +01:00
$first = true ;
foreach ( $order as $ord ) {
2023-01-04 15:46:32 +01:00
if ( $first === true ) {
2019-01-30 16:18:44 +01:00
$first = false ;
} else {
$order_sql .= ',' ;
}
$order_sql .= $ord [ 'field' ] . ' ' . $ord [ 'order' ];
}
$sql_condition = " FROM tagente_modulo
2018-10-02 13:19:17 +02:00
$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
2018-10-31 08:57:34 +01:00
AND disabled = 0
2018-10-02 13:19:17 +02:00
AND $status_filter_sql
2018-11-06 11:14:12 +01:00
AND $status_module_group_filter
2018-10-02 13:19:17 +02:00
$tags_sql
AND tagente_estado . estado != $monitor_filter
" ;
2015-10-21 17:06:08 +02:00
2020-12-09 14:05:40 +01:00
$count_modules = db_get_all_rows_sql (
'SELECT COUNT(DISTINCT tagente_modulo.id_agente_modulo)' . $sql_condition
);
2018-11-06 11:14:12 +01:00
2023-01-04 15:46:32 +01:00
$count_modules = ( isset ( $count_modules [ 0 ]) === true ) ? reset ( $count_modules [ 0 ]) : 0 ;
2015-10-21 17:06:08 +02:00
2019-01-30 16:18:44 +01:00
// Get monitors/modules
2020-12-09 14:05:40 +01:00
// Get all module from agent.
2019-01-30 16:18:44 +01:00
$sql_modules_info = " SELECT tagente_estado.*, tagente_modulo.*, tmodule_group.*
2018-11-06 11:14:12 +01:00
$sql_condition
GROUP BY tagente_modulo . id_agente_modulo ORDER BY $order_sql " ;
2015-10-21 17:06:08 +02:00
2023-01-04 15:46:32 +01:00
if ( $monitors_change_filter === true ) {
2019-01-30 16:18:44 +01:00
$limit = ' LIMIT ' . $config [ 'block_size' ] . ' OFFSET 0' ;
} else {
$limit = ' LIMIT ' . $config [ 'block_size' ] . ' OFFSET ' . get_parameter ( 'offset' , 0 );
}
$paginate_module = false ;
2023-01-04 15:46:32 +01:00
if ( isset ( $config [ 'paginate_module' ]) === true ) {
$paginate_module = ( bool ) $config [ 'paginate_module' ];
2019-01-30 16:18:44 +01:00
}
2023-01-04 15:46:32 +01:00
if ( $paginate_module === true ) {
2019-01-30 16:18:44 +01:00
$modules = db_get_all_rows_sql ( $sql_modules_info . $limit );
} else {
$modules = db_get_all_rows_sql ( $sql_modules_info );
}
2023-01-04 15:46:32 +01:00
if ( empty ( $modules ) === true ) {
2019-01-30 16:18:44 +01:00
$modules = [];
}
2019-04-05 13:18:38 +02:00
// Urls to sort the table.
$url_up_type = $url . '&sort_field=type&sort=up&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
$url_down_type = $url . '&sort_field=type&sort=down&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
$url_up_name = $url . '&sort_field=name&sort=up&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
$url_down_name = $url . '&sort_field=name&sort=down&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
$url_up_status = $url . '&sort_field=status&sort=up&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
$url_down_status = $url . '&sort_field=status&sort=down&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
$url_up_last = $url . '&sort_field=last_contact&sort=up&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
$url_down_last = $url . '&sort_field=last_contact&sort=down&refr=&filter_monitors=1&status_filter_monitor=' . $status_filter_monitor . ' &status_text_monitor=' . $status_text_monitor . '&status_module_group= ' . $status_module_group ;
2023-01-11 13:02:18 +01:00
// Enterprise policies functions included.
2023-01-04 15:46:32 +01:00
$isFunctionPolicies = enterprise_include_once ( 'include/functions_policies.php' );
2023-01-11 13:02:18 +01:00
// Table.
2019-01-30 16:18:44 +01:00
$table = new stdClass ();
$table -> width = '100%' ;
2023-01-10 14:57:40 +01:00
$table -> styleTable = 'border: 0;border-radius: 0;vertical-align: baseline;' ;
2019-03-27 17:03:55 +01:00
$table -> cellpadding = 0 ;
$table -> cellspacing = 0 ;
2023-01-10 10:18:37 +01:00
$table -> class = 'tactical_table info_table' ;
2023-01-04 15:46:32 +01:00
$table -> align = [];
$table -> style = [];
2019-01-30 16:18:44 +01:00
$table -> head = [];
$table -> data = [];
2023-01-04 15:46:32 +01:00
$table -> headstyle = [];
// Cell alignments.
2019-06-03 19:13:29 +02:00
$table -> align [ 0 ] = 'center' ;
2023-01-04 15:46:32 +01:00
$table -> align [ 1 ] = 'center' ;
2019-06-03 14:30:23 +02:00
$table -> align [ 2 ] = 'left' ;
$table -> align [ 3 ] = 'left' ;
2023-01-04 15:46:32 +01:00
$table -> align [ 4 ] = 'center' ;
2019-06-03 14:30:23 +02:00
$table -> align [ 5 ] = 'left' ;
2023-01-04 15:46:32 +01:00
$table -> align [ 6 ] = 'left' ;
$table -> align [ 7 ] = 'center' ;
2023-01-10 14:57:40 +01:00
// Fixed styles.
$table -> headstyle [ 0 ] = 'width: 4%;text-align: center;' ;
$table -> headstyle [ 1 ] = 'width: 55px;text-align: left;' ;
$table -> headstyle [ 4 ] = 'width: 100px; text-align: center' ;
$table -> headstyle [ 7 ] = 'width: 130px; text-align: center' ;
$table -> headstyle [ 8 ] = 'width: 10%; text-align: center' ;
$table -> headstyle [ 9 ] = 'text-align: center' ;
2023-01-04 15:46:32 +01:00
// Row class.
2023-01-10 10:18:37 +01:00
$table -> head [ 0 ] = ( $isFunctionPolicies !== ENTERPRISE_NOT_HOOK ) ? '<span title="' . __ ( 'Policy' ) . '">' . __ ( 'P' ) . '</span>' : '' ;
2023-01-10 14:57:40 +01:00
$table -> head [ 1 ] = '<span title="' . __ ( 'Module type' ) . '">' . __ ( 'T' ) . '</span>' . ui_get_sorting_arrows ( $url_up_type , $url_down_type , $selectTypeUp , $selectTypeDown );
2023-01-10 10:18:37 +01:00
$table -> head [ 2 ] = '<span>' . __ ( 'Module name' ) . '</span>' . ui_get_sorting_arrows ( $url_up_name , $url_down_name , $selectNameUp , $selectNameDown );
$table -> head [ 3 ] = '<span>' . __ ( 'Description' ) . '</span>' ;
$table -> head [ 4 ] = '<span>' . __ ( 'Status' ) . '</span>' . ui_get_sorting_arrows ( $url_up_status , $url_down_status , $selectStatusUp , $selectStatusDown );
$table -> head [ 5 ] = '<span>' . __ ( 'Thresholds' ) . '</span>' ;
$table -> head [ 6 ] = '<span>' . __ ( 'Data' ) . '</span>' ;
$table -> head [ 7 ] = '<span>' . __ ( 'Last contact' ) . '</span>' . ui_get_sorting_arrows ( $url_up_last , $url_down_last , $selectLastContactUp , $selectLastContactDown );
$table -> head [ 8 ] = '<span>' . __ ( 'Graphs' ) . '</span>' ;
$table -> head [ 9 ] = '<span>' . __ ( 'Actions' ) . '</span>' ;
2019-05-29 12:06:05 +02:00
2019-01-30 16:18:44 +01:00
$last_modulegroup = 0 ;
2023-01-10 10:18:37 +01:00
$rowIndex = 0 ;
2019-01-30 16:18:44 +01:00
$id_type_web_content_string = db_get_value (
'id_tipo' ,
'ttipo_modulo' ,
'nombre' ,
'web_content_string'
);
$show_context_help_first_time = false ;
2023-01-10 10:18:37 +01:00
$hierachy_mode = ( string ) get_parameter ( 'hierachy_mode' );
2019-01-30 16:18:44 +01:00
2023-01-04 15:46:32 +01:00
if ( $hierachy_mode === 'true' ) {
2019-01-30 16:18:44 +01:00
$modules_hierachy = [];
$modules_hierachy = get_hierachy_modules_tree ( $modules );
$modules_dt = get_dt_from_modules_tree ( $modules_hierachy );
$modules = $modules_dt ;
}
foreach ( $modules as $module ) {
2023-01-04 15:46:32 +01:00
$idAgenteModulo = $module [ 'id_agente_modulo' ];
2023-01-10 10:18:37 +01:00
if ( $hierachy_mode === 'false' ) {
2019-01-30 16:18:44 +01:00
// 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 ) {
2023-01-10 14:57:40 +01:00
$table -> colspan [ $rowIndex ][ 0 ] = count ( $table -> head );
2019-01-30 16:18:44 +01:00
$table -> rowclass [ $rowIndex ] = 'datos4' ;
array_push ( $table -> data , [ '<b>' . $module [ 'name' ] . '</b>' ]);
$rowIndex ++ ;
$last_modulegroup = $module [ 'id_module_group' ];
}
2019-06-03 14:30:23 +02:00
// End of title of group.
2019-01-30 16:18:44 +01:00
}
2023-01-10 14:57:40 +01:00
$table -> rowstyle [ $rowIndex ] = 'vertical-align: baseline' ;
2019-01-30 16:18:44 +01:00
$data = [];
2023-01-04 15:46:32 +01:00
// Module policy.
$data [ 0 ] = '' ;
2019-01-30 16:18:44 +01:00
if ( $isFunctionPolicies !== ENTERPRISE_NOT_HOOK ) {
2023-01-04 15:46:32 +01:00
if (( int ) $module [ 'id_policy_module' ] !== 0 ) {
$linked = ( bool ) policies_is_module_linked ( $module [ 'id_agente_modulo' ]);
2019-01-30 16:18:44 +01:00
$id_policy = db_get_value_sql ( 'SELECT id_policy FROM tpolicy_modules WHERE id = ' . $module [ 'id_policy_module' ]);
2023-01-04 15:46:32 +01:00
$name_policy = ( empty ( $id_policy ) === false ) ? db_get_value_sql ( 'SELECT name FROM tpolicies WHERE id = ' . $id_policy ) : __ ( 'Unknown' );
2019-01-30 16:18:44 +01:00
$policyInfo = policies_info_module_policy ( $module [ 'id_policy_module' ]);
2023-01-04 15:46:32 +01:00
$adopt = policies_is_module_adopt ( $module [ 'id_agente_modulo' ]);
2019-01-30 16:18:44 +01:00
2023-05-04 18:24:11 +02:00
if (( bool ) $linked === true ) {
if (( bool ) $adopt === true ) {
2019-01-30 16:18:44 +01:00
$img = 'images/policies_brick.png' ;
$title = '(' . __ ( 'Adopted' ) . ') ' . $name_policy ;
} else {
2023-01-10 10:18:37 +01:00
$img = 'images/policy@svg.svg' ;
2019-01-30 16:18:44 +01:00
$title = $name_policy ;
}
} else {
2023-05-04 18:24:11 +02:00
if (( bool ) $adopt === true ) {
2019-01-30 16:18:44 +01:00
$img = 'images/policies_not_brick.png' ;
$title = '(' . __ ( 'Unlinked' ) . ') (' . __ ( 'Adopted' ) . ') ' . $name_policy ;
} else {
$img = 'images/unlinkpolicy.png' ;
$title = '(' . __ ( 'Unlinked' ) . ') ' . $name_policy ;
}
}
2023-01-04 15:46:32 +01:00
$data [ 0 ] .= html_print_anchor (
[
'href' => ui_get_full_url ( '?sec=gmodules&sec2=enterprise/godmode/policies/policies&id=' . $id_policy ),
2023-01-10 10:18:37 +01:00
'content' => html_print_image (
$img ,
true ,
[
'title' => $title ,
'style' => 'margin: 0 5px;' ,
'class' => 'main_menu_icon' ,
]
),
2023-01-04 15:46:32 +01:00
],
true
);
2019-01-30 16:18:44 +01:00
}
}
2023-01-04 15:46:32 +01:00
// Module server type.
$data [ 1 ] = '' ;
$data [ 1 ] .= ui_print_servertype_icon (( int ) $module [ 'id_modulo' ]);
2019-01-30 16:18:44 +01:00
2023-01-04 15:46:32 +01:00
// Module name.
$data [ 2 ] = '' ;
if ( isset ( $module [ 'deep' ]) === true && (( int ) $module [ 'deep' ] !== 0 )) {
$data [ 2 ] .= str_repeat ( ' ' , $module [ 'deep' ]);
$data [ 2 ] .= html_print_image ( 'images/icono_escuadra.png' , true , [ 'style' => 'padding-bottom: inherit;' ]) . ' ' ;
2019-01-30 16:18:44 +01:00
}
2023-01-04 15:46:32 +01:00
if (( bool ) $module [ 'quiet' ] === true ) {
$data [ 2 ] .= html_print_image (
2019-01-30 16:18:44 +01:00
'images/dot_blue.png' ,
true ,
[
'border' => '0' ,
'title' => __ ( 'Quiet' ),
'alt' => '' ,
]
2023-01-04 15:46:32 +01:00
);
2019-01-30 16:18:44 +01:00
}
2023-01-04 15:46:32 +01:00
$data [ 2 ] .= ui_print_truncate_text ( $module [ 'nombre' ], 'module_medium' , false , true , true , '…' , 'font-size: 9pt;' );
if ( empty ( $module [ 'extended_info' ]) === false ) {
$data [ 2 ] .= ui_print_help_tip ( $module [ 'extended_info' ], true , '/images/default_list.png' );
2019-01-30 16:18:44 +01:00
}
2019-05-28 12:13:29 +02:00
// Adds tag context information.
2019-01-30 16:18:44 +01:00
if ( tags_get_modules_tag_count ( $module [ 'id_agente_modulo' ]) > 0 ) {
2023-01-04 15:46:32 +01:00
$data [ 2 ] .= ' <a class="tag_details" href="ajax.php?page=operation/agentes/estado_monitores&get_tag_tooltip=1&id_agente_modulo=' . $module [ 'id_agente_modulo' ] . '">' . html_print_image ( 'images/tag_red.png' , true , [ 'id' => 'tag-details-' . $module [ 'id_agente_modulo' ], 'class' => 'img_help invert_filter' ]) . '</a> ' ;
2019-01-30 16:18:44 +01:00
}
2019-05-28 12:13:29 +02:00
// Adds relations context information.
2023-01-11 13:02:18 +01:00
if ( modules_relation_exists ( $module [ 'id_agente_modulo' ]) === true ) {
2023-01-04 15:46:32 +01:00
$data [ 2 ] .= ' <a class="relations_details" href="ajax.php?page=operation/agentes/estado_monitores&get_relations_tooltip=1&id_agente_modulo=' . $module [ 'id_agente_modulo' ] . '">' . html_print_image ( 'images/link2.png' , true , [ 'id' => 'relations-details-' . $module [ 'id_agente_modulo' ], 'class' => 'img_help' ]) . '</a> ' ;
2019-01-30 16:18:44 +01:00
}
2023-01-04 15:46:32 +01:00
// Module description.
$data [ 3 ] = '' ;
$data [ 3 ] .= ui_print_string_substr ( $module [ 'descripcion' ], 60 , true , 9 );
2019-01-30 16:18:44 +01:00
2023-01-04 15:46:32 +01:00
// Module status.
$data [ 4 ] = '' ;
if ( $module [ 'datos' ] !== strip_tags ( $module [ 'datos' ])) {
2019-01-30 16:18:44 +01:00
$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
);
2023-05-08 11:59:08 +02:00
if ( strlen ( $module [ 'ip_target' ]) !== 0 ) {
$title .= '<br/>IP: ' . $module [ 'ip_target' ];
}
2023-01-04 15:46:32 +01:00
$last_status_change_text = __ ( 'Time elapsed since last status change: ' );
$last_status_change_text .= ( empty ( $module [ 'last_status_change' ]) === false ) ? human_time_comparation ( $module [ 'last_status_change' ]) : __ ( 'N/A' );
2020-03-23 12:47:58 +01:00
2023-01-04 15:46:32 +01:00
if ( $show_context_help_first_time === false ) {
2019-01-30 16:18:44 +01:00
$show_context_help_first_time = true ;
2023-01-04 15:46:32 +01:00
if (( int ) $module [ 'estado' ] === AGENT_MODULE_STATUS_UNKNOWN ) {
$data [ 4 ] .= clippy_context_help ( 'module_unknow' );
2019-01-30 16:18:44 +01:00
}
}
2023-05-22 11:39:59 +02:00
$data [ 4 ] .= ui_print_status_image ( $status , htmlspecialchars ( $title ), true , false , false , true , $last_status_change_text );
2023-01-04 15:46:32 +01:00
// Module thresholds.
$data [ 5 ] = '' ;
if (( int ) $module [ 'id_tipo_modulo' ] !== 25 ) {
$data [ 5 ] = ui_print_module_warn_value ( $module [ 'max_warning' ], $module [ 'min_warning' ], $module [ 'str_warning' ], $module [ 'max_critical' ], $module [ 'min_critical' ], $module [ 'str_critical' ], $module [ 'warning_inverse' ], $module [ 'critical_inverse' ], 'class="font_9pt"' );
2019-01-30 16:18:44 +01:00
} else {
2023-01-04 15:46:32 +01:00
$data [ 5 ] = '' ;
2019-01-30 16:18:44 +01:00
}
2023-01-04 15:46:32 +01:00
// Module last value.
$data [ 6 ] = '' ;
$data [ 6 ] .= '<span class="inherited_text_data_for_humans">' . modules_get_agentmodule_data_for_humans ( $module ) . '</span>' ;
2019-01-30 16:18:44 +01:00
2023-01-10 10:18:37 +01:00
// Last contact.
2023-01-04 15:46:32 +01:00
$data [ 7 ] = '' ;
2023-01-10 10:18:37 +01:00
if (( int ) $module [ 'estado' ] === 3 ) {
$timestampClass = 'redb font_9pt' ;
} else {
$timestampClass = 'font_9pt' ;
}
$data [ 7 ] .= ui_print_timestamp ( $module [ 'utimestamp' ], true , [ 'class' => $timestampClass ]);
// Graph buttons.
$data [ 8 ] = '' ;
2023-01-04 15:46:32 +01:00
if (( int ) $module [ 'history_data' ] === 1 ) {
2021-12-14 13:21:34 +01:00
if ( empty (( float ) $module [ 'min_warning' ]) === true
&& empty (( float ) $module [ 'max_warning' ]) === true
&& empty ( $module [ 'warning_inverse' ]) === true
&& empty (( float ) $module [ 'min_critical' ]) === true
&& empty (( float ) $module [ 'max_critical' ]) === true
&& empty ( $module [ 'critical_inverse' ]) === true
) {
$tresholds = false ;
2023-01-04 15:46:32 +01:00
} else {
$tresholds = true ;
2021-12-14 13:21:34 +01:00
}
2023-01-04 15:46:32 +01:00
$graphButtons = [];
$graph_type = return_graphtype ( $module [ 'id_tipo_modulo' ]);
2019-01-30 16:18:44 +01:00
$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' ]));
2023-01-04 15:46:32 +01:00
// Show events for boolean modules by default.
$draw_events = ( $graph_type === 'boolean' ) ? 1 : 0 ;
2021-12-14 13:21:34 +01:00
// Try to display the SNMP module realtime graph.
2019-01-30 16:18:44 +01:00
$rt_button = get_module_realtime_link_graph ( $module );
2023-01-04 15:46:32 +01:00
if ( empty ( $rt_button ) === false ) {
$graphButtons [] = $rt_button ;
2019-01-30 16:18:44 +01:00
}
2021-12-14 13:21:34 +01:00
if ( $tresholds === true || $graph_type === 'boolean' ) {
2023-01-04 15:46:32 +01:00
$link = 'winopeng_var(\'operation/agentes/stat_win.php?type=' . $graph_type . '&period=' . SECONDS_1DAY . '&id=' . $module [ 'id_agente_modulo' ] . '&refresh=' . SECONDS_10MINUTES . '&histogram=1\', \'day_' . $win_handle . '\', 800, 480)' ;
$graphButtons [] = html_print_anchor (
2021-12-14 13:21:34 +01:00
[
2023-01-04 15:46:32 +01:00
'href' => 'javascript:' . $link ,
'content' => html_print_image (
'images/event-history.svg' ,
true ,
2023-06-02 11:42:18 +02:00
[
'title' => __ ( 'Event history' ),
'class' => 'main_menu_icon forced_title' ,
]
2023-01-04 15:46:32 +01:00
),
],
true
);
2021-12-14 13:21:34 +01:00
}
2023-01-04 15:46:32 +01:00
if ( is_snapshot_data ( $module [ 'datos' ]) === false ) {
2023-01-04 16:03:41 +01:00
$link = 'winopeng_var(\'operation/agentes/stat_win.php?type=' . $graph_type . '&period=' . SECONDS_1DAY . '&id=' . $module [ 'id_agente_modulo' ] . '&refresh=' . SECONDS_10MINUTES . '&draw_events=' . $draw_events . '\', \'day_' . $win_handle . '\', 800, 480)' ;
2023-01-04 15:46:32 +01:00
$graphButtons [] = html_print_anchor (
2021-03-11 15:40:23 +01:00
[
2023-01-04 15:46:32 +01:00
'href' => 'javascript:' . $link ,
'content' => html_print_image (
'images/module-graph.svg' ,
true ,
2023-05-23 15:20:30 +02:00
[
2023-06-02 11:42:18 +02:00
'title' => __ ( 'Module graph' ),
2023-05-23 15:20:30 +02:00
'class' => 'main_menu_icon forced_title' ,
]
2023-01-04 15:46:32 +01:00
),
],
true
);
2019-01-30 16:18:44 +01:00
}
2019-08-26 12:26:43 +02:00
$modules_get_agentmodule_name = modules_get_agentmodule_name ( $module [ 'id_agente_modulo' ]);
// Escape the double quotes that may have the name of the module.
$modules_get_agentmodule_name = str_replace ( '"' , '\"' , $modules_get_agentmodule_name );
2023-01-04 15:46:32 +01:00
$graphButtons [] = html_print_anchor (
2021-03-11 15:40:23 +01:00
[
2023-01-04 15:46:32 +01:00
'href' => 'javascript: show_module_detail_dialog(' . $module [ 'id_agente_modulo' ] . ', ' . $id_agente . ', \'\', ' . ( 0 ) . ', ' . SECONDS_1DAY . ', \'' . $modules_get_agentmodule_name . '\')' ,
'content' => html_print_image (
'images/simple-value.svg' ,
true ,
2023-06-02 11:42:18 +02:00
[
'title' => __ ( 'Module detail' ),
'class' => 'main_menu_icon forced_title' ,
]
2023-01-04 15:46:32 +01:00
),
],
true
);
2023-01-10 10:18:37 +01:00
$data [ 8 ] = html_print_div (
2023-01-04 15:46:32 +01:00
[
'class' => 'table_action_buttons' ,
'content' => implode ( '' , $graphButtons ),
],
true
);
2019-01-30 16:18:44 +01:00
}
2023-01-04 15:46:32 +01:00
// Actions.
$data [ 9 ] = '' ;
$moduleActionButtons = [];
if ((( int ) $module [ 'id_modulo' ] !== 1 ) && (( int ) $module [ 'id_tipo_modulo' ] !== 100 )) {
if ( $agent_w === true ) {
if (( int ) $module [ 'flag' ] === 0 ) {
$additionalLinkAction = '&flag=1' ;
$linkCaption = __ ( 'Force checks' );
2023-03-30 08:43:23 +02:00
$imgaction = 'images/force@svg.svg' ;
2023-01-04 15:46:32 +01:00
} else {
$additionalLinkAction = '' ;
$linkCaption = __ ( 'Refresh' );
2023-03-27 14:07:36 +02:00
$imgaction = 'images/go-back@svg.svg' ;
2023-01-04 15:46:32 +01:00
}
2023-03-10 14:49:38 +01:00
$moduleActionButtons [] = html_print_anchor (
2023-01-04 15:46:32 +01:00
[
2023-03-27 14:07:36 +02:00
'href' => 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $id_agente . '&id_agente_modulo=' . $module [ 'id_agente_modulo' ] . '&refr=60' . $additionalLinkAction . '"' ,
2023-03-10 14:49:38 +01:00
'content' => html_print_image (
2023-03-27 14:07:36 +02:00
$imgaction ,
2023-03-10 14:49:38 +01:00
true ,
2023-06-02 12:03:29 +02:00
[
'title' => __ ( 'Force remote check' ),
'class' => 'main_menu_icon forced_title' ,
]
2023-03-10 14:49:38 +01:00
),
2023-01-04 15:46:32 +01:00
],
true
);
}
2019-01-30 16:18:44 +01:00
}
2023-01-04 15:46:32 +01:00
if (( bool ) check_acl ( $config [ 'id_user' ], $id_grupo , 'AW' ) === true
&& $cluster_view === false
) {
2023-03-10 14:49:38 +01:00
$moduleActionButtons [] = html_print_anchor (
2023-01-04 15:46:32 +01:00
[
2023-03-10 14:49:38 +01:00
'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente=' . $id_agente . '&tab=module&id_agent_module=' . $module [ 'id_agente_modulo' ] . '&edit_module=' . $module [ 'id_modulo' ] . '"' ,
'content' => html_print_image (
'images/edit.svg' ,
true ,
2023-06-02 12:03:29 +02:00
[
'title' => __ ( 'Edit configuration' ),
'class' => 'main_menu_icon forced_title' ,
]
2023-03-10 14:49:38 +01:00
),
2023-01-04 15:46:32 +01:00
],
true
);
}
$data [ 9 ] = html_print_div (
[
'class' => 'table_action_buttons' ,
'content' => implode ( '' , $moduleActionButtons ),
],
true
);
2019-01-30 16:18:44 +01:00
array_push ( $table -> data , $data );
$rowIndex ++ ;
}
2020-06-08 11:24:46 +02:00
ui_require_javascript_file ( 'pandora.js' );
2019-01-30 16:18:44 +01:00
?>
< script type = " text/javascript " >
/* <![CDATA[ */
$ ( " a.tag_details " ) . cluetip ({
arrows : true ,
attribute : 'href' ,
cluetipClass : 'default'
})
. click ( function () {
return false ;
});
$ ( " a.relations_details " ) . cluetip ({
width : 500 ,
arrows : true ,
attribute : 'href' ,
cluetipClass : 'default'
})
. click ( function () {
return false ;
});
/* ]]> */
</ script >
< ? php
2023-01-11 13:02:18 +01:00
if ( empty ( $table -> data ) === true ) {
ui_print_info_message (
[
'no_close' => true ,
'message' => ( $filter_monitors === true ) ? __ ( 'Any monitors aren\'t with this filter.' ) : __ ( 'This agent doesn\'t have any active monitors.' ),
]
);
2019-01-30 16:18:44 +01:00
} else {
2019-06-03 14:30:23 +02:00
$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 ;
2019-01-30 16:18:44 +01:00
2023-01-11 13:02:18 +01:00
if ( $paginate_module === true ) {
2019-01-30 16:18:44 +01:00
ui_pagination (
$count_modules ,
false ,
0 ,
0 ,
false ,
'offset' ,
true ,
'' ,
'pagination_list_modules(offset_param)' ,
[
'count' => '' ,
'offset' => 'offset_param' ,
]
);
}
html_print_table ( $table );
2023-01-11 13:02:18 +01:00
if ( $paginate_module === true ) {
2019-01-30 16:18:44 +01:00
ui_pagination (
$count_modules ,
false ,
0 ,
0 ,
false ,
'offset' ,
true ,
2023-03-23 12:41:39 +01:00
'' ,
2019-01-30 16:18:44 +01:00
'pagination_list_modules(offset_param)' ,
[
'count' => '' ,
'offset' => 'offset_param' ,
]
);
}
}
unset ( $table );
unset ( $table_data );
}
2023-01-11 13:02:18 +01:00
if ( $get_type === true ) {
2019-01-30 16:18:44 +01:00
$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 ;
}
2020-12-09 14:05:40 +01:00
if ( $get_graph_module === true ) {
global $config ;
$output = '' ;
$graph_data = get_parameter ( 'graph_data' , '' );
$params = json_decode ( base64_decode ( $graph_data ), true );
$server_id = ( int ) get_parameter ( 'server_id' , 0 );
include_once $config [ 'homedir' ] . '/include/functions_graph.php' ;
// Metaconsole connection to the node.
if ( is_metaconsole () === true && empty ( $server_id ) === false ) {
$server = metaconsole_get_connection_by_id ( $server_id );
metaconsole_connect ( $server );
}
2023-08-31 13:42:52 +02:00
if ( $params [ 'enable_projected_period' ] === '1' ) {
$params_graphic = [
'period' => $params [ 'period' ],
'date' => strtotime ( date ( 'Y-m-d H:i:s' )),
'only_image' => false ,
'homeurl' => ui_get_full_url ( false , false , false , false ) . '/' ,
'ttl' => false ,
'height' => $config [ 'graph_image_height' ],
'landscape' => $content [ 'landscape' ],
'return_img_base_64' => true ,
];
$params_combined = [
'projection' => $params [ 'period_projected' ],
];
2021-12-14 13:21:34 +01:00
2023-08-31 13:42:52 +02:00
$return [ 'chart' ] = graphic_combined_module (
[ $params [ 'agent_module_id' ]],
$params_graphic ,
$params_combined
);
2021-12-14 13:21:34 +01:00
$output .= '<div class="stat_win_histogram">' ;
2023-08-31 13:42:52 +02:00
$output .= $return [ 'chart' ];
$output .= '</div>' ;
} else {
if ( $params [ 'histogram' ] === true ) {
$params [ 'id_agent_module' ] = $params [ 'agent_module_id' ];
$params [ 'dinamic_proc' ] = 1 ;
$output .= '<div class="stat_win_histogram">' ;
if ( $params [ 'compare' ] === 'separated' ) {
$graph = \reporting_module_histogram_graph (
[ 'datetime' => ( $params [ 'begin_date' ] - $params [ 'period' ])],
$params
);
$output .= $graph [ 'chart' ];
}
2021-12-14 13:21:34 +01:00
$graph = \reporting_module_histogram_graph (
2023-08-31 13:42:52 +02:00
[ 'datetime' => $params [ 'begin_date' ]],
2021-12-14 13:21:34 +01:00
$params
);
$output .= $graph [ 'chart' ];
2023-08-31 13:42:52 +02:00
$output .= '</div>' ;
} else {
$output .= grafico_modulo_sparse ( $params );
2021-12-14 13:21:34 +01:00
}
}
2020-12-09 14:05:40 +01:00
if ( is_metaconsole () === true && empty ( $server_id ) === false ) {
metaconsole_restore_db ();
}
2022-01-19 12:18:23 +01:00
echo $output ;
2020-12-09 14:05:40 +01:00
return ;
}
if ( $get_graph_module_interfaces === true ) {
global $config ;
include_once $config [ 'homedir' ] . '/include/functions_graph.php' ;
$output = '' ;
$graph_data = get_parameter ( 'graph_data' , '' );
$params = json_decode ( base64_decode ( $graph_data ), true );
$modules = get_parameter ( 'modules' , '' );
$modules = json_decode ( base64_decode ( $modules ), true );
$graph_data_combined = get_parameter ( 'graph_data_combined' , '' );
$params_combined = json_decode (
base64_decode ( $graph_data_combined ),
true
);
$output .= graphic_combined_module (
$modules ,
$params ,
$params_combined
);
echo $output ;
return ;
}
2022-11-08 16:30:25 +01:00
if ( $get_data_dataMatrix === true ) {
global $config ;
$table_id = get_parameter ( 'table_id' , '' );
$modules = json_decode (
io_safe_output (
get_parameter ( 'modules' , '' )
),
true
);
$period = get_parameter ( 'period' , 0 );
$slice = get_parameter ( 'slice' , 0 );
// Datatables offset, limit.
$start = get_parameter ( 'start' , 0 );
2022-11-10 12:05:25 +01:00
$formatData = ( bool ) get_parameter ( 'formatData' , 0 );
2022-11-08 16:30:25 +01:00
$length = get_parameter (
'length' ,
$config [ 'block_size' ]
);
$order = get_datatable_order ( true );
2022-12-13 10:41:38 +01:00
// Total time per page.
2022-11-08 16:30:25 +01:00
$time_all_box = ( $length * $slice );
2022-12-13 10:41:38 +01:00
// Total number of boxes.
2022-11-08 16:30:25 +01:00
$total_box = ceil ( $period / $slice );
if ( $start > 0 ) {
$start = ( $start / $length );
}
// Uncompress.
try {
ob_start ();
2022-12-13 10:41:38 +01:00
$dateNow = get_system_time ();
$final = ( $dateNow - $period );
$date = ( $dateNow - ( $time_all_box * $start ));
if (( $date - $time_all_box ) > $final ) {
$datelimit = ( $date - $time_all_box );
} else {
$datelimit = $final ;
}
2022-11-08 16:30:25 +01:00
foreach ( $modules as $key => $value ) {
2022-11-10 16:10:50 +01:00
if ( is_metaconsole () === true ) {
try {
$node = new Node (( int ) $value [ 'id_node' ]);
$node -> connect ();
} catch ( \Exception $e ) {
// Unexistent agent.
$node -> disconnect ();
}
}
2022-11-10 12:05:25 +01:00
$value [ 'thresholds' ] = [
'min_critical' => ( empty ( $value [ 'c_min' ]) === true ) ? null : $value [ 'c_min' ],
'max_critical' => ( empty ( $value [ 'c_max' ]) === true ) ? null : $value [ 'c_max' ],
'min_warning' => ( empty ( $value [ 'w_min' ]) === true ) ? null : $value [ 'w_min' ],
'max_warning' => ( empty ( $value [ 'w_max' ]) === true ) ? null : $value [ 'w_max' ],
];
2022-11-08 16:30:25 +01:00
$module_data = db_uncompress_module_data (
$value [ 'id' ],
$datelimit ,
$date ,
$slice ,
true
);
$uncompressData [] = array_reduce (
$module_data ,
2022-11-10 12:05:25 +01:00
function ( $carry , $item ) use ( $value , $config , $formatData ) {
// Last value.
$vdata = null ;
2022-11-08 16:30:25 +01:00
if ( is_array ( $item [ 'data' ]) === true ) {
2022-11-10 12:05:25 +01:00
foreach ( $item [ 'data' ] as $v ) {
$vdata = $v [ 'datos' ];
2022-11-08 16:30:25 +01:00
}
}
2022-11-10 12:05:25 +01:00
$status = get_status_data_modules (
$value [ 'id' ],
$vdata ,
$value [ 'thresholds' ]
);
2022-11-10 16:10:50 +01:00
2023-03-13 19:30:51 +01:00
$resultData = '<span class="widget-module-tabs-data" style="color:' . $status [ 'color' ] . '">' ;
2022-11-10 16:10:50 +01:00
if ( $vdata !== null && $vdata !== '' && $vdata !== false ) {
2022-11-10 12:05:25 +01:00
if ( isset ( $formatData ) === true
&& ( bool ) $formatData === true
) {
$resultData .= format_for_graph (
$vdata ,
$config [ 'graph_precision' ]
);
} else {
$resultData .= sla_truncate (
$vdata ,
$config [ 'graph_precision' ]
);
}
$resultData .= ' ' . $value [ 'unit' ];
} else {
$resultData .= '--' ;
}
$resultData .= '</span>' ;
$carry [] = [
'utimestamp' => $item [ 'utimestamp' ],
'Column-' . $value [ 'id' ] => $resultData ,
];
2022-11-08 16:30:25 +01:00
return $carry ;
},
[]
);
2022-11-10 16:10:50 +01:00
if ( is_metaconsole () === true ) {
$node -> disconnect ();
}
2022-11-08 16:30:25 +01:00
}
if ( empty ( $uncompressData ) === false ) {
$data = array_reduce (
$uncompressData ,
function ( $carry , $item ) {
foreach ( $item as $data_module ) {
foreach ( $data_module as $key => $value ) {
if ( $key === 'utimestamp' ) {
$carry [ $data_module [ 'utimestamp' ]][ 'date' ] = date ( 'Y-m-d H:i' , ( int ) $value );
} else {
$carry [ $data_module [ 'utimestamp' ]][ $key ] = $value ;
}
}
}
return $carry ;
}
);
}
if ( empty ( $data ) === false ) {
$data = array_reverse ( array_values ( $data ));
} else {
$data = [];
}
// RecordsTotal && recordsfiltered resultados totales.
echo json_encode (
[
'data' => $data ,
'recordsTotal' => $total_box ,
'recordsFiltered' => $total_box ,
]
);
$response = ob_get_clean ();
// Clean output buffer.
while ( ob_get_level () !== 0 ) {
ob_end_clean ();
}
} catch ( Exception $e ) {
echo json_encode (
[ 'error' => $e -> getMessage ()]
);
}
// If not valid it will throw an exception.
json_decode ( $response );
2023-01-11 13:02:18 +01:00
if ( json_last_error () === JSON_ERROR_NONE ) {
2022-11-08 16:30:25 +01:00
// If valid dump.
echo $response ;
} else {
echo json_encode (
[ 'error' => $response ]
);
}
return ;
}
2023-01-24 12:26:49 +01:00
2023-02-09 10:12:59 +01:00
if ( $get_data_ModulesByStatus === true ) {
global $config ;
$data = [];
$table_id = get_parameter ( 'table_id' , '' );
$search = get_parameter ( 'search' , '' );
$status = get_parameter ( 'status' , '' );
$start = get_parameter ( 'start' , 0 );
$length = get_parameter ( 'length' , $config [ 'block_size' ]);
// There is a limit of (2^32)^2 (18446744073709551615) rows in a MyISAM table, show for show all use max nrows.
$length = ( $length != '-1' ) ? $length : '18446744073709551615' ;
$order = get_datatable_order ( true );
$nodes = get_parameter ( 'nodes' , 0 );
2023-05-26 08:57:45 +02:00
$disabled_modules = ( bool ) get_parameter ( 'disabled_modules' , false );
2023-02-09 10:12:59 +01:00
$where = '' ;
$recordsTotal = 0 ;
if ( empty ( $search ) === false ) {
$where = 'tagente_modulo.nombre LIKE "%%' . $search . '%%" AND ' ;
}
2023-03-23 09:18:39 +01:00
if ( str_contains ( $status , '6' ) === true ) {
$expl = explode ( ',' , $status );
$exist = array_search ( '6' , $expl );
if ( isset ( $exist ) === true ) {
unset ( $expl [ $exist ]);
}
array_push ( $expl , '1' , '2' );
$status = implode ( ',' , $expl );
}
2023-02-09 10:12:59 +01:00
$where .= sprintf (
' tagente_estado . estado IN ( % s )
AND tagente_modulo . delete_pending = 0 ' ,
2023-05-26 08:57:45 +02:00
$status ,
2023-02-09 10:12:59 +01:00
);
2023-05-26 08:57:45 +02:00
if ( $disabled_modules === false ) {
$where .= ' AND tagente_modulo.disabled = 0' ;
}
2023-02-09 10:12:59 +01:00
if ( is_metaconsole () === false ) {
$order_by = '' ;
switch ( $order [ 'field' ]) {
case 'nombre' :
$order_by = 'tagente_modulo.' . $order [ 'field' ] . ' ' . $order [ 'direction' ];
break ;
case 'alias' :
$order_by = 'tagente.' . $order [ 'field' ] . ' ' . $order [ 'direction' ];
break ;
case 'last_status_change' :
$order_by = 'tagente_estado.' . $order [ 'field' ] . ' ' . $order [ 'direction' ];
break ;
case 'estado' :
$order_by = 'tagente_estado.' . $order [ 'field' ] . ' ' . $order [ 'direction' ];
break ;
default :
$order_by = 'tagente_estado.last_status_change desc' ;
break ;
}
$sql = sprintf (
' SELECT
tagente_modulo . nombre ,
tagente . alias ,
tagente . id_agente ,
tagente_estado . last_status_change ,
tagente_estado . estado
FROM tagente_modulo
INNER JOIN tagente
ON tagente_modulo . id_agente = tagente . id_agente
INNER JOIN tagente_estado
ON tagente_estado . id_agente_modulo = tagente_modulo . id_agente_modulo
WHERE % s
ORDER BY % s
LIMIT % d , % d ' ,
$where ,
$order_by ,
$start ,
$length
);
$data = db_get_all_rows_sql ( $sql );
$sql_count = sprintf (
' SELECT COUNT ( * ) AS " total "
FROM tagente_modulo
INNER JOIN tagente
ON tagente_modulo . id_agente = tagente . id_agente
INNER JOIN tagente_estado
2023-03-15 11:30:22 +01:00
ON tagente_estado . id_agente_modulo = tagente_modulo . id_agente_modulo
WHERE % s ' ,
$where
2023-02-09 10:12:59 +01:00
);
$recordsTotal = db_get_value_sql ( $sql_count );
// Metaconsole.
} else {
// $servers_ids = array_column(metaconsole_get_servers(), 'id');
$servers_ids = explode ( ',' , $nodes );
foreach ( $servers_ids as $server_id ) {
try {
$node = new Node (( int ) $server_id );
$node -> connect ();
$sql = sprintf (
' SELECT
tagente_modulo . nombre ,
tagente . alias ,
tagente . id_agente ,
tagente_estado . last_status_change ,
tagente_estado . estado
FROM tagente_modulo
INNER JOIN tagente
ON tagente_modulo . id_agente = tagente . id_agente
INNER JOIN tagente_estado
ON tagente_estado . id_agente_modulo = tagente_modulo . id_agente_modulo
WHERE % s ' ,
$where
);
$res_sql = db_get_all_rows_sql ( $sql );
foreach ( $res_sql as $row_sql ) {
$row_sql [ 'server_name' ] = $node -> server_name ();
$row_sql [ 'server_url' ] = $node -> server_url ();
array_push ( $data , $row_sql );
}
$node -> disconnect ();
} catch ( \Exception $e ) {
// Unexistent modules.
$node -> disconnect ();
}
}
2023-03-15 11:30:22 +01:00
if ( in_array ( 0 , $servers_ids ) === true ) {
$sql = sprintf (
' SELECT
tagente_modulo . nombre ,
tagente . alias ,
tagente . id_agente ,
tagente_estado . last_status_change ,
tagente_estado . estado
FROM tagente_modulo
INNER JOIN tagente
ON tagente_modulo . id_agente = tagente . id_agente
INNER JOIN tagente_estado
ON tagente_estado . id_agente_modulo = tagente_modulo . id_agente_modulo
WHERE % s ' ,
$where
);
$res_sql = db_get_all_rows_sql ( $sql );
foreach ( $res_sql as $row_sql ) {
$row_sql [ 'server_name' ] = __ ( 'Metaconsole' );
$row_sql [ 'server_url' ] = $config [ 'homeurl' ];
array_push ( $data , $row_sql );
}
}
2023-02-09 10:12:59 +01:00
// Drop temporary table if exist.
db_process_sql ( 'DROP TEMPORARY TABLE IF EXISTS temp_modules_status;' );
$table_temporary = ' CREATE TEMPORARY TABLE IF NOT EXISTS temp_modules_status (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
nombre VARCHAR ( 600 ),
alias VARCHAR ( 600 ),
id_agente INT ,
last_status_change INT ,
estado INT ,
server_name VARCHAR ( 100 ),
server_url VARCHAR ( 200 ),
PRIMARY KEY ( `id` ),
KEY `nombre` ( `nombre` ( 600 ))
) ' ;
db_process_sql ( $table_temporary );
$result = db_process_sql_insert_multiple ( 'temp_modules_status' , $data );
if ( empty ( $result ) === false ) {
$data = [];
$sql = '' ;
$where = '' ;
if ( empty ( $search ) === false ) {
$where = 'nombre LIKE "%%' . $search . '%%" AND ' ;
}
$where .= sprintf (
'estado IN (%s)' ,
$status
);
$order_by = $order [ 'field' ] . ' ' . $order [ 'direction' ];
$sql = sprintf (
' SELECT
nombre ,
alias ,
id_agente ,
last_status_change ,
estado ,
server_name ,
server_url
FROM temp_modules_status
WHERE % s
ORDER BY % s
LIMIT % d , % d ' ,
$where ,
$order_by ,
$start ,
$length
);
$data = db_get_all_rows_sql ( $sql );
$sql_count = sprintf (
' SELECT COUNT ( * ) AS " total "
2023-03-15 11:30:22 +01:00
FROM temp_modules_status
WHERE % s ' ,
$where
2023-02-09 10:12:59 +01:00
);
$recordsTotal = db_get_value_sql ( $sql_count );
}
}
if ( $data === false ) {
$data = [];
}
foreach ( $data as $key => $row ) {
$data [ $key ][ 'nombre' ] = html_ellipsis_characters ( $row [ 'nombre' ], 35 , true );
if ( is_metaconsole () === false ) {
$name_link = '<a href="index.php?sec=estado&sec2=' ;
} else {
$name_link = '<a href="' . $row [ 'server_url' ] . 'index.php?sec=estado&sec2=' ;
}
$name_link .= 'operation/agentes/ver_agente&id_agente=' . $row [ 'id_agente' ];
$name_link .= '"><b>' ;
$name_link .= '<span class="ellipsis-35ch">' . html_ellipsis_characters ( $row [ 'alias' ], 35 , true ) . '</span>' ;
$name_link .= '</b></a>' ;
$data [ $key ][ 'alias' ] = $name_link ;
$data [ $key ][ 'last_status_change' ] = ui_print_timestamp (
$row [ 'last_status_change' ],
true
);
switch (( int ) $row [ 'estado' ]) {
case 0 :
$status_img = ui_print_status_image ( STATUS_MODULE_OK , __ ( 'Normal' ), true );
break ;
case 1 :
case 6 :
$status_img = ui_print_status_image ( STATUS_MODULE_CRITICAL , __ ( 'Critical' ), true );
break ;
case 2 :
$status_img = ui_print_status_image ( STATUS_MODULE_WARNING , __ ( 'Warning' ), true );
break ;
case 3 :
$status_img = ui_print_status_image ( STATUS_MODULE_UNKNOWN , __ ( 'Unknown' ), true );
break ;
case 5 :
$status_img = ui_print_status_image ( STATUS_MODULE_NO_DATA , __ ( 'Not init' ), true );
break ;
default :
$status_img = '' ;
break ;
}
$data [ $key ][ 'estado' ] = $status_img ;
}
echo json_encode (
[
'data' => $data ,
'recordsTotal' => $recordsTotal ,
'recordsFiltered' => $recordsTotal ,
]
);
}
2023-01-24 12:26:49 +01:00
if ( $get_children_modules === true ) {
$parent_modules = get_parameter ( 'parent_modulues' , false );
$children_selected = [];
if ( $parent_modules === false ) {
$children_selected = false ;
} else {
foreach ( $parent_modules as $parent ) {
2023-01-25 18:03:54 +01:00
$child_modules = get_children_module ( $parent_modules , [ 'nombre' , 'id_agente_modulo' ], true );
2023-01-24 12:26:49 +01:00
if (( bool ) $child_modules === false ) {
continue ;
}
foreach ( $child_modules as $child ) {
2023-01-25 18:03:54 +01:00
$module_exist = in_array ( $child [ 'id_agente_modulo' ], $parent_modules );
2023-01-24 12:26:49 +01:00
$child_exist = in_array ( $child , $children_selected );
if ( $module_exist === false && $child_exist === false ) {
array_push ( $children_selected , $child );
}
}
}
}
if ( empty ( $children_selected ) === true ) {
$children_selected = false ;
}
echo json_encode ( $children_selected );
2023-02-01 09:36:42 +01:00
return ;
}
2023-01-19 10:49:48 +01:00
// Saves an event filter.
if ( $save_monitor_filter ) {
$values = [];
$values [ 'id_name' ] = get_parameter ( 'id_name' );
$values [ 'id_group_filter' ] = get_parameter ( 'id_group_filter' );
$values [ 'ag_group' ] = get_parameter ( 'ag_group' );
$values [ 'modulegroup' ] = get_parameter ( 'modulegroup' );
$values [ 'recursion' ] = get_parameter ( 'recursion' );
$values [ 'status' ] = get_parameter ( 'status' );
$values [ 'ag_modulename' ] = get_parameter ( 'ag_modulename' );
$values [ 'ag_freestring' ] = get_parameter ( 'ag_freestring' );
$values [ 'tag_filter' ] = json_encode ( get_parameter ( 'tag_filter' ));
$values [ 'moduletype' ] = get_parameter ( 'moduletype' );
$values [ 'module_option' ] = get_parameter ( 'module_option' );
$values [ 'min_hours_status' ] = get_parameter ( 'min_hours_status' );
$values [ 'datatype' ] = get_parameter ( 'datatype' );
$values [ 'not_condition' ] = get_parameter ( 'not_condition' );
$values [ 'ag_custom_fields' ] = get_parameter ( 'ag_custom_fields' );
$exists = ( bool ) db_get_value_filter (
'id_filter' ,
'tmonitor_filter' ,
$values
);
if ( $exists === true ) {
echo 'duplicate' ;
} else {
$result = db_process_sql_insert ( 'tmonitor_filter' , $values );
if ( $result === false ) {
echo 'error' ;
} else {
echo $result ;
}
}
}
if ( $update_monitor_filter ) {
$values = [];
$id = get_parameter ( 'id' );
$values [ 'ag_group' ] = get_parameter ( 'ag_group' );
$values [ 'modulegroup' ] = get_parameter ( 'modulegroup' );
$values [ 'recursion' ] = get_parameter ( 'recursion' );
$values [ 'status' ] = get_parameter ( 'status' );
$values [ 'ag_modulename' ] = get_parameter ( 'ag_modulename' );
$values [ 'ag_freestring' ] = get_parameter ( 'ag_freestring' );
$values [ 'tag_filter' ] = json_encode ( get_parameter ( 'tag_filter' ));
$values [ 'moduletype' ] = get_parameter ( 'moduletype' );
$values [ 'module_option' ] = get_parameter ( 'module_option' );
$values [ 'min_hours_status' ] = get_parameter ( 'min_hours_status' );
$values [ 'datatype' ] = get_parameter ( 'datatype' );
$values [ 'not_condition' ] = get_parameter ( 'not_condition' );
$values [ 'ag_custom_fields' ] = get_parameter ( 'ag_custom_fields' );
$result = db_process_sql_update (
'tmonitor_filter' ,
$values ,
[ 'id_filter' => $id ]
);
if ( $result === false ) {
echo 'error' ;
} else {
2023-03-17 12:25:43 +01:00
ui_update_name_fav_element ( $id , 'Modules' , $values [ 'ag_modulename' ]);
2023-01-19 10:49:48 +01:00
echo 'ok' ;
}
}
2023-02-28 17:06:31 +01:00
if ( $delete_monitor_filter ) {
$id = get_parameter ( 'id' );
$user_groups = users_get_groups (
$config [ 'id_user' ],
'AW' ,
users_can_manage_group_all ( 'AW' ),
true
);
$sql = ' DELETE
FROM tmonitor_filter
WHERE id_filter = '.$id.' AND id_group_filter IN ( '.implode(' , ', array_keys($user_groups)).' ) ' ;
$monitor_filters = db_process_sql ( $sql );
if ( $monitor_filters === false ) {
echo 'error' ;
} else {
2023-03-13 17:21:28 +01:00
db_process_sql_delete (
'tfavmenu_user' ,
[
'id_element' => $id ,
'section' => 'Modules' ,
'id_user' => $config [ 'id_user' ],
]
);
2023-02-28 17:06:31 +01:00
echo 'ok' ;
}
}
2023-01-19 10:49:48 +01:00
if ( $get_monitor_filters ) {
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter' ;
$monitor_filters = db_get_all_rows_sql ( $sql );
$result = [];
if ( $monitor_filters !== false ) {
foreach ( $monitor_filters as $monitor_filter ) {
$result [ $monitor_filter [ 'id_filter' ]] = $monitor_filter [ 'id_name' ];
}
}
echo io_json_mb_encode ( $result );
}
if (( int ) $load_filter_modal === 1 ) {
$user_groups = users_get_groups (
$config [ 'id_user' ],
'AR' ,
2023-02-28 17:06:31 +01:00
users_can_manage_group_all ( 'AR' ),
2023-01-19 10:49:48 +01:00
true
);
$sql = ' SELECT id_filter , id_name
FROM tmonitor_filter
WHERE id_group_filter IN ( '.implode(' , ', array_keys($user_groups)).' ) ' ;
$event_filters = db_get_all_rows_sql ( $sql );
$filters = [];
foreach ( $event_filters as $event_filter ) {
$filters [ $event_filter [ 'id_filter' ]] = $event_filter [ 'id_name' ];
}
2023-02-27 13:41:44 +01:00
echo '<div id="load-filter-select" class="load-filter-modal" title="' . __ ( 'Load' ) . '">' ;
2023-01-19 10:49:48 +01:00
echo '<form method="post" id="form_load_filter" action="index.php?sec=view&sec2=operation/agentes/status_monitor&pure=">' ;
$table = new StdClass ;
$table -> id = 'load_filter_form' ;
$table -> width = '100%' ;
2023-02-27 13:41:44 +01:00
$table -> class = 'filter-table-adv' ;
2023-01-19 10:49:48 +01:00
$data = [];
$table -> rowid [ 3 ] = 'update_filter_row1' ;
2023-02-27 13:41:44 +01:00
$data [ 0 ] = html_print_label_input_block (
2023-01-19 10:49:48 +01:00
__ ( 'Load filter' ),
2023-02-27 13:41:44 +01:00
html_print_select (
$filters ,
'filter_id' ,
$current ,
'' ,
__ ( 'None' ),
0 ,
true ,
false ,
true ,
'' ,
false
)
2023-01-19 10:49:48 +01:00
);
2023-02-27 13:41:44 +01:00
2023-01-19 10:49:48 +01:00
$table -> data [] = $data ;
$table -> rowclass [] = '' ;
html_print_table ( $table );
2023-02-27 13:41:44 +01:00
html_print_div (
[
'class' => 'action-buttons' ,
'content' => html_print_submit_button (
__ ( 'Load filter' ),
'srcbutton' ,
false ,
[
'icon' => 'search' ,
'mode' => 'mini' ,
],
true
),
],
false
);
echo html_print_input_hidden ( 'load_filter' , 1 , true );
2023-01-19 10:49:48 +01:00
echo '</form>' ;
echo '</div>' ;
?>
< script type = " text/javascript " >
function show_filter () {
$ ( " #load-filter-select " ) . dialog ({
resizable : true ,
draggable : true ,
modal : false ,
closeOnEscape : true ,
width : 450
});
}
$ ( document ) . ready ( function () {
show_filter ();
});
</ script >
< ? php
return ;
}
if ( $save_filter_modal ) {
2023-02-27 13:41:44 +01:00
echo '<div id="save-filter-select" title="' . __ ( 'Save' ) . '">' ;
2023-01-25 17:41:46 +01:00
if ( check_acl ( $config [ 'id_user' ], 0 , 'AW' )) {
2023-01-19 10:49:48 +01:00
echo '<div id="#info_box"></div>' ;
$table = new StdClass ;
$table -> id = 'save_filter_form' ;
2023-02-27 13:41:44 +01:00
$table -> size = [];
$table -> size [ 0 ] = '50%' ;
$table -> size [ 1 ] = '50%' ;
$table -> class = 'filter-table-adv' ;
2023-01-19 10:49:48 +01:00
$data = [];
2023-02-27 13:41:44 +01:00
$table -> rowid [ 0 ] = 'update_save_selector' ;
$data [ 0 ][ 0 ] = html_print_label_input_block (
__ ( 'New filter' ),
html_print_radio_button (
'filter_mode' ,
'new' ,
'' ,
true ,
true
)
);
2023-01-19 10:49:48 +01:00
2023-02-27 13:41:44 +01:00
$data [ 0 ][ 1 ] = html_print_label_input_block (
2023-03-03 08:20:44 +01:00
__ ( 'Update/delete filter' ),
2023-02-27 13:41:44 +01:00
html_print_radio_button (
'filter_mode' ,
'update' ,
'' ,
false ,
true
)
);
2023-01-19 10:49:48 +01:00
$table -> rowid [ 1 ] = 'save_filter_row1' ;
2023-02-27 13:41:44 +01:00
$data [ 1 ][ 0 ] = html_print_label_input_block (
__ ( 'Filter name' ),
html_print_input_text ( 'id_name' , '' , '' , 15 , 255 , true )
);
$labelInput = __ ( 'Filter group' );
if ( is_metaconsole () === true ) {
$labelInput = __ ( 'Save in Group' );
2023-01-19 10:49:48 +01:00
}
$user_groups_array = users_get_groups_for_select (
$config [ 'id_user' ],
2023-01-25 17:41:46 +01:00
'AW' ,
2023-02-28 17:06:31 +01:00
users_can_manage_group_all ( 'AW' ),
2023-01-19 10:49:48 +01:00
true
);
2023-02-27 13:41:44 +01:00
$data [ 1 ][ 1 ] = html_print_label_input_block (
$labelInput ,
html_print_select (
$user_groups_array ,
'id_group_filter_dialog' ,
$id_group_filter ,
'' ,
'' ,
0 ,
true ,
false ,
false
2023-03-03 14:16:06 +01:00
),
[ 'div_class' => 'filter-group-dialog' ]
2023-01-19 10:49:48 +01:00
);
$table -> rowid [ 2 ] = 'save_filter_row2' ;
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter' ;
$monitor_filters = db_get_all_rows_sql ( $sql );
$_filters_update = [];
if ( $monitor_filters !== false ) {
foreach ( $monitor_filters as $monitor_filter ) {
$_filters_update [ $monitor_filter [ 'id_filter' ]] = $monitor_filter [ 'id_name' ];
}
}
2023-02-27 13:41:44 +01:00
$data [ 2 ][ 0 ] = html_print_label_input_block (
__ ( 'Overwrite filter' ),
html_print_select (
$_filters_update ,
'overwrite_filter' ,
'' ,
'' ,
'' ,
0 ,
true
)
2023-01-19 10:49:48 +01:00
);
2023-02-27 13:41:44 +01:00
$table -> data = $data ;
2023-01-19 10:49:48 +01:00
html_print_table ( $table );
2023-02-27 13:41:44 +01:00
html_print_div (
[
'id' => 'submit-save_filter' ,
'class' => 'action-buttons' ,
'content' => html_print_submit_button (
2023-03-03 08:20:44 +01:00
__ ( 'Save current filter' ),
2023-02-27 13:41:44 +01:00
'srcbutton' ,
false ,
[
'icon' => 'search' ,
'mode' => 'mini' ,
'onclick' => 'save_new_filter();' ,
],
true
),
],
false
);
2023-03-03 08:20:44 +01:00
$input_actions = html_print_submit_button (
__ ( 'Delete filter' ),
'delete_filter' ,
false ,
[
'icon' => 'delete' ,
'mode' => 'mini' ,
'onclick' => 'save_delete_filter();' ,
],
true
);
$input_actions .= html_print_submit_button (
__ ( 'Update filter' ),
'srcbutton' ,
false ,
[
'icon' => 'update' ,
'mode' => 'mini' ,
'onclick' => 'save_update_filter();' ,
],
true
);
2023-02-27 13:41:44 +01:00
html_print_div (
[
'id' => 'update_filter_row' ,
'class' => 'action-buttons' ,
2023-03-03 08:20:44 +01:00
'content' => $input_actions ,
2023-02-27 13:41:44 +01:00
],
false
);
2023-01-19 10:49:48 +01:00
} else {
include 'general/noaccess.php' ;
}
echo '</div>' ;
?>
< script type = " text/javascript " >
function show_save_filter () {
2023-02-27 13:41:44 +01:00
$ ( '#save_filter_row2' ) . hide ();
$ ( '#update_filter_row' ) . hide ();
2023-02-28 17:06:31 +01:00
$ ( '#update_delete_row' ) . hide ();
2023-03-03 14:16:06 +01:00
$ ( '.filter-group-dialog' ) . show ();
2023-01-19 10:49:48 +01:00
// Filter save mode selector
$ ( " [name='filter_mode'] " ) . click ( function () {
if ( $ ( this ) . val () == 'new' ) {
2023-02-27 13:41:44 +01:00
$ ( '#save_filter_row2' ) . hide ();
2023-01-19 10:49:48 +01:00
$ ( '#submit-save_filter' ) . show ();
2023-02-27 13:41:44 +01:00
$ ( '#update_filter_row' ) . hide ();
2023-02-28 17:06:31 +01:00
$ ( '#update_delete_row' ) . hide ();
2023-03-03 14:16:06 +01:00
$ ( '.filter-group-dialog' ) . show ();
2023-01-19 10:49:48 +01:00
}
else {
2023-02-27 13:41:44 +01:00
$ ( '#save_filter_row2' ) . show ();
$ ( '#update_filter_row' ) . show ();
2023-01-19 10:49:48 +01:00
$ ( '#submit-save_filter' ) . hide ();
2023-02-28 17:06:31 +01:00
$ ( '#update_delete_row' ) . show ();
2023-03-03 14:16:06 +01:00
$ ( '.filter-group-dialog' ) . hide ();
2023-01-19 10:49:48 +01:00
}
});
$ ( " #save-filter-select " ) . dialog ({
resizable : true ,
draggable : true ,
modal : false ,
2023-02-27 13:41:44 +01:00
closeOnEscape : true ,
width : 450 ,
height : 350
2023-01-19 10:49:48 +01:00
});
}
function save_new_filter () {
// If the filter name is blank show error
if ( $ ( '#text-id_name' ) . val () == '' ) {
$ ( '#show_filter_error' ) . html ( " <h3 class='error'><?php echo __('Filter name cannot be left blank'); ?></h3> " );
// Close dialog
$ ( '.ui-dialog-titlebar-close' ) . trigger ( 'click' );
return false ;
}
var custom_fields_values = $ ( 'input[name^="ag_custom_fields"]' ) . map ( function () {
return this . value ;
}) . get ();
var custom_fields_ids = $ ( " input[name^='ag_custom_fields'] " ) . map ( function () {
var name = $ ( this ) . attr ( " name " );
var number = name . match ( / \ [( .* ? ) \ ] / )[ 1 ];
return number ;
}) . get ();
var ag_custom_fields = custom_fields_ids . reduce ( function ( result , custom_fields_id , index ) {
result [ custom_fields_id ] = custom_fields_values [ index ];
return result ;
}, {});
var id_filter_save ;
jQuery . post ( " <?php echo ui_get_full_url('ajax.php', false, false, false); ?> " ,
{
" page " : " include/ajax/module " ,
" save_monitor_filter " : 1 ,
" id_name " : $ ( " #text-id_name " ) . val (),
" id_group_filter " : $ ( " #id_group_filter_dialog " ) . val (),
" ag_group " : $ ( " #ag_group " ) . val (),
" modulegroup " : $ ( " #modulegroup " ) . val (),
" recursion " : $ ( " #checkbox-recursion " ) . is ( ':checked' ),
" status " : $ ( " #status " ) . val (),
" severity " : $ ( " #severity " ) . val (),
" ag_modulename " : $ ( " #text-ag_modulename " ) . val (),
" ag_freestring " : $ ( " #text-ag_freestring " ) . val (),
" tag_filter " : $ ( " #tag_filter " ) . val (),
" moduletype " : $ ( " #moduletype " ) . val (),
" module_option " : $ ( '#module_option' ) . val (),
" min_hours_status " : $ ( '#text-min_hours_status' ) . val (),
" datatype " : $ ( " #datatype " ) . val (),
" not_condition " : $ ( " #not_condition_switch " ) . is ( ':checked' ),
" ag_custom_fields " : JSON . stringify ( ag_custom_fields ),
},
function ( data ) {
$ ( " #info_box " ) . hide ();
if ( data == 'error' ) {
$ ( " #info_box " ) . filter ( function ( i , item ) {
if ( $ ( item ) . data ( 'type_info_box' ) == " error_create_filter " ) {
return true ;
}
else
return false ;
}) . show ();
}
else if ( data == 'duplicate' ) {
$ ( " #info_box " ) . filter ( function ( i , item ) {
if ( $ ( item ) . data ( 'type_info_box' ) == " duplicate_create_filter " ) {
return true ;
}
else
return false ;
}) . show ();
}
else {
id_filter_save = data ;
$ ( " #info_box " ) . filter ( function ( i , item ) {
if ( $ ( item ) . data ( 'type_info_box' ) == " success_create_filter " ) {
return true ;
}
else
return false ;
}) . show ();
}
// Close dialog.
$ ( " #save-filter-select " ) . dialog ( 'close' );
}
);
}
function save_update_filter () {
var id_filter_update = $ ( " #overwrite_filter " ) . val ();
var name_filter_update = $ ( " #overwrite_filter option[value=' " + id_filter_update + " '] " ) . text ();
var custom_fields_values = $ ( 'input[name^="ag_custom_fields"]' ) . map ( function () {
return this . value ;
}) . get ();
var custom_fields_ids = $ ( " input[name^='ag_custom_fields'] " ) . map ( function () {
var name = $ ( this ) . attr ( " name " );
var number = name . match ( / \ [( .* ? ) \ ] / )[ 1 ];
return number ;
}) . get ();
var ag_custom_fields = custom_fields_ids . reduce ( function ( result , custom_fields_id , index ) {
result [ custom_fields_id ] = custom_fields_values [ index ];
return result ;
}, {});
jQuery . post ( " <?php echo ui_get_full_url('ajax.php', false, false, false); ?> " ,
{
" page " : " include/ajax/module " ,
" update_monitor_filter " : 1 ,
" id " : $ ( " #overwrite_filter " ) . val (),
" ag_group " : $ ( " #ag_group " ) . val (),
" modulegroup " : $ ( " #modulegroup " ) . val (),
" recursion " : $ ( " #checkbox-recursion " ) . is ( ':checked' ),
" status " : $ ( " #status " ) . val (),
" severity " : $ ( " #severity " ) . val (),
" ag_modulename " : $ ( " #text-ag_modulename " ) . val (),
" ag_freestring " : $ ( " #text-ag_freestring " ) . val (),
" tag_filter " : $ ( " #tag_filter " ) . val (),
" moduletype " : $ ( " #moduletype " ) . val (),
" module_option " : $ ( '#module_option' ) . val (),
" min_hours_status " : $ ( '#text-min_hours_status' ) . val (),
" datatype " : $ ( " #datatype " ) . val (),
" not_condition " : $ ( " #not_condition_switch " ) . is ( ':checked' ),
" ag_custom_fields " : JSON . stringify ( ag_custom_fields ),
},
function ( data ) {
$ ( " .info_box " ) . hide ();
if ( data == 'ok' ) {
$ ( " .info_box " ) . filter ( function ( i , item ) {
if ( $ ( item ) . data ( 'type_info_box' ) == " success_update_filter " ) {
return true ;
}
else
return false ;
}) . show ();
}
else {
$ ( " .info_box " ) . filter ( function ( i , item ) {
if ( $ ( item ) . data ( 'type_info_box' ) == " error_create_filter " ) {
return true ;
}
else
return false ;
}) . show ();
}
});
// First remove all options of filters select
$ ( '#filter_id' ) . find ( 'option' ) . remove () . end ();
// Add 'none' option the first
$ ( '#filter_id' ) . append ( $ ( '<option></option>' ) . html ( < ? php echo " ' " . __ ( 'none' ) . " ' " ; ?> ).attr ("value", 0));
// Reload filters select
jQuery . post ( " <?php echo ui_get_full_url('ajax.php', false, false, false); ?> " ,
{
" page " : " include/ajax/module " ,
" get_monitor_filters " : 1
},
function ( data ) {
jQuery . each ( data , function ( i , val ) {
s = js_html_entity_decode ( val );
if ( i == id_filter_update ) {
$ ( '#filter_id' ) . append ( $ ( '<option selected="selected"></option>' ) . html ( s ) . attr ( " value " , i ));
}
else {
$ ( '#filter_id' ) . append ( $ ( '<option></option>' ) . html ( s ) . attr ( " value " , i ));
}
});
},
" json "
);
// Close dialog
$ ( '.ui-dialog-titlebar-close' ) . trigger ( 'click' );
// Update the info with the loaded filter
$ ( " #hidden-id_name " ) . val ( $ ( '#text-id_name' ) . val ());
$ ( '#filter_loaded_span' ) . html ( $ ( '#filter_loaded_text' ) . html () + ': ' + name_filter_update );
return false ;
}
2023-02-28 17:06:31 +01:00
function save_delete_filter () {
var id_filter_update = $ ( " #overwrite_filter " ) . val ();
jQuery . post ( " <?php echo ui_get_full_url('ajax.php', false, false, false); ?> " ,
{
" page " : " include/ajax/module " ,
" delete_monitor_filter " : 1 ,
" id " : $ ( " #overwrite_filter " ) . val (),
},
function ( data ) {
$ ( " .info_box " ) . hide ();
if ( data == 'ok' ) {
$ ( " .info_box " ) . filter ( function ( i , item ) {
if ( $ ( item ) . data ( 'type_info_box' ) == " success_update_filter " ) {
return true ;
}
else
return false ;
}) . show ();
}
else {
$ ( " .info_box " ) . filter ( function ( i , item ) {
if ( $ ( item ) . data ( 'type_info_box' ) == " error_create_filter " ) {
return true ;
}
else
return false ;
}) . show ();
}
});
// First remove all options of filters select.
$ ( '#filter_id' ) . find ( 'option' ) . remove () . end ();
// Add 'none' option.
$ ( '#filter_id' ) . append ( $ ( '<option></option>' ) . html ( < ? php echo " ' " . __ ( 'None' ) . " ' " ; ?> ).attr ("value", 0));
// Reload filters select.
jQuery . post ( " <?php echo ui_get_full_url('ajax.php', false, false, false); ?> " ,
{
" page " : " include/ajax/module " ,
" get_monitor_filters " : 1
},
function ( data ) {
jQuery . each ( data , function ( i , val ) {
s = js_html_entity_decode ( val );
if ( i == id_filter_update ) {
$ ( '#filter_id' ) . append ( $ ( '<option selected="selected"></option>' ) . html ( s ) . attr ( " value " , i ));
}
else {
$ ( '#filter_id' ) . append ( $ ( '<option></option>' ) . html ( s ) . attr ( " value " , i ));
}
});
},
" json "
);
// Close dialog
$ ( '.ui-dialog-titlebar-close' ) . trigger ( 'click' );
return false ;
}
2023-01-19 10:49:48 +01:00
$ ( document ) . ready ( function () {
show_save_filter ();
});
</ script >
< ? php
2023-01-24 12:26:49 +01:00
return ;
}
2016-10-06 08:58:53 +02:00
}