diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 0ee52ea3a8..db9fcfe8c2 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2013-02-05 Sancho Lerena + + * util/pandora_manage.pl: Added feature for adding + custom traps. Improved help format syntax. + 2013-02-05 Sancho Lerena * util/pandora_db.pl: Added deletion for extended session diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index c84db2ffdb..69fdd8a733 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -3,7 +3,7 @@ ############################################################################### # Pandora FMS General Management Tool ############################################################################### -# Copyright (c) 2010 Artica Soluciones Tecnologicas S.L +# Copyright (c) 2013 Artica Soluciones Tecnologicas S.L # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 2 @@ -27,7 +27,7 @@ use PandoraFMS::Core; use PandoraFMS::Config; # version: define current version -my $version = "5.0dev PS120621"; +my $version = "5.0dev PS130205"; # save program name for logging my $progname = basename($0); @@ -86,8 +86,8 @@ sub help_screen{ print "Available options by category:\n\n" unless $param ne ''; print "Available options for $param:\n\n" unless $param eq ''; print "AGENTS:\n\n" unless $param ne ''; - help_screen_line('--create_agent', ' [
]', 'Create agent'); - help_screen_line('--update_agent', ' ', 'Update an agent field. The fields can be the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id'); + help_screen_line('--create_agent', " \n\t [
]", 'Create agent'); + help_screen_line('--update_agent', ' ', "Update an agent field. The fields can be \n\t the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), \n\t parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id"); help_screen_line('--delete_agent', '', 'Delete agent'); help_screen_line('--disable_group', '', 'Disable agents from an entire group'); help_screen_line('--enable_group', '', 'Enable agents from an entire group'); @@ -95,37 +95,37 @@ sub help_screen{ help_screen_line('--stop_downtime', '', 'Stop a planned downtime'); help_screen_line('--get_agent_group', '', 'Get the group name of an agent'); help_screen_line('--get_agent_modules', '', 'Get the modules of an agent'); - help_screen_line('--get_agents', '[ ]', 'Get list of agents with optative filter parameters'); + help_screen_line('--get_agents', '[ ]', "Get \n\t list of agents with optative filter parameters"); help_screen_line('--delete_conf_file', '', 'Delete a local conf of a given agent'); - help_screen_line('--clean_conf_file', '', 'Clean a local conf of a given agent deleting all modules, policies, file collections and comments'); + help_screen_line('--clean_conf_file', '', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments"); help_screen_line('--get_bad_conf_files', '', 'Get the files bad configured (without essential tokens)'); - print "MODULES:\n\n" unless $param ne ''; - help_screen_line('--create_data_module', ' [ ]', 'Add data server module to agent'); - help_screen_line('--create_network_module', ' [ ]', 'Add not snmp network module to agent'); - help_screen_line('--create_snmp_module', ' [ ]', 'Add snmp network module to agent'); - help_screen_line('--create_plugin_module', ' [ ]', 'Add plug-in module to agent'); + print "\nMODULES:\n\n" unless $param ne ''; + help_screen_line('--create_data_module', " [ \n\t \n\t ]", 'Add data server module to agent'); + help_screen_line('--create_network_module', " \n\t [ \n\t \n\t ]", 'Add not snmp network module to agent'); + help_screen_line('--create_snmp_module', " \n\t [ \n\t \n\t \n\t \n\t ]", 'Add snmp network module to agent'); + help_screen_line('--create_plugin_module', " \n\t [ \n\t \n\t ]", 'Add plug-in module to agent'); help_screen_line('--delete_module', 'Delete module from agent', ' '); - help_screen_line('--data_module', ' []', 'Insert data to module'); - help_screen_line('--get_module_data', ' []', 'Show the data of a module in the last X seconds (interval) in CSV format'); - help_screen_line('--delete_data', '-m | -a | -g ', 'Delete historic data of a module, the modules of an agent or the modules of the agents of a group'); + help_screen_line('--data_module', " \n\t []", 'Insert data to module'); + help_screen_line('--get_module_data', " []", "\n\t Show the data of a module in the last X seconds (interval) in CSV format"); + help_screen_line('--delete_data', '-m | -a | -g ', "Delete historic \n\t data of a module, the modules of an agent or the modules of the agents of a group"); help_screen_line('--update_module', ' ', 'Update a module field'); - help_screen_line('--get_agents_module_current_data', '', 'Get the agent and current data of all the modules with a given name'); - help_screen_line('--create_network_module_from_component', ' ', 'Create a new network module from a network component'); - print "ALERTS:\n\n" unless $param ne ''; + help_screen_line('--get_agents_module_current_data', '', "Get the agent and current data \n\t of all the modules with a given name"); + help_screen_line('--create_network_module_from_component', ' ', "Create a new network \n\t module from a network component"); + print "\nALERTS:\n\n" unless $param ne ''; help_screen_line('--create_template_module', ' ', 'Add alert template to module'); help_screen_line('--delete_template_module', ' ', 'Delete alert template from module'); - help_screen_line('--create_template_action', ' [ ]', 'Add alert action to module-template'); - help_screen_line('--delete_template_action', ' ', 'Delete alert action from module-template'); + help_screen_line('--create_template_action', " \n\t [ ]', 'Add alert action to module-template"); + help_screen_line('--delete_template_action', " \n\t ", 'Delete alert action from module-template'); 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('--create_alert_template', ' [ ]', 'Create alert template'); + help_screen_line('--create_alert_template', " \n\t [ \n\t \n\t \n\t ]", 'Create alert template'); help_screen_line('--delete_alert_template', '', 'Delete alert template'); - help_screen_line('--update_alert_template', ' ', 'Update a field of an alert template'); + help_screen_line('--update_alert_template', " \n\t ", 'Update a field of an alert template'); help_screen_line('--validate_all_alerts', '', 'Validate all the alerts'); - print "USERS:\n\n" unless $param ne ''; + print "\nUSERS:\n\n" unless $param ne ''; help_screen_line('--create_user', ' []', 'Create user'); help_screen_line('--delete_user', '', 'Delete user'); - help_screen_line('--update_user', ' ', '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('--update_user', ' ', "Update a user field. The fields\n\t can be the following: email, phone, is_admin (0-1), language, id_skin, flash_chart (0-1)\n\t , comments, fullname, password"); help_screen_line('--enable_user', '', 'Enable a given user'); help_screen_line('--disable_user', '', 'Disable a given user'); help_screen_line('--create_profile', ' ', 'Add perfil to user'); @@ -133,32 +133,34 @@ sub help_screen{ help_screen_line('--add_profile_to_user', ' []', 'Add a profile in group to a user'); help_screen_line('--disable_eacl', '', 'Disable enterprise ACL system'); help_screen_line('--enable_eacl', '', 'Enable enterprise ACL system'); - print "EVENTS:\n\n" unless $param ne ''; - help_screen_line('--create_event', ' [ ]', 'Add event'); - help_screen_line('--validate_event', ' ', 'Validate events'); + print "\nEVENTS:\n\n" unless $param ne ''; + help_screen_line('--create_event', " [ \n\t \n\t ]", 'Add event'); + help_screen_line('--validate_event', " \n\t ", 'Validate events'); help_screen_line('--validate_event_id', '', 'Validate event given a event id'); help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); - print "INCIDENTS:\n\n" unless $param ne ''; - help_screen_line('--create_incident', ' <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'); - print "POLICIES:\n\n" unless $param ne ''; + print "\nINCIDENTS:\n\n" unless $param ne ''; + help_screen_line('--create_incident', "<title> <description> <origin> <status> <priority 0 for Informative, \n\t 1 for Low, 2 for Medium, 3 for Serious, 4 for Very serious or 5 for Maintenance>\n\t <group> [<owner>]", 'Create incidents'); + print "\nPOLICIES:\n\n" unless $param ne ''; help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy'); help_screen_line('--apply_all_policies', '', 'Force apply to all the policies'); help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy'); help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file'); help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy'); - 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_policy_data_module', "<policy_name> <module_name> <module_type> [<description> \n\t <module_group> <min> <max> <post_process> <interval> <warning_min> <warning_max> \n\t <critical_min> <critical_max> <history_data> <data_configuration> <warning_str> \n\t <critical_str>]", 'Add data server module to policy'); + help_screen_line('--create_policy_network_module', "<policy_name> <module_name> <module_type> [<module_port> \n\t <description> <module_group> <min> <max> <post_process> <interval> \n\t <warning_min> <warning_max> <critical_min> <critical_max> <history_data> <ff_threshold> \n\t <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> \n\t <version> [<community> <oid> <description> <module_group> <min> <max> \n\t <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max> <history_data>\n\t <snmp3_priv_method> <snmp3_priv_pass> <snmp3_sec_level> <snmp3_auth_method> <snmp3_auth_user> \n\t <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> \n\t <module_port> <plugin_name> <user> <password> <parameters> [<description> <module_group> <min> \n\t <max> <post_process> <interval> <warning_min> <warning_max> <critical_min> <critical_max>\n\t <history_data> <ff_threshold> <warning_str> <critical_str>]", 'Add plug-in module to policy'); help_screen_line('--validate_policy_alerts', '<policy_name>', 'Validate the alerts of a given policy'); help_screen_line('--get_policy_modules', '<policy_name>', 'Get the modules of a policy'); - help_screen_line('--get_policies', '[<agent_name>]', 'Get all the policies (without parameters) or the policies of a given agent (agent name as parameter)'); - print "NETFLOW:\n\n" unless $param ne ''; - help_screen_line('--create_netflow_filter', '<filter_name> <group_name> <filter> <aggregate_by dstip|dstport|none|proto|srcip|srcport> <output_format kilobytes|kilobytespersecond|megabytes|megabytespersecond>', 'Create a new netflow filter'); - print "TOOLS:\n\n" unless $param ne ''; - help_screen_line('--exec_from_file', '<file_path> <option_to_execute> <option_params>', 'Execute any CLI option with macros from CSV file'); - print "SETUP:\n\n" unless $param ne ''; - help_screen_line('--set_event_storm_protection', '<value>', 'Enable (1) or disable (0) event storm protection'); + help_screen_line('--get_policies', '[<agent_name>]', "Get all the policies (without parameters) or \n\tthe policies of a given agent (agent name as parameter)"); + + print "\nNETFLOW:\n\n" unless $param ne ''; + help_screen_line('--create_netflow_filter', "<filter_name> <group_name> <filter> \n\t <aggregate_by dstip|dstport|none|proto|srcip|srcport> <output_format kilobytes|kilobytespersecond|\n\t megabytes|megabytespersecond>", "Create a new netflow filter"); + print "\nTOOLS:\n\n" unless $param ne ''; + help_screen_line('--exec_from_file', '<file_path> <option_to_execute> <option_params>', "Execute any CLI option \n\t with macros from CSV file"); + help_screen_line('--create_snmp_trap', '<name> <oid> <description> <severity>', "Create a new trap definition. \n\tSeverity 0 (Maintenance), 1(Info) , 2 (Normal), 3 (Warning), 4 (Critical), 5 (Minor) and 6 (Major)"); + print "\nSETUP:\n\n" unless $param ne ''; + help_screen_line('--set_event_storm_protection', '<value>', "Enable (1) or disable (0) event \n\t storm protection"); print "\n"; exit; @@ -206,7 +208,7 @@ sub pandora_manage_init ($) { $conf->{"quiet"}=0; # Daemon 0 by default - print "\nPandora FMS Manage tool $version Copyright (c) 2010 Artica ST\n"; + print "\nPandora FMS CLI $version Copyright (c) 2013 Artica ST\n"; print "This program is Free Software, licensed under the terms of GPL License v2\n"; print "You can download latest versions and documentation at http://www.pandorafms.org\n\n"; @@ -265,11 +267,30 @@ sub pandora_add_profile_to_user ($$$;$) { VALUES (?, ?, ?)', safe_input($user_id), $profile_id, $group_id); } + +########################################################################## +## Create a SNMP trap, given OID name description +########################################################################## + +sub cli_create_snmp_trap ($$) { + my ($conf, $dbh) = @_; + + my ($name, $oid, $description, $severity); + + ($name, $oid, $description, $severity) = @ARGV[2..5]; + + db_do ($dbh, 'INSERT INTO ttrap_custom_values (`oid`, `text`, `description`, `severity`) + VALUES (?, ?, ?, ?)', $oid, $name, $description, $severity); + + print "Creando $name $oid $description $severity \n"; + exit; +} + ########################################################################## ## Create a user. ########################################################################## sub pandora_create_user ($$$$$) { -my ($dbh, $name, $password, $is_admin, $comments) = @_; + my ($dbh, $name, $password, $is_admin, $comments) = @_; return db_insert ($dbh, 'id_user', 'INSERT INTO tusuario (id_user, fullname, password, comments, is_admin) @@ -655,7 +676,7 @@ sub param_check ($$;$) { ############################################################################## sub help_screen_line($$$){ my ($option, $parameters, $help) = @_; - print "\t$option $parameters\t$help.\n" unless ($param ne '' && $param ne $option); + print "\n\t$option $parameters : $help.\n" unless ($param ne '' && $param ne $option); } ############################################################################### @@ -3543,6 +3564,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 5); cli_create_netflow_filter(); } + elsif ($param eq '--create_snmp_trap') { + param_check($ltotal, 4); + cli_create_snmp_trap ($conf, $dbh); + } elsif ($param eq '--set_event_storm_protection') { param_check($ltotal, 1); cli_set_event_storm_protection();