2012-01-16 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/DB.pm: Added a missed safe input in the get_agent_module_id function * util/pandora_manage.pl: Added options to update a field of a data, network, plugin or snmp module git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5374 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
0b748c7eda
commit
25290779b5
|
@ -1,3 +1,11 @@
|
|||
2012-01-16 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* lib/PandoraFMS/DB.pm: Added a missed safe input in
|
||||
the get_agent_module_id function
|
||||
|
||||
* util/pandora_manage.pl: Added options to update a
|
||||
field of a data, network, plugin or snmp module
|
||||
|
||||
2012-01-13 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* util/pandora_manage.pl: Added update_alert_template
|
||||
|
|
|
@ -238,7 +238,7 @@ sub get_module_name ($$) {
|
|||
sub get_agent_module_id ($$$) {
|
||||
my ($dbh, $module_name, $agent_id) = @_;
|
||||
|
||||
my $rc = get_db_value ($dbh, "SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 0 AND nombre = ? AND id_agente = ?", $module_name, $agent_id);
|
||||
my $rc = get_db_value ($dbh, "SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 0 AND nombre = ? AND id_agente = ?", safe_input($module_name), $agent_id);
|
||||
return defined ($rc) ? $rc : -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,62 @@ exit;
|
|||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
##############################################################################
|
||||
# Print a help screen and exit.
|
||||
##############################################################################
|
||||
sub help_screen{
|
||||
print "Usage: $0 <path to pandora_server.conf> [options] \n\n" unless $param ne '';
|
||||
print "Available options:\n\n" unless $param ne '';
|
||||
print "Available options for $param:\n\n" unless $param eq '';
|
||||
help_screen_line('--disable_alerts', '', 'Disable alerts in all groups (system wide)');
|
||||
help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)');
|
||||
help_screen_line('--disable_eacl', '', 'Disable enterprise ACL system');
|
||||
help_screen_line('--enable_eacl', '', 'Enable enterprise ACL system');
|
||||
help_screen_line('--disable_group', '<group_name>', 'Disable agents from an entire group');
|
||||
help_screen_line('--enable_group', '<group_name>', 'Enable agents from an entire group');
|
||||
help_screen_line('--create_agent', '<agent_name> <operating_system> <group> <server_name> [<address> <description> <interval>]', 'Create agent');
|
||||
help_screen_line('--delete_agent', '<agent_name>', 'Delete agent');
|
||||
help_screen_line('--create_data_module', '<module_name> <module_type> <agent_name> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <definition_file> <warning_str> <critical_str>]', 'Add data server module to agent');
|
||||
help_screen_line('--create_network_module', '<module_name> <module_type> <agent_name> <module_address> [<module_port> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add not snmp network module to agent');
|
||||
help_screen_line('--create_snmp_module', '<module_name> <module_type> <agent_name> <module_address> <module_port> <version> [<community> <oid> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <snmp3_priv_method> <snmp3_priv_pass> <snmp3_sec_level> <snmp3_auth_method> <snmp3_auth_user> <snmp3_priv_pass> <ff_threshold> <warning_str> <critical_str>]', 'Add snmp network module to agent');
|
||||
help_screen_line('--create_plugin_module', '<module_name> <module_type> <agent_name> <module_address> <module_port> <plugin_name> <user> <password> <parameters> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add plug-in module to agent');
|
||||
help_screen_line('--delete_module', 'Delete module from agent', '<module_name> <agent_name>');
|
||||
help_screen_line('--create_template_module', '<template_name> <module_name> <agent_name>', 'Add alert template to module');
|
||||
help_screen_line('--delete_template_module', '<template_name> <module_name> <agent_name>', 'Delete alert template from module');
|
||||
help_screen_line('--create_template_action', '<action_name> <template_name> <module_name> <agent_name> [<fires_min> <fires_max>]', 'Add alert action to module-template');
|
||||
help_screen_line('--delete_template_action', '<action_name> <template_name> <module_name> <agent_name>', 'Delete alert action from module-template');
|
||||
help_screen_line('--data_module', '<server_name> <agent_name> <module_name> <module_type> [<datetime>]', 'Insert data to module');
|
||||
help_screen_line('--create_user', '<user_name> <user_password> <is_admin> [<comments>]', 'Create user');
|
||||
help_screen_line('--delete_user', '<user_name>', 'Delete user');
|
||||
help_screen_line('--create_profile', '<user_name> <profile_name> <group_name>', 'Add perfil to user');
|
||||
help_screen_line('--delete_profile', '<user_name> <profile_name> <group_name>', 'Delete perfil from user');
|
||||
help_screen_line('--create_event', '<event> <event_type> <agent_name> <module_name> <group_name> [<event_status> <severity> <template_name>]', 'Add event');
|
||||
help_screen_line('--validate_event', '<agent_name> <module_name> <datetime_min> <datetime_max> <user_name> <criticity> <template_name>', 'Validate events');
|
||||
help_screen_line('--create_incident', '<title> <description> <origin> <status> <priority 0 for Informative, 1 for Low, 2 for Medium, 3 for Serious, 4 for Very serious or 5 for Maintenance> <group> [<owner>]', 'Create incidents');
|
||||
help_screen_line('--delete_data', '-m <module_name> <agent_name> | -a <agent_name> | -g <group_name>', 'Delete historic data of a module, the modules of an agent or the modules of the agents of a group');
|
||||
help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file');
|
||||
help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy');
|
||||
help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy');
|
||||
help_screen_line('--create_group', '<group_name> [<parent_group_name> <icon>]', 'Create an agent group');
|
||||
help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy');
|
||||
help_screen_line('--disable_user', '<user_id>', 'Disable a given user');
|
||||
help_screen_line('--enable_user', '<user_id>', 'Enable a given user');
|
||||
help_screen_line('--update_user', '<user_id> <field_to_change> <new_value>', 'Update a user field. The fields can be the following: email, phone, is_admin (0-1), language, id_skin, flash_chart (0-1), comments, fullname, password');
|
||||
help_screen_line('--add_profile_to_user', '<user_id> <profile_name> [<group_name>]', 'Add a profile in group to a user');
|
||||
help_screen_line('--get_module_data', '<agent_name> <module_name> <interval> [<csv_separator>]', 'Show the data of a module in the last X seconds (interval) in CSV format');
|
||||
help_screen_line('--create_policy_data_module', '<policy_name> <module_name> <module_type> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <data_configuration> <warning_str> <critical_str>]', 'Add data server module to policy');
|
||||
help_screen_line('--create_policy_network_module', '<policy_name> <module_name> <module_type> [<module_port> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add not snmp network module to policy');
|
||||
help_screen_line('--create_policy_snmp_module', '<policy_name> <module_name> <module_type> <module_port> <version> [<community> <oid> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <snmp3_priv_method> <snmp3_priv_pass> <snmp3_sec_level> <snmp3_auth_method> <snmp3_auth_user> <snmp3_priv_pass> <ff_threshold> <warning_str> <critical_str>]', 'Add snmp network module to policy');
|
||||
help_screen_line('--create_policy_plugin_module', '<policy_name> <module_name> <module_type> <module_port> <plugin_name> <user> <password> <parameters> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add plug-in module to policy');
|
||||
help_screen_line('--create_alert_template', '<template_name> <condition_type_serialized> <time_from> <time_to> [<description> <group_name> <field1> <field2> <field3> <priority> <default_action> <days> <time_threshold> <min_alerts> <max_alerts> <alert_recovery> <field2_recovery> <field3_recovery> <condition_type_separator>]', 'Create alert template');
|
||||
help_screen_line('--delete_alert_template', '<template_name>', 'Delete alert template');
|
||||
help_screen_line('--update_alert_template', '<template_name> <field_to_change> <new_value>', 'Update a field of an alert template');
|
||||
help_screen_line('--update_module', '<agent_name> <module_name> <field_to_change> <new_value>', 'Update a module field');
|
||||
|
||||
print "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Disable a entire group
|
||||
###############################################################################
|
||||
|
@ -470,61 +526,6 @@ sub help_screen_line($$$){
|
|||
print "\t$option $parameters\t$help.\n" unless ($param ne '' && $param ne $option);
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Print a help screen and exit.
|
||||
##############################################################################
|
||||
sub help_screen{
|
||||
print "Usage: $0 <path to pandora_server.conf> [options] \n\n" unless $param ne '';
|
||||
print "Available options:\n\n" unless $param ne '';
|
||||
print "Available options for $param:\n\n" unless $param eq '';
|
||||
help_screen_line('--disable_alerts', '', 'Disable alerts in all groups (system wide)');
|
||||
help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)');
|
||||
help_screen_line('--disable_eacl', '', 'Disable enterprise ACL system');
|
||||
help_screen_line('--enable_eacl', '', 'Enable enterprise ACL system');
|
||||
help_screen_line('--disable_group', '<group_name>', 'Disable agents from an entire group');
|
||||
help_screen_line('--enable_group', '<group_name>', 'Enable agents from an entire group');
|
||||
help_screen_line('--create_agent', '<agent_name> <operating_system> <group> <server_name> [<address> <description> <interval>]', 'Create agent');
|
||||
help_screen_line('--delete_agent', '<agent_name>', 'Delete agent');
|
||||
help_screen_line('--create_data_module', '<module_name> <module_type> <agent_name> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <definition_file> <warning_str> <critical_str>]', 'Add data server module to agent');
|
||||
help_screen_line('--create_network_module', '<module_name> <module_type> <agent_name> <module_address> [<module_port> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add not snmp network module to agent');
|
||||
help_screen_line('--create_snmp_module', '<module_name> <module_type> <agent_name> <module_address> <module_port> <version> [<community> <oid> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <snmp3_priv_method> <snmp3_priv_pass> <snmp3_sec_level> <snmp3_auth_method> <snmp3_auth_user> <snmp3_priv_pass> <ff_threshold> <warning_str> <critical_str>]', 'Add snmp network module to agent');
|
||||
help_screen_line('--create_plugin_module', '<module_name> <module_type> <agent_name> <module_address> <module_port> <plugin_name> <user> <password> <parameters> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add plug-in module to agent');
|
||||
help_screen_line('--delete_module', 'Delete module from agent', '<module_name> <agent_name>');
|
||||
help_screen_line('--create_template_module', '<template_name> <module_name> <agent_name>', 'Add alert template to module');
|
||||
help_screen_line('--delete_template_module', '<template_name> <module_name> <agent_name>', 'Delete alert template from module');
|
||||
help_screen_line('--create_template_action', '<action_name> <template_name> <module_name> <agent_name> [<fires_min> <fires_max>]', 'Add alert action to module-template');
|
||||
help_screen_line('--delete_template_action', '<action_name> <template_name> <module_name> <agent_name>', 'Delete alert action from module-template');
|
||||
help_screen_line('--data_module', '<server_name> <agent_name> <module_name> <module_type> [<datetime>]', 'Insert data to module');
|
||||
help_screen_line('--create_user', '<user_name> <user_password> <is_admin> [<comments>]', 'Create user');
|
||||
help_screen_line('--delete_user', '<user_name>', 'Delete user');
|
||||
help_screen_line('--create_profile', '<user_name> <profile_name> <group_name>', 'Add perfil to user');
|
||||
help_screen_line('--delete_profile', '<user_name> <profile_name> <group_name>', 'Delete perfil from user');
|
||||
help_screen_line('--create_event', '<event> <event_type> <agent_name> <module_name> <group_name> [<event_status> <severity> <template_name>]', 'Add event');
|
||||
help_screen_line('--validate_event', '<agent_name> <module_name> <datetime_min> <datetime_max> <user_name> <criticity> <template_name>', 'Validate events');
|
||||
help_screen_line('--create_incident', '<title> <description> <origin> <status> <priority 0 for Informative, 1 for Low, 2 for Medium, 3 for Serious, 4 for Very serious or 5 for Maintenance> <group> [<owner>]', 'Create incidents');
|
||||
help_screen_line('--delete_data', '-m <module_name> <agent_name> | -a <agent_name> | -g <group_name>', 'Delete historic data of a module, the modules of an agent or the modules of the agents of a group');
|
||||
help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file');
|
||||
help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy');
|
||||
help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy');
|
||||
help_screen_line('--create_group', '<group_name> [<parent_group_name> <icon>]', 'Create an agent group');
|
||||
help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy');
|
||||
help_screen_line('--disable_user', '<user_id>', 'Disable a given user');
|
||||
help_screen_line('--enable_user', '<user_id>', 'Enable a given user');
|
||||
help_screen_line('--update_user', '<user_id> <field_to_change> <new_value>', 'Update a user field. The fields can be the following: email, phone, is_admin (0-1), language, id_skin, flash_chart (0-1), comments, fullname, password');
|
||||
help_screen_line('--add_profile_to_user', '<user_id> <profile_name> [<group_name>]', 'Add a profile in group to a user');
|
||||
help_screen_line('--get_module_data', '<agent_name> <module_name> <interval> [<csv_separator>]', 'Show the data of a module in the last X seconds (interval) in CSV format');
|
||||
help_screen_line('--create_policy_data_module', '<policy_name> <module_name> <module_type> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <data_configuration> <warning_str> <critical_str>]', 'Add data server module to policy');
|
||||
help_screen_line('--create_policy_network_module', '<policy_name> <module_name> <module_type> [<module_port> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add not snmp network module to policy');
|
||||
help_screen_line('--create_policy_snmp_module', '<policy_name> <module_name> <module_type> <module_port> <version> [<community> <oid> <description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <snmp3_priv_method> <snmp3_priv_pass> <snmp3_sec_level> <snmp3_auth_method> <snmp3_auth_user> <snmp3_priv_pass> <ff_threshold> <warning_str> <critical_str>]', 'Add snmp network module to policy');
|
||||
help_screen_line('--create_policy_plugin_module', '<policy_name> <module_name> <module_type> <module_port> <plugin_name> <user> <password> <parameters> [<description> <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> <warning_str> <critical_str>]', 'Add plug-in module to policy');
|
||||
help_screen_line('--create_alert_template', '<template_name> <condition_type_serialized> <time_from> <time_to> [<description> <group_name> <field1> <field2> <field3> <priority> <default_action> <days> <time_threshold> <min_alerts> <max_alerts> <alert_recovery> <field2_recovery> <field3_recovery> <condition_type_separator>]', 'Create alert template');
|
||||
help_screen_line('--delete_alert_template', '<template_name>', 'Delete alert template');
|
||||
help_screen_line('--update_alert_template', '<template_name> <field_to_change> <new_value>', 'Update a field of an alert template');
|
||||
|
||||
print "\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# CLI FUNCTIONS
|
||||
|
@ -1212,7 +1213,7 @@ sub cli_create_plugin_module($) {
|
|||
$parameters{'id_plugin'} = $plugin_id;
|
||||
$parameters{'plugin_user'} = $user;
|
||||
$parameters{'plugin_pass'} = $password;
|
||||
$parameters{'plugin_parameter'} = $params;
|
||||
$parameters{'plugin_parameter'} = safe_input($params);
|
||||
|
||||
# Optional parameters
|
||||
$parameters{'id_module_group'} = $module_group_id unless !defined ($module_group);
|
||||
|
@ -1552,7 +1553,7 @@ sub cli_alert_template_update() {
|
|||
exit;
|
||||
}
|
||||
|
||||
print "[INFO] Updating field '$field' in user '$template_name'\n\n";
|
||||
print "[INFO] Updating field '$field' in alert template '$template_name'\n\n";
|
||||
|
||||
my $update;
|
||||
|
||||
|
@ -1561,6 +1562,334 @@ sub cli_alert_template_update() {
|
|||
pandora_update_alert_template_from_hash ($update, 'id', $template_id, $dbh);
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Check the specific fields of data module when update
|
||||
##############################################################################
|
||||
|
||||
sub pandora_check_data_module_fields($) {
|
||||
my $field_value = shift;
|
||||
|
||||
print "[ERROR] The field '".$field_value->{'field'}."' is not available for data modules\n\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Check the specific fields of network module when update
|
||||
##############################################################################
|
||||
|
||||
sub pandora_check_network_module_fields($) {
|
||||
my $field_value = shift;
|
||||
|
||||
if($field_value->{'field'} eq 'ff_threshold') {
|
||||
$field_value->{'field'} = 'min_ff_event';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'module_address') {
|
||||
my $agent_name = @ARGV[3];
|
||||
|
||||
my $id_agent = get_agent_id($dbh,$agent_name);
|
||||
|
||||
$field_value->{'field'} = 'ip_target';
|
||||
|
||||
# Check if the address already exist
|
||||
my $address_id = get_addr_id($dbh,$field_value->{'new_value'});
|
||||
|
||||
# If the addres doesnt exist, we add it to the addresses list
|
||||
if($address_id == -1) {
|
||||
$address_id = add_address($dbh,$field_value->{'new_value'});
|
||||
}
|
||||
|
||||
# Add the address to the agent
|
||||
add_new_address_agent ($dbh, $address_id, $id_agent);
|
||||
|
||||
# Only pending set as main address (Will be done at the end of the function)
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'module_port') {
|
||||
if ($field_value->{'new_value'} > 65535 || $field_value->{'new_value'} < 1) {
|
||||
print "[ERROR] Port error. Port must into [1-65535]\n\n";
|
||||
exit;
|
||||
}
|
||||
$field_value->{'field'} = 'tcp_port';
|
||||
}
|
||||
else {
|
||||
print "[ERROR] The field '".$field_value->{'field'}."' is not available for network modules\n\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Check the specific fields of snmp module when update
|
||||
##############################################################################
|
||||
|
||||
sub pandora_check_snmp_module_fields($) {
|
||||
my $field_value = shift;
|
||||
|
||||
if($field_value->{'field'} eq 'version') {
|
||||
$field_value->{'field'} = 'tcp_send';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'ff_threshold') {
|
||||
$field_value->{'field'} = 'min_ff_event';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'community') {
|
||||
$field_value->{'field'} = 'snmp_community';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'oid') {
|
||||
$field_value->{'field'} = 'snmp_oid';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'snmp3_priv_method') {
|
||||
$field_value->{'field'} = 'custom_string_1';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'snmp3_priv_pass') {
|
||||
$field_value->{'field'} = 'custom_string_2';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'snmp3_sec_level') {
|
||||
$field_value->{'field'} = 'custom_string_3';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'snmp3_auth_method') {
|
||||
$field_value->{'field'} = 'plugin_parameter';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'snmp3_auth_user') {
|
||||
$field_value->{'field'} = 'plugin_user';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'snmp3_auth_pass') {
|
||||
$field_value->{'field'} = 'plugin_pass';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'module_address') {
|
||||
my $agent_name = @ARGV[3];
|
||||
|
||||
my $id_agent = get_agent_id($dbh,$agent_name);
|
||||
|
||||
$field_value->{'field'} = 'ip_target';
|
||||
|
||||
# Check if the address already exist
|
||||
my $address_id = get_addr_id($dbh,$field_value->{'new_value'});
|
||||
|
||||
# If the addres doesnt exist, we add it to the addresses list
|
||||
if($address_id == -1) {
|
||||
$address_id = add_address($dbh,$field_value->{'new_value'});
|
||||
}
|
||||
|
||||
# Add the address to the agent
|
||||
add_new_address_agent ($dbh, $address_id, $id_agent);
|
||||
|
||||
# Only pending set as main address (Will be done at the end of the function)
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'module_port') {
|
||||
if ($field_value->{'new_value'} > 65535 || $field_value->{'new_value'} < 1) {
|
||||
print "[ERROR] Port error. Port must into [1-65535]\n\n";
|
||||
exit;
|
||||
}
|
||||
$field_value->{'field'} = 'tcp_port';
|
||||
}
|
||||
else {
|
||||
print "[ERROR] The field '".$field_value->{'field'}."' is not available for SNMP modules\n\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Check the specific fields of plugin module when update
|
||||
##############################################################################
|
||||
|
||||
sub pandora_check_plugin_module_fields($) {
|
||||
my $field_value = shift;
|
||||
|
||||
if($field_value->{'field'} eq 'plugin_name') {
|
||||
my $plugin_id = get_plugin_id($dbh,$field_value->{'new_value'});
|
||||
exist_check($plugin_id,'plugin',$field_value->{'new_value'});
|
||||
|
||||
$field_value->{'new_value'} = $plugin_id;
|
||||
$field_value->{'field'} = 'id_plugin';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'user') {
|
||||
$field_value->{'field'} = 'plugin_user';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'password') {
|
||||
$field_value->{'field'} = 'plugin_pass';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'parameters') {
|
||||
$field_value->{'field'} = 'plugin_parameter';
|
||||
$field_value->{'new_value'} = safe_input($field_value->{'new_value'});
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'ff_threshold') {
|
||||
$field_value->{'field'} = 'min_ff_event';
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'module_address') {
|
||||
my $agent_name = @ARGV[3];
|
||||
|
||||
my $id_agent = get_agent_id($dbh,$agent_name);
|
||||
|
||||
$field_value->{'field'} = 'ip_target';
|
||||
|
||||
# Check if the address already exist
|
||||
my $address_id = get_addr_id($dbh,$field_value->{'new_value'});
|
||||
|
||||
# If the addres doesnt exist, we add it to the addresses list
|
||||
if($address_id == -1) {
|
||||
$address_id = add_address($dbh,$field_value->{'new_value'});
|
||||
}
|
||||
|
||||
# Add the address to the agent
|
||||
add_new_address_agent ($dbh, $address_id, $id_agent);
|
||||
|
||||
# Only pending set as main address (Will be done at the end of the function)
|
||||
}
|
||||
elsif($field_value->{'field'} eq 'module_port') {
|
||||
$field_value->{'field'} = 'tcp_port';
|
||||
}
|
||||
else {
|
||||
print "[ERROR] The field '".$field_value->{'field'}."' is not available for plugin modules\n\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Add a profile to a User in a Group
|
||||
# Related option: --update_module
|
||||
##############################################################################
|
||||
|
||||
sub cli_module_update() {
|
||||
my ($module_name,$agent_name,$field,$new_value) = @ARGV[2..5];
|
||||
|
||||
my $id_agent = get_agent_id($dbh,$agent_name);
|
||||
exist_check($id_agent,'agent',$agent_name);
|
||||
my $id_agent_module = get_agent_module_id ($dbh, $module_name, $id_agent);
|
||||
exist_check($id_agent_module,'agent module',$module_name);
|
||||
|
||||
# Check and adjust parameters in common values
|
||||
|
||||
if($field eq 'min' || $field eq 'max' || $field eq 'post_process' || $field eq 'history_data') {
|
||||
# Fields admited, no changes
|
||||
}
|
||||
elsif($field eq 'interval') {
|
||||
$field = 'module_interval';
|
||||
}
|
||||
elsif($field eq 'warning_min') {
|
||||
$field = 'min_warning';
|
||||
}
|
||||
elsif($field eq 'warning_max') {
|
||||
$field = 'max_warning';
|
||||
}
|
||||
elsif($field eq 'critical_min') {
|
||||
$field = 'min_critical';
|
||||
}
|
||||
elsif($field eq 'critical_max') {
|
||||
$field = 'max_critical';
|
||||
}
|
||||
elsif($field eq 'warning_str') {
|
||||
$field = 'str_warning';
|
||||
$new_value = safe_input($new_value);
|
||||
}
|
||||
elsif($field eq 'critical_str') {
|
||||
$field = 'str_critical';
|
||||
$new_value = safe_input($new_value);
|
||||
}
|
||||
elsif($field eq 'agent_name') {
|
||||
my $id_agent_change = get_agent_id($dbh,$new_value);
|
||||
exist_check($id_agent_change,'agent',$new_value);
|
||||
my $id_agent_module_exist = get_agent_module_id ($dbh, $module_name, $id_agent_change);
|
||||
if($id_agent_module_exist != -1) {
|
||||
print "[ERROR] A module called '$module_name' already exist in the agent '$new_value'\n\n";
|
||||
exit;
|
||||
}
|
||||
$field = 'id_agente';
|
||||
$new_value = $id_agent_change;
|
||||
}
|
||||
elsif($field eq 'module_name') {
|
||||
my $id_agent_module_change = get_agent_module_id ($dbh, $new_value, $id_agent);
|
||||
if($id_agent_module_change != -1) {
|
||||
print "[ERROR] A module called '$new_value' already exist in the agent '$agent_name'\n\n";
|
||||
exit;
|
||||
}
|
||||
$field = 'nombre';
|
||||
$new_value = safe_input($new_value);
|
||||
}
|
||||
elsif($field eq 'description') {
|
||||
$field = 'descripcion';
|
||||
$new_value = safe_input($new_value);
|
||||
}
|
||||
elsif($field eq 'module_group') {
|
||||
my $module_group_id = get_module_group_id($dbh,$new_value);
|
||||
|
||||
if($module_group_id == -1) {
|
||||
print "[ERROR] Module group '$new_value' doesnt exist\n\n";
|
||||
exit;
|
||||
}
|
||||
$field = 'id_module_group';
|
||||
$new_value = $module_group_id;
|
||||
}
|
||||
else {
|
||||
# If is not a common value, check type and call type update funtion
|
||||
my $type = pandora_get_module_type($dbh,$id_agent_module);
|
||||
|
||||
my %field_value;
|
||||
$field_value{'field'} = $field;
|
||||
$field_value{'new_value'} = $new_value;
|
||||
|
||||
if($type eq 'data') {
|
||||
pandora_check_data_module_fields(\%field_value);
|
||||
}
|
||||
elsif($type eq 'network') {
|
||||
pandora_check_network_module_fields(\%field_value);
|
||||
}
|
||||
elsif($type eq 'snmp') {
|
||||
pandora_check_snmp_module_fields(\%field_value);
|
||||
}
|
||||
elsif($type eq 'plugin') {
|
||||
pandora_check_plugin_module_fields(\%field_value);
|
||||
}
|
||||
else {
|
||||
print "[ERROR] The field '$field' is not available for this type of module\n\n";
|
||||
}
|
||||
|
||||
$field = $field_value{'field'};
|
||||
$new_value = $field_value{'new_value'};
|
||||
}
|
||||
|
||||
print "[INFO] Updating field '$field' in module '$module_name' of agent '$agent_name' with new value '$new_value'\n\n";
|
||||
|
||||
my $update;
|
||||
|
||||
$update->{$field} = $new_value;
|
||||
|
||||
pandora_update_module_from_hash ($conf, $update, 'id_agente_modulo', $id_agent_module, $dbh);
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Return the type of given module (data, network, snmp or plugin)
|
||||
##############################################################################
|
||||
|
||||
sub pandora_get_module_type($$) {
|
||||
my ($dbh,$id_agent_module) = @_;
|
||||
|
||||
my $id_modulo = get_db_value($dbh, 'SELECT id_modulo FROM tagente_modulo WHERE id_agente_modulo = ?',$id_agent_module);
|
||||
|
||||
if($id_modulo == 1) {
|
||||
return 'data';
|
||||
}
|
||||
if($id_modulo == 2) {
|
||||
my $id_module_type = get_db_value($dbh, 'SELECT id_tipo_modulo FROM tagente_modulo WHERE id_agente_modulo = ?',$id_agent_module);
|
||||
if($id_module_type >= 15 && $id_module_type <= 18) {
|
||||
return 'snmp';
|
||||
}
|
||||
else {
|
||||
return 'network';
|
||||
}
|
||||
}
|
||||
elsif($id_modulo == 4) {
|
||||
return 'plugin';
|
||||
}
|
||||
elsif($id_modulo == 6) {
|
||||
return 'wmi';
|
||||
}
|
||||
elsif($id_modulo == 7) {
|
||||
return 'web';
|
||||
}
|
||||
else {
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Add a profile to a User in a Group
|
||||
# Related option: --add_profile_to_user
|
||||
|
@ -1672,7 +2001,7 @@ sub cli_delete_profile() {
|
|||
}
|
||||
|
||||
##############################################################################
|
||||
# Create event.
|
||||
# Create event
|
||||
# Related option: --create_event
|
||||
##############################################################################
|
||||
|
||||
|
@ -2285,6 +2614,10 @@ sub pandora_manage_main ($$$) {
|
|||
param_check($ltotal, 3);
|
||||
cli_alert_template_update();
|
||||
}
|
||||
elsif ($param eq '--update_module') {
|
||||
param_check($ltotal, 4);
|
||||
cli_module_update();
|
||||
}
|
||||
else {
|
||||
print "[ERROR] Invalid option '$param'.\n\n";
|
||||
$param = '';
|
||||
|
|
Loading…
Reference in New Issue