2009-01-15 11:21:38 +01:00
< ? php
2009-06-08 20:26:14 +02:00
// Pandora FMS - http://pandorafms.com
// ==================================================
2010-05-06 17:53:38 +02:00
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
2009-06-08 20:26:14 +02:00
// Please see http://pandorafms.org for full contribution list
2009-01-15 11:21:38 +01:00
// This program is free software; you can redistribute it and/or
2009-06-08 20:26:14 +02:00
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
2009-01-15 11:21:38 +01:00
// 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.
2009-06-08 20:26:14 +02:00
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/dev.php,
include/auth/ldap.php, include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FusionCharts.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/help/en/help_plugin_parameters.php,
include/help/en/help_snmpcommunity.php, include/help/en/help_wmiquery.php,
include/help/en/help_postprocess.php,
include/help/en/help_prediction_source_module.php,
include/help/en/help_date_format.php, include/help/en/help_recontask.php,
include/help/en/help_alert-matches.php, include/help/en/help_tcp_send.php,
include/help/en/help_wmifield.php, include/help/en/help_duplicateconfig.php,
include/help/en/help_agent_status.php,
include/help/en/help_manage_alerts.php, include/help/en/help_wmikey.php,
include/help/en/help_alert_type.php,
include/help/en/help_network_component.php,
include/help/en/help_time_stamp-comparation.php,
include/help/en/help_eventview.php, include/help/en/help_timesource.php,
include/help/en/help_alert_validation.php,
include/help/en/help_map_builder.php,
include/help/en/help_alert_recovery.php,
include/help/en/help_module_type.php,
include/help/en/help_planned_downtime.php,
include/help/en/help_serverlag.php, include/help/en/help_alerts.php,
include/help/en/help_snmpwalk.php,
include/help/en/help_module_definition.php,
include/help/en/help_plugin_definition.php,
include/help/en/help_wminamespace.php, include/help/en/help_snmpoid.php
include/help/en/help_manageconfig.php,
include/help/es/help_alert_validation.php,
include/help/es/help_plugin_parameters.php,
include/help/es/help_snmpcommunity.php, include/help/es/help_wmiquery.php,
include/help/es/help_map_builder.php, include/help/es/help_postprocess.php,
include/help/es/help_date_format.php,
include/help/es/help_alert_recovery.php,
include/help/es/help_prediction_source_module.php,
include/help/es/help_module_type.php,
include/help/es/help_planned_downtime.php,
include/help/es/help_alert-matches.php, include/help/es/help_recontask.php,
include/help/es/help_alerts.php, include/help/es/help_serverlag.php,
include/help/es/help_snmpwalk.php,
include/help/es/help_module_definition.php,
include/help/es/help_tcp_send.php, include/help/es/help_duplicateconfig.php,
include/help/es/help_wmifield.php, include/help/es/help_manage_alerts.php,
include/help/es/help_wmikey.php, include/help/es/help_plugin_definition.php,
include/help/es/help_alert_type.php, include/help/es/help_snmpoid.php,
include/help/es/help_wminamespace.php,
include/help/es/help_network_component.php,
include/help/es/help_time_stamp-comparation.php,
include/help/es/help_manageconfig.php, include/help/es/help_timesource.php,
include/config_process.php, include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change comments blocks for delete the
warnings to construct phpDoc Files, give a struct and order in the
phpDoc files.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1881 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-25 19:39:28 +02:00
/**
* @ package Include
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
* @ subpackage Agents
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/dev.php,
include/auth/ldap.php, include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FusionCharts.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/help/en/help_plugin_parameters.php,
include/help/en/help_snmpcommunity.php, include/help/en/help_wmiquery.php,
include/help/en/help_postprocess.php,
include/help/en/help_prediction_source_module.php,
include/help/en/help_date_format.php, include/help/en/help_recontask.php,
include/help/en/help_alert-matches.php, include/help/en/help_tcp_send.php,
include/help/en/help_wmifield.php, include/help/en/help_duplicateconfig.php,
include/help/en/help_agent_status.php,
include/help/en/help_manage_alerts.php, include/help/en/help_wmikey.php,
include/help/en/help_alert_type.php,
include/help/en/help_network_component.php,
include/help/en/help_time_stamp-comparation.php,
include/help/en/help_eventview.php, include/help/en/help_timesource.php,
include/help/en/help_alert_validation.php,
include/help/en/help_map_builder.php,
include/help/en/help_alert_recovery.php,
include/help/en/help_module_type.php,
include/help/en/help_planned_downtime.php,
include/help/en/help_serverlag.php, include/help/en/help_alerts.php,
include/help/en/help_snmpwalk.php,
include/help/en/help_module_definition.php,
include/help/en/help_plugin_definition.php,
include/help/en/help_wminamespace.php, include/help/en/help_snmpoid.php
include/help/en/help_manageconfig.php,
include/help/es/help_alert_validation.php,
include/help/es/help_plugin_parameters.php,
include/help/es/help_snmpcommunity.php, include/help/es/help_wmiquery.php,
include/help/es/help_map_builder.php, include/help/es/help_postprocess.php,
include/help/es/help_date_format.php,
include/help/es/help_alert_recovery.php,
include/help/es/help_prediction_source_module.php,
include/help/es/help_module_type.php,
include/help/es/help_planned_downtime.php,
include/help/es/help_alert-matches.php, include/help/es/help_recontask.php,
include/help/es/help_alerts.php, include/help/es/help_serverlag.php,
include/help/es/help_snmpwalk.php,
include/help/es/help_module_definition.php,
include/help/es/help_tcp_send.php, include/help/es/help_duplicateconfig.php,
include/help/es/help_wmifield.php, include/help/es/help_manage_alerts.php,
include/help/es/help_wmikey.php, include/help/es/help_plugin_definition.php,
include/help/es/help_alert_type.php, include/help/es/help_snmpoid.php,
include/help/es/help_wminamespace.php,
include/help/es/help_network_component.php,
include/help/es/help_time_stamp-comparation.php,
include/help/es/help_manageconfig.php, include/help/es/help_timesource.php,
include/config_process.php, include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change comments blocks for delete the
warnings to construct phpDoc Files, give a struct and order in the
phpDoc files.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1881 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-25 19:39:28 +02:00
*/
2009-01-15 11:21:38 +01:00
2009-05-04 Esteban Sánchez <estebans@artica.es>
* include/functions_agents.php: Added create_agent(),
* include/functions_db.php: Renamed dame_agente_id() to get_agent_id ().
Added process_sql_begin(), process_sql_rollback() and process_sql_commit()
and use MySQL functions directly because the Pandora cache was avoiding
more than one execution.
* include/functions_incidents.php, include/functions_messages.php,
godmode/agentes/massive_delete_agents.php,
godmode/agentes/massive_delete_alerts.php,
godmode/agentes/massive_delete_modules.php,
godmode/agentes/massive_edit_modules.php,
godmode/db/db_purge.php,
include/functions_events.php: Use new transaction functions.
* include/functions_modules.php: Sanitize some values. Added
create_agent_module_from_network_component(), create_agent_module()
and get_network_component().
* godmode/agentes/configurar_agente.php: Use get_agent_id() and transaction
functions.
* reporting/fgraph.php, operation/reporting/reporting_viewer.php: Use
get_agent_id().
* godmode/setup/file_manager.php: Removed unnecesary variable.
* operation/agentes/ver_agente.php: Replaced exit with return on ajax
operation.
* include/config_process.php: Updated build number.
* include/functions_network_profiles.php: Fixed documentation.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1672 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-04 12:10:19 +02:00
/**
* Creates an agent
*
* @ param string Agent name .
* @ param string Group to be included .
* @ param int Agent interval
* @ param string Agent IP
*
* @ return int New agent id if created . False if it could not be created .
*/
function create_agent ( $name , $id_group , $interval , $ip_address , $values = false ) {
if ( empty ( $name ))
return false ;
2009-07-16 17:28:07 +02:00
if ( empty ( $id_group ))
2009-05-04 Esteban Sánchez <estebans@artica.es>
* include/functions_agents.php: Added create_agent(),
* include/functions_db.php: Renamed dame_agente_id() to get_agent_id ().
Added process_sql_begin(), process_sql_rollback() and process_sql_commit()
and use MySQL functions directly because the Pandora cache was avoiding
more than one execution.
* include/functions_incidents.php, include/functions_messages.php,
godmode/agentes/massive_delete_agents.php,
godmode/agentes/massive_delete_alerts.php,
godmode/agentes/massive_delete_modules.php,
godmode/agentes/massive_edit_modules.php,
godmode/db/db_purge.php,
include/functions_events.php: Use new transaction functions.
* include/functions_modules.php: Sanitize some values. Added
create_agent_module_from_network_component(), create_agent_module()
and get_network_component().
* godmode/agentes/configurar_agente.php: Use get_agent_id() and transaction
functions.
* reporting/fgraph.php, operation/reporting/reporting_viewer.php: Use
get_agent_id().
* godmode/setup/file_manager.php: Removed unnecesary variable.
* operation/agentes/ver_agente.php: Replaced exit with return on ajax
operation.
* include/config_process.php: Updated build number.
* include/functions_network_profiles.php: Fixed documentation.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1672 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-04 12:10:19 +02:00
return false ;
if ( empty ( $ip_address ))
return false ;
2009-07-16 17:28:07 +02:00
$interval = safe_int ( $interval , 1 , 300 );
2009-05-04 Esteban Sánchez <estebans@artica.es>
* include/functions_agents.php: Added create_agent(),
* include/functions_db.php: Renamed dame_agente_id() to get_agent_id ().
Added process_sql_begin(), process_sql_rollback() and process_sql_commit()
and use MySQL functions directly because the Pandora cache was avoiding
more than one execution.
* include/functions_incidents.php, include/functions_messages.php,
godmode/agentes/massive_delete_agents.php,
godmode/agentes/massive_delete_alerts.php,
godmode/agentes/massive_delete_modules.php,
godmode/agentes/massive_edit_modules.php,
godmode/db/db_purge.php,
include/functions_events.php: Use new transaction functions.
* include/functions_modules.php: Sanitize some values. Added
create_agent_module_from_network_component(), create_agent_module()
and get_network_component().
* godmode/agentes/configurar_agente.php: Use get_agent_id() and transaction
functions.
* reporting/fgraph.php, operation/reporting/reporting_viewer.php: Use
get_agent_id().
* godmode/setup/file_manager.php: Removed unnecesary variable.
* operation/agentes/ver_agente.php: Replaced exit with return on ajax
operation.
* include/config_process.php: Updated build number.
* include/functions_network_profiles.php: Fixed documentation.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1672 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-04 12:10:19 +02:00
if ( empty ( $interval ))
return false ;
if ( ! is_array ( $values ))
$values = array ();
$values [ 'nombre' ] = $name ;
$values [ 'id_grupo' ] = $id_group ;
$values [ 'intervalo' ] = $interval ;
$values [ 'direccion' ] = $ip_address ;
process_sql_begin ();
$id_agent = process_sql_insert ( 'tagente' , $values );
if ( $id_agent === false ) {
process_sql_rollback ();
return false ;
}
// Create address for this agent in taddress
agent_add_address ( $id_agent , $ip_address );
// Create special module agent_keepalive
$id_agent_module = process_sql_insert ( 'tagente_modulo' ,
array ( 'nombre' => 'agent_keepalive' ,
'id_agente' => $id_agent ,
'id_tipo_modulo' => 100 ,
'descripcion' => __ ( 'Agent keepalive monitor' ),
'id_modulo' => 1 ,
'min_warning' => 0 ,
'max_warning' => 1 ));
if ( $id_agent_module === false ) {
process_sql_rollback ();
return false ;
}
$result = process_sql_insert ( 'tagente_estado' ,
array ( 'id_agente_modulo' => $id_agent_module ,
'datos' => '' ,
'timestamp' => 0 ,
'estado' => 0 ,
'id_agente' => $id_agent ,
'last_try' => 0 ,
'utimestamp' => 0 ,
'current_interval' => 0 ,
'running_by' => 0 ,
'last_execution_try' => 0 ));
if ( $result === false ) {
process_sql_rollback ();
return false ;
}
process_sql_commit ();
2009-11-30 18:38:45 +01:00
pandora_audit ( " Agent management " , " New agent ' $name ' created " );
2009-11-27 Sancho lerena <slerena@artica.es>
* operation/menu.php: User section has no ACL check, always can be seen.
* index.php: Added suppor for user-defined custom language (this code was
on my disk for 3 months, pending to be commited!).
* include/functions_db.php,
* include/functions_agents.php,
* godmode/alerts/alert_list.php,
* godmode/agentes/modificar_agente.php,
* godmode/agentes/configurar_agente.php: Added audit calls to several
management operations who don't have or have insufficient audit info.
* godmode/users/configure_user.php: Fixed several annoyings bugs. Added
custom language support, and added more audit info on management operations.
* godmode/users/user_list.php: More audit info.
* include/config_process.php: Add new debug option to render error log to
/pandora_console.log. Also set timezone if not defined (this makes warnings
on several PHP 5.x setups). Added user custom language support.
* include/functions_events.php: More audit info. Fixed problems with HTML
encoding render.
* functions_io.php: Some cleaning.
* include/functions_messages.php: Fixed problems with HTML
encoding render.
* functions_ui.php: Fixed problems with HTML encoding render in
print_string_substr() function.
* auth/mysql.php: is_user_admin() functions seems to be broken ¿?¿!. Fixed.
* styles/pandora.css: removed green colored left border in default style.
* message.php, incident*: Fixed problems with HTML encoding render.
* user.php: Better ACL check before let user to view/edit another user.
* user_edit: Removed some un-used form fields, some arrangements in layout,
and FIXED forever problems with password change (new code written).
* users/user_statistics.php: Now user can see its own audit records.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2139 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-27 21:02:12 +01:00
2009-05-04 Esteban Sánchez <estebans@artica.es>
* include/functions_agents.php: Added create_agent(),
* include/functions_db.php: Renamed dame_agente_id() to get_agent_id ().
Added process_sql_begin(), process_sql_rollback() and process_sql_commit()
and use MySQL functions directly because the Pandora cache was avoiding
more than one execution.
* include/functions_incidents.php, include/functions_messages.php,
godmode/agentes/massive_delete_agents.php,
godmode/agentes/massive_delete_alerts.php,
godmode/agentes/massive_delete_modules.php,
godmode/agentes/massive_edit_modules.php,
godmode/db/db_purge.php,
include/functions_events.php: Use new transaction functions.
* include/functions_modules.php: Sanitize some values. Added
create_agent_module_from_network_component(), create_agent_module()
and get_network_component().
* godmode/agentes/configurar_agente.php: Use get_agent_id() and transaction
functions.
* reporting/fgraph.php, operation/reporting/reporting_viewer.php: Use
get_agent_id().
* godmode/setup/file_manager.php: Removed unnecesary variable.
* operation/agentes/ver_agente.php: Replaced exit with return on ajax
operation.
* include/config_process.php: Updated build number.
* include/functions_network_profiles.php: Fixed documentation.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1672 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-04 12:10:19 +02:00
return $id_agent ;
}
2009-01-15 11:21:38 +01:00
/**
* Get all the simple alerts of an agent .
*
* @ param int Agent id
* @ param string Filter on " fired " , " notfired " or " disabled " . Any other value
* will not do any filter .
2009-02-18 13:29:30 +01:00
* @ param array Extra filter options in an indexed array . See
* format_array_to_where_clause_sql ()
2009-10-26 17:35:34 +01:00
* @ param boolean $allModules
2009-01-15 11:21:38 +01:00
*
* @ return array All simple alerts defined for an agent . Empty array if no
* alerts found .
*/
2010-10-25 17:58:28 +02:00
function get_agent_alerts_simple ( $id_agent = false , $filter = '' , $options = false , $where = '' ,
$allModules = false , $orderby = false , $idGroup = false , $count = false ) {
2010-09-17 14:34:11 +02:00
if ( is_array ( $filter )) {
$disabled = $filter [ 'disabled' ];
$filter = ' AND talert_template_modules.standby = "' . $filter [ 'standby' ] . '"' ;
2010-10-25 17:58:28 +02:00
}
else {
2010-09-17 14:34:11 +02:00
$filter = '' ;
$disabled = $filter ;
}
2009-11-30 18:28:08 +01:00
2010-09-17 14:34:11 +02:00
switch ( $disabled ) {
2009-09-16 15:10:49 +02:00
case " notfired " :
2010-09-17 14:34:11 +02:00
$filter .= ' AND times_fired = 0 AND talert_template_modules.disabled = 0' ;
2009-09-16 15:10:49 +02:00
break ;
case " fired " :
2010-09-17 14:34:11 +02:00
$filter .= ' AND times_fired > 0 AND talert_template_modules.disabled = 0' ;
2009-09-16 15:10:49 +02:00
break ;
case " disabled " :
2010-09-17 14:34:11 +02:00
$filter .= ' AND talert_template_modules.disabled = 1' ;
2009-09-16 15:10:49 +02:00
break ;
2010-09-17 14:34:11 +02:00
case " all_enabled " :
$filter .= ' AND talert_template_modules.disabled = 0' ;
2009-10-21 22:25:26 +02:00
break ;
2009-09-16 15:10:49 +02:00
default :
2010-09-17 14:34:11 +02:00
$filter .= '' ;
2009-01-15 11:21:38 +01:00
}
2009-02-18 13:29:30 +01:00
if ( is_array ( $options )) {
$filter .= format_array_to_where_clause_sql ( $options );
}
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
if (( $id_agent === false ) && ( $idGroup !== false )) {
2010-04-22 18:51:23 +02:00
if ( $idGroup != 0 ) { //All group
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
$subQuery = 'SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 0 AND id_agente IN (SELECT id_agente FROM tagente WHERE id_grupo = ' . $idGroup . ')' ;
}
else {
$subQuery = 'SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 0' ;
}
}
else if ( $id_agent === false ) {
2009-10-26 17:35:34 +01:00
if ( $allModules ) $disabled = '' ;
else $disabled = 'WHERE disabled = 0' ;
2009-09-16 15:10:49 +02:00
$subQuery = ' SELECT id_agente_modulo
2009-10-26 17:35:34 +01:00
FROM tagente_modulo ' . $disabled ;
2009-09-16 15:10:49 +02:00
}
else {
$id_agent = ( array ) $id_agent ;
2009-11-30 12:08:09 +01:00
$id_modules = array_keys ( get_agent_modules ( $id_agent , false , array ( 'delete_pending' => 0 )));
2009-09-16 15:10:49 +02:00
if ( empty ( $id_modules ))
return array ();
$subQuery = implode ( " , " , $id_modules );
}
2009-12-08 09:10:13 +01:00
$orderbyText = '' ;
2010-07-21 12:06:13 +02:00
if ( $orderby !== false ) {
if ( is_array ( $orderby )) {
$orderbyText = sprintf ( " ORDER BY %s " , $orderby [ 'field' ], $orderby [ 'order' ]);
}
else {
$orderbyText = sprintf ( " ORDER BY %s " , $orderby );
}
}
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
2010-07-21 12:06:13 +02:00
$selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.nombre AS agent_name, t4.name AS template_name' ;
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
if ( $count !== false ) {
$selectText = 'COUNT(talert_template_modules.id) AS count' ;
}
2009-11-30 18:28:08 +01:00
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
$sql = sprintf ( " SELECT %s
2009-09-16 15:10:49 +02:00
FROM talert_template_modules
2009-11-30 18:28:08 +01:00
INNER JOIN tagente_modulo AS t2
ON talert_template_modules . id_agent_module = t2 . id_agente_modulo
2010-07-21 12:06:13 +02:00
INNER JOIN tagente AS t3
ON t2 . id_agente = t3 . id_agente
INNER JOIN talert_templates AS t4
ON talert_template_modules . id_alert_template = t4 . id
2010-04-07 11:50:09 +02:00
WHERE id_agent_module in ( % s ) % s % s % s " ,
$selectText , $subQuery , $where , $filter , $orderbyText );
2010-09-17 14:34:11 +02:00
2010-04-28 20:38:58 +02:00
$alerts = get_db_all_rows_sql ( $sql );
2009-01-15 11:21:38 +01:00
if ( $alerts === false )
return array ();
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
if ( $count !== false ) {
return $alerts [ 0 ][ 'count' ];
}
else {
return $alerts ;
}
2009-01-15 11:21:38 +01:00
}
/**
* Get all the combined alerts of an agent .
*
* @ param int $id_agent Agent id
2009-02-18 13:29:30 +01:00
* @ param string Special filter . Can be : " notfired " , " fired " or " disabled " .
* @ param array Extra filter options in an indexed array . See
* format_array_to_where_clause_sql ()
2009-01-15 11:21:38 +01:00
*
* @ return array An array with all combined alerts defined for an agent .
*/
2010-04-07 11:50:09 +02:00
function get_agent_alerts_compound ( $id_agent = false , $filter = '' , $options = false , $idGroup = false , $count = false , $where = '' ) {
2009-01-15 11:21:38 +01:00
switch ( $filter ) {
2010-09-17 14:34:11 +02:00
case " notfired " :
$filter = ' AND times_fired = 0 AND disabled = 0' ;
break ;
case " fired " :
$filter = ' AND times_fired > 0 AND disabled = 0' ;
break ;
case " disabled " :
$filter = ' AND disabled = 1' ;
break ;
case 'all_enabled' :
$filter = ' AND disabled = 0' ;
break ;
default :
$filter = '' ;
2010-10-25 17:58:28 +02:00
break ;
2009-01-15 11:21:38 +01:00
}
2009-01-19 15:42:34 +01:00
2009-02-18 13:29:30 +01:00
if ( is_array ( $options )) {
$filter .= format_array_to_where_clause_sql ( $options );
}
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
if (( $id_agent === false ) && ( $idGroup !== false )) {
2010-04-22 18:51:23 +02:00
if ( $idGroup != 0 ) { //All group
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
$subQuery = 'SELECT id_agente FROM tagente WHERE id_grupo = ' . $idGroup ;
}
else {
$subQuery = 'SELECT id_agente FROM tagente' ;
}
}
2010-09-30 09:57:34 +02:00
else if ( $id_agent == false ) {
2009-09-16 15:10:49 +02:00
$subQuery = ' SELECT id_agente
FROM tagente WHERE disabled = 0 ' ;
}
else {
$id_agent = ( array ) $id_agent ;
2010-09-30 09:57:34 +02:00
2009-09-16 15:10:49 +02:00
$subQuery = implode ( ',' , $id_agent );
}
2009-02-18 13:29:30 +01:00
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
$selectText = '*' ;
if ( $count !== false ) {
$selectText = 'COUNT(id) AS count' ;
}
$sql = sprintf ( " SELECT %s FROM talert_compound
2010-04-07 11:50:09 +02:00
WHERE id_agent IN ( % s ) % s % s " ,
$selectText , $subQuery , $where , $filter );
2009-01-19 15:42:34 +01:00
2010-04-28 20:38:58 +02:00
$alerts = get_db_all_rows_sql ( $sql );
2009-01-15 11:21:38 +01:00
if ( $alerts === false )
return array ();
2010-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_ui.php: changed some parts of source code in the
functions "format_alert_row" for show column modules in general view. In the
function "pagination" added the parameter $offset_name with default value
'offset' for to use several paginations in one page.
* include/functions_agents.php: added the parameters $limit, $idGroup,
$count in the function "get_agent_alerts_simple", and now you can limit the
rows, search by id group and return the count of rows (without limit). And
in the function "get_agent_alerts_compound" added the same parameters to
another function $idGroup, $limit, $count for similar uses.
* operation/agentes/alerts_status.php: cleaned more parts of source code,
fixed the mad array_merge of alerts, fixed SQL with the searchs IN
(large large list ids), fixed the pagination before loop all rows, now
only loop the block page rows.
* operation/agentes/alerts_status.functions.php: new file with the functions
"forceExecution", "validateAlert", and "printFormFilterAlert".
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2542 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-04-06 14:46:34 +02:00
if ( $count !== false ) {
return $alerts [ 0 ][ 'count' ];
}
else {
return $alerts ;
}
2009-01-15 11:21:38 +01:00
}
2009-04-20 16:00:27 +02:00
/**
* Get a list of agents .
*
* By default , it will return all the agents where the user has reading access .
*
2009-07-28 12:52:40 +02:00
* @ param array filter options in an indexed array . See
2009-04-20 16:00:27 +02:00
* format_array_to_where_clause_sql ()
* @ param array Fields to get .
* @ param string Access needed in the agents groups .
2010-07-19 16:57:46 +02:00
* @ param array $order The order of agents , by default is upward for field nombre .
2009-04-20 16:00:27 +02:00
*
2009-05-19 21:04:43 +02:00
* @ return mixed An array with all alerts defined for an agent or false in case no allowed groups are specified .
2009-04-20 16:00:27 +02:00
*/
2010-07-19 16:57:46 +02:00
function get_agents ( $filter = false , $fields = false , $access = 'AR' , $order = array ( 'field' => 'nombre' , 'order' => 'ASC' )) {
2010-08-26 17:51:09 +02:00
global $config ;
2009-05-19 21:04:43 +02:00
if ( ! is_array ( $filter )) {
2009-04-20 16:00:27 +02:00
$filter = array ();
2009-05-19 21:04:43 +02:00
}
2010-08-26 17:51:09 +02:00
2009-05-19 21:04:43 +02:00
//Get user groups
2010-08-26 17:51:09 +02:00
$groups = array_keys ( get_user_groups ( $config [ " id_user " ], $access , false ));
2009-05-19 21:04:43 +02:00
//If no group specified, get all user groups
if ( empty ( $filter [ 'id_grupo' ])) {
$filter [ 'id_grupo' ] = $groups ;
2010-10-25 17:58:28 +02:00
}
elseif ( ! is_array ( $filter [ 'id_grupo' ])) {
2009-05-19 21:04:43 +02:00
//If group is specified but not allowed, return false
if ( ! in_array ( $filter [ 'id_grupo' ], $groups )) {
return false ;
}
$filter [ 'id_grupo' ] = ( array ) $filter [ 'id_grupo' ]; //Make an array
2010-10-25 17:58:28 +02:00
}
else {
2009-05-19 21:04:43 +02:00
//Check each group specified to the user groups, remove unwanted groups
foreach ( $filter [ 'id_grupo' ] as $key => $id_group ) {
if ( ! in_array ( $id_group , $groups )) {
unset ( $filter [ 'id_grupo' ][ $key ]);
}
}
//If no allowed groups are specified return false
if ( count ( $filter [ 'id_grupo' ]) == 0 ) {
return false ;
2009-04-20 16:00:27 +02:00
}
2009-05-13 Esteban Sánchez <estebans@artica.es>
* images/clean.png, images/fullscreen.png, images/local_component.png,
images/log-out.png, images/normalscreen.png,
images/server_export.png: Added to repository. New tango icons.
* images/application_osx_terminal.png, images/arrow_refresh.png,
images/asterisk_yellow.png, images/attach.png,
images/drive_network.png, images/drive_user.png,
images/page_white_acrobat.png, images/rainbow.png,
images/telephone.png: Deleted from repository. Unused images.
* images/add.png, images/application_double.png,
images/application_edit.png, images/application.png,
images/book_edit.png, images/calendar_view_day.png,
images/camera.png, images/email_open.png, images/email.png,
images/god3.png, images/group.png, images/heart.png,
images/house.png, images/lupa.png, images/monitor.png,
images/mouse.png, images/package.png, images/page_white_magnify.png,
images/page_white.png, images/page_white_text.png,
images/paste_plain.png, images/pdf.png,
images/refresh.png, images/reporting.png, images/rosette.png,
images/script.png, images/server_database.png, images/server.png,
images/world.png, images/zoom.png: Updated to use tango icons.
* general/ui/agents_list.php: Added pagination.
* general/header.php: Logout icon replaced.
* include/styles/pandora.css: Some styles for tabs.
* include/functions_db.php: Changed export server icon.
* operation/events/events.php, operation/snmpconsole/snmp_view.php,
operation/visual_console/render_view.php,
operation/agentes/networkmap.php: Changed fullscreen icons.
* godmode/agentes/configurar_agente.php,
include/functions_modules.php,
include/functions_agents.php: Style correction.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1686 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-13 14:29:37 +02:00
}
2009-04-20 16:00:27 +02:00
2010-04-22 18:51:23 +02:00
if ( in_array ( 0 , $filter [ 'id_grupo' ])) {
2009-05-19 21:04:43 +02:00
unset ( $filter [ 'id_grupo' ]);
}
if ( ! is_array ( $fields )) {
$fields = array ();
$fields [ 0 ] = " id_agente " ;
$fields [ 1 ] = " nombre " ;
}
2010-07-19 16:57:46 +02:00
$filter [ 'order' ] = $order [ 'field' ] . ' ' . $order [ 'order' ];
2009-05-19 21:04:43 +02:00
return get_db_all_rows_filter ( 'tagente' , $filter , $fields );
2009-04-20 16:00:27 +02:00
}
2009-01-15 11:21:38 +01:00
/**
* Get all the alerts of an agent , simple and combined .
*
* @ param int $id_agent Agent id
2009-02-18 13:29:30 +01:00
* @ param string Special filter . Can be : " notfired " , " fired " or " disabled " .
* @ param array Extra filter options in an indexed array . See
* format_array_to_where_clause_sql ()
2009-01-15 11:21:38 +01:00
*
* @ return array An array with all alerts defined for an agent .
*/
2009-09-16 15:10:49 +02:00
function get_agent_alerts ( $id_agent = false , $filter = false , $options = false ) {
2009-02-18 13:29:30 +01:00
$combined_alerts = get_agent_alerts_compound ( $id_agent , $filter , $options );
2009-09-16 15:10:49 +02:00
$simple_alerts = get_agent_alerts_simple ( $id_agent , $filter , $options );
2009-01-15 11:21:38 +01:00
2009-02-11 17:55:04 +01:00
return array ( 'simple' => $simple_alerts , 'compounds' => $combined_alerts );
2009-01-15 11:21:38 +01:00
}
2009-02-24 17:31:02 +01:00
/**
* Copy the agents config from one agent to the other
*
2009-03-17 10:22:02 +01:00
* @ param int Agent id
* @ param mixed Agent id or id ' s ( array ) to copy to
* @ param bool Whether to copy modules as well ( defaults to $_REQUEST [ 'copy_modules' ])
* @ param bool Whether to copy alerts as well
* @ param array Which modules to copy .
* @ param array Which alerts to copy . Only will be used if target_modules is empty .
2009-02-24 17:31:02 +01:00
*
* @ return bool True in case of good , false in case of bad
*/
2009-03-17 10:22:02 +01:00
function process_manage_config ( $source_id_agent , $destiny_id_agents , $copy_modules = false , $copy_alerts = false , $target_modules = false , $target_alerts = false ) {
2009-02-24 17:31:02 +01:00
if ( empty ( $source_id_agent )) {
echo '<h3 class="error">' . __ ( 'No source agent to copy' ) . '</h3>' ;
return false ;
}
if ( empty ( $destiny_id_agents )) {
echo '<h3 class="error">' . __ ( 'No destiny agent(s) to copy' ) . '</h3>' ;
return false ;
}
if ( $copy_modules == false ) {
$copy_modules = ( bool ) get_parameter ( 'copy_modules' , $copy_modules );
}
2009-03-17 10:22:02 +01:00
2009-02-24 17:31:02 +01:00
if ( $copy_alerts == false ) {
$copy_alerts = ( bool ) get_parameter ( 'copy_alerts' , $copy_alerts );
}
2009-03-04 16:59:00 +01:00
2009-03-17 10:22:02 +01:00
if ( ! $copy_modules && ! $copy_alerts )
return ;
if ( empty ( $target_modules )) {
$target_modules = ( array ) get_parameter ( 'target_modules' , array ());
}
if ( empty ( $target_alerts )) {
$target_alerts = ( array ) get_parameter ( 'target_alerts' , array ());
}
if ( empty ( $target_modules )) {
if ( ! $copy_alerts ) {
2009-02-24 17:31:02 +01:00
echo '<h3 class="error">' . __ ( 'No modules have been selected' ) . '</h3>' ;
return false ;
}
2009-03-17 10:22:02 +01:00
$target_modules = array ();
2009-02-24 17:31:02 +01:00
2009-03-17 10:22:02 +01:00
foreach ( $target_alerts as $id_alert ) {
$alert = get_alert_agent_module ( $id_alert );
if ( $alert === false )
continue ;
/* Check if some alerts which doesn't belong to the agent was given */
if ( get_agentmodule_agent ( $alert [ 'id_agent_module' ]) != $source_id_agent )
continue ;
array_push ( $target_modules , $alert [ 'id_agent_module' ]);
}
}
process_sql ( 'SET AUTOCOMMIT = 0' );
process_sql ( 'START TRANSACTION' );
$error = false ;
foreach ( $destiny_id_agents as $id_destiny_agent ) {
foreach ( $target_modules as $id_agent_module ) {
$result = copy_agent_module_to_agent ( $id_agent_module ,
$id_destiny_agent );
if ( $result === false ) {
$error = true ;
break ;
}
$id_destiny_module = $result ;
if ( ! $copy_alerts )
continue ;
/* If the alerts were given , copy afterwards . Otherwise , all the
alerts for the module will be copied */
if ( ! empty ( $target_alerts )) {
foreach ( $target_alerts as $id_alert ) {
$alert = get_alert_agent_module ( $id_alert );
if ( $alert === false )
continue ;
if ( $alert [ 'id_agent_module' ] != $id_agent_module )
continue ;
2009-03-04 16:59:00 +01:00
$result = copy_alert_agent_module_to_agent_module ( $alert [ 'id' ],
$id_destiny_module );
if ( $result === false ) {
$error = true ;
break ;
2009-02-24 17:31:02 +01:00
}
}
2009-03-17 10:22:02 +01:00
continue ;
}
$alerts = get_alerts_agent_module ( $id_agent_module , true );
if ( $alerts === false )
continue ;
foreach ( $alerts as $alert ) {
$result = copy_alert_agent_module_to_agent_module ( $alert [ 'id' ],
$id_destiny_module );
if ( $result === false ) {
$error = true ;
break ;
}
2009-02-24 17:31:02 +01:00
}
}
2009-03-17 10:22:02 +01:00
if ( $error )
break ;
2009-02-24 17:31:02 +01:00
}
2009-03-17 10:22:02 +01:00
if ( $error ) {
echo '<h3 class="error">' . __ ( 'There was an error copying the agent configuration, the copy has been cancelled' ) . '</h3>' ;
process_sql ( 'ROLLBACK' );
} else {
echo '<h3 class="suc">' . __ ( 'Successfully copied' ) . '</h3>' ;
process_sql ( 'COMMIT' );
}
process_sql ( 'SET AUTOCOMMIT = 1' );
}
2009-10-06 21:51:18 +02:00
function getNextAgentContact ( $idAgent , $maxModules = false ) {
$agent = get_db_row_sql ( " SELECT * FROM tagente WHERE id_agente = " . $idAgent );
$difference = get_system_time () - strtotime ( $agent [ " ultimo_contacto " ]);
$max = $agent [ " intervalo " ];
if ( $maxModules ) {
$sql = sprintf ( " SELECT MAX(module_interval) FROM tagente_modulo WHERE id_agente = %d " , $id_agente );
$maxModules = ( int ) get_db_sql ( $sql );
if ( $maxModules > 0 )
$max = $maxModules ;
}
if ( $max > 0 )
return round ( $difference / (( $max * 2 ) / 100 ));
else
return false ;
}
2010-10-08 13:16:57 +02:00
/**
* Get all the modules common in various agents that have associated alerts . If an empty list is passed it will select all
*
* @ param mixed Agent id to get modules . It can also be an array of agent id ' s .
* @ param mixed Array , comma delimited list or singular value of rows to
* select . If nothing is specified , nombre will be selected . A special
* character " * " will select all the values .
* @ param mixed Aditional filters to the modules . It can be an indexed array
* ( keys would be the field name and value the expected value , and would be
* joined with an AND operator ) or a string , including any SQL clause ( without
* the WHERE keyword ) .
* @ param bool Wheter to return the modules indexed by the id_agente_modulo or
* not . Default is indexed .
* Example :
< code >
Both are similars :
$modules = get_agent_modules ( $id_agent , false , array ( 'disabled' => 0 ));
$modules = get_agent_modules ( $id_agent , false , 'disabled = 0' );
Both are similars :
$modules = get_agent_modules ( $id_agent , '*' , array ( 'disabled' => 0 , 'history_data' => 0 ));
$modules = get_agent_modules ( $id_agent , '*' , 'disabled = 0 AND history_data = 0' );
</ code >
*
* @ return array An array with all modules in the agent .
* If multiple rows are selected , they will be in an array
*/
function get_agents_common_modules_with_alerts ( $id_agent , $filter = false , $indexed = true , $get_not_init_modules = true ) {
$id_agent = safe_int ( $id_agent , 1 );
$where = '' ;
if ( ! empty ( $id_agent )) {
$where = sprintf ( ' WHERE t2.id_agent_module = t1.id_agente_modulo AND delete_pending = 0 AND id_agente IN (%s) AND (SELECT count(nombre) FROM tagente_modulo t3, talert_template_modules t4 WHERE t4.id_agent_module = t3.id_agente_modulo AND delete_pending = 0 AND t1.nombre = t3.nombre AND id_agente IN (%s)) = (%s)' , implode ( " , " , ( array ) $id_agent ), implode ( " , " , ( array ) $id_agent ), count ( $id_agent ));
}
if ( ! empty ( $filter )) {
$where .= ' AND ' ;
if ( is_array ( $filter )) {
$fields = array ();
foreach ( $filter as $field => $value ) {
array_push ( $fields , $field . '="' . $value . '"' );
}
$where .= implode ( ' AND ' , $fields );
} else {
$where .= $filter ;
}
}
$sql = sprintf ( ' SELECT DISTINCT ( t1 . id_agente_modulo )
FROM tagente_modulo t1 , talert_template_modules t2
% s
ORDER BY nombre ' ,
$where );
$result = get_db_all_rows_sql ( $sql );
if ( empty ( $result )) {
return array ();
}
if ( ! $indexed )
return $result ;
$modules = array ();
foreach ( $result as $module ) {
if ( $get_not_init_modules || get_agentmodule_is_init ( $module [ 'id_agente_modulo' ])) {
$modules [ $module [ 'id_agente_modulo' ]] = $module [ 'id_agente_modulo' ];
}
}
return $modules ;
}
/**
* Get all the modules common in various agents . If an empty list is passed it will select all
*
* @ param mixed Agent id to get modules . It can also be an array of agent id ' s .
* @ param mixed Array , comma delimited list or singular value of rows to
* select . If nothing is specified , nombre will be selected . A special
* character " * " will select all the values .
* @ param mixed Aditional filters to the modules . It can be an indexed array
* ( keys would be the field name and value the expected value , and would be
* joined with an AND operator ) or a string , including any SQL clause ( without
* the WHERE keyword ) .
* @ param bool Wheter to return the modules indexed by the id_agente_modulo or
* not . Default is indexed .
* Example :
< code >
Both are similars :
$modules = get_agent_modules ( $id_agent , false , array ( 'disabled' => 0 ));
$modules = get_agent_modules ( $id_agent , false , 'disabled = 0' );
Both are similars :
$modules = get_agent_modules ( $id_agent , '*' , array ( 'disabled' => 0 , 'history_data' => 0 ));
$modules = get_agent_modules ( $id_agent , '*' , 'disabled = 0 AND history_data = 0' );
</ code >
*
* @ return array An array with all modules in the agent .
* If multiple rows are selected , they will be in an array
*/
function get_agents_common_modules ( $id_agent , $filter = false , $indexed = true , $get_not_init_modules = true ) {
$id_agent = safe_int ( $id_agent , 1 );
$where = '' ;
if ( ! empty ( $id_agent )) {
$where = sprintf ( ' WHERE delete_pending = 0 AND id_agente IN (%s) AND (SELECT count(nombre) FROM tagente_modulo t2 WHERE delete_pending = 0 AND t1.nombre = t2.nombre AND id_agente IN (%s)) = (%s)' , implode ( " , " , ( array ) $id_agent ), implode ( " , " , ( array ) $id_agent ), count ( $id_agent ));
}
if ( ! empty ( $filter )) {
$where .= ' AND ' ;
if ( is_array ( $filter )) {
$fields = array ();
foreach ( $filter as $field => $value ) {
array_push ( $fields , $field . '="' . $value . '"' );
}
$where .= implode ( ' AND ' , $fields );
} else {
$where .= $filter ;
}
}
$sql = sprintf ( ' SELECT DISTINCT ( t1 . id_agente_modulo ) as id_agente_modulo
FROM tagente_modulo t1 , talert_template_modules t2
% s
ORDER BY nombre ' ,
$where );
$result = get_db_all_rows_sql ( $sql );
if ( empty ( $result )) {
return array ();
}
if ( ! $indexed )
return $result ;
$modules = array ();
foreach ( $result as $module ) {
if ( $get_not_init_modules || get_agentmodule_is_init ( $module [ 'id_agente_modulo' ])) {
$modules [ $module [ 'id_agente_modulo' ]] = $module [ 'id_agente_modulo' ];
}
}
return $modules ;
}
2009-01-15 11:21:38 +01:00
?>