diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index bd6022a72e..72abc0c503 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.731 +Version: 7.0NG.731-190130 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 41596fb0a4..22a044bb54 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731" +pandora_version="7.0NG.731-190130" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 0f3310dbe6..7c33041d65 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -42,7 +42,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.731'; -use constant AGENT_BUILD => '190129'; +use constant AGENT_BUILD => '190130'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 9afd3f7ba2..ebafb01118 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.731 -%define release 1 +%define release 190130 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 2b96e28f21..e107a9b358 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.731 -%define release 1 +%define release 190130 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 6235692d07..de175bdf2a 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.731" -PI_BUILD="190129" +PI_BUILD="190130" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 9537c6365b..faeb6db6bb 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{190129} +{190130} ViewReadme {Yes} @@ -2387,7 +2387,7 @@ Windows,BuildSeparateArchives {No} Windows,Executable -{<%AppName%>-Setup<%Ext%>} +{<%AppName%>-<%Version%>-Setup<%Ext%>} Windows,FileDescription {<%AppName%> <%Version%> Setup} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 1b1209ea17..ee7b0f8011 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.731(Build 190129)") +#define PANDORA_VERSION ("7.0NG.731(Build 190130)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index c63fac6c8c..025dd7eb33 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.731(Build 190129))" + VALUE "ProductVersion", "(7.0NG.731(Build 190130))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 9b6db9ceae..4f975eec3e 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.731 +Version: 7.0NG.731-190130 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 4de8457efe..2075088e74 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731" +pandora_version="7.0NG.731-190130" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 777c3b4e2c..96df7d128f 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC190129'; +$build_version = 'PC190130'; $pandora_version = 'v7.0NG.731'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index db050245fa..ab6599390e 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -37,6 +37,7 @@ enterprise_include_once ('include/functions_events.php'); enterprise_include_once ('include/functions_agents.php'); enterprise_include_once ('include/functions_modules.php'); enterprise_include_once ('include/functions_clusters.php'); +enterprise_include_once ('include/functions_alerts.php'); /** * Parse the "other" parameter. @@ -4514,6 +4515,45 @@ function api_get_all_alert_templates($thrash1, $thrash2, $other, $thrash3) { } } +function api_get_all_alert_commands($thrash1, $thrash2, $other, $thrash3) { + global $config; + + if (defined ('METACONSOLE')) { + return; + } + + if (!isset($other['data'][0])) + $separator = ';'; // by default + else + $separator = $other['data'][0]; + + if (!check_acl($config["id_user"], 0, "LM")) { + returnError("forbidden", "csv"); + return; + } + + $commands = db_get_all_rows_filter( + 'talert_commands', + array('id_group' => array_keys(users_get_groups(false, "LM"))) + ); + +if ($commands === false) $commands = array (); + + if ($commands !== false) { + $data['type'] = 'array'; + $data['data'] = $commands; + } + + if (!$commands) { + returnError('error_get_all_alert_commands', + __('Error getting all alert commands.')); + } + else { + returnData('csv', $data, $separator); + } +} + + /** * Get an alert tamplate, and print the result like a csv. * @@ -7841,6 +7881,108 @@ function api_set_module_group_synch($thrash1, $thrash2, $other, $thrash4) { } +/** + * Create a new alert command + * @param $id as command name (optional) + * other= (mandatory). Are the following in this order: + * + * (mandatory) + * (optional) + * (optional) + * (optional) + * ... (optional) + + example: + + *http://localhost/pandora_console/include/api.php?op=set&op2=alert_commands&id=PRUEBA1&other=command|0|Desc|1|des1|val1|des2|val2|des3|val3||val4|des5&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora +*/ +function api_set_alert_commands($id, $thrash2, $other, $trash1) { + global $config; + + $command = $other['data'][0]; + $id_group = 0; + if ($other['data'][1] != '') + $id_group = $other['data'][1]; + $description = $other['data'][2]; + $internal = $other['data'][3]; + + if (defined ('METACONSOLE')) { + return; + } + + if (!check_acl($config['id_user'], 0, "LW")){ + returnError('forbidden', 'string'); + return; + } + + $name = db_get_value ('id', 'talert_commands', 'name', $id); + $group = db_get_value ('id_grupo', 'tgrupo', 'id_grupo', $id_group); + + if ($id == '' || !$id) { + returnError('error_parameter', __('Name cannot be empty.')); + return; + } + + if ($command == '' || !$command) { + returnError('error_parameter', __('Command cannot be empty.')); + return; + } + + if ($name) { + returnError('error_parameter', __('Name already exist')); + return; + } + + if (!$group && $id_group != 0) { + returnError('error_parameter', __('Group does not exist')); + return; + } + + if ($other['type'] == 'string') { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + else if ($other['type'] == 'array') { + + $fields_descriptions = array(); + $fields_values = array(); + $max_macro_fields = $config['max_macro_fields'] * 2; + + $values = array(); + for ($i=0;$i<$max_macro_fields; $i++) { + $n = $i + 4; + + if (!$other['data'][$n]) + $other['data'][$n] = ''; + + if ($n%2==0) + $fields_descriptions[] = $other['data'][$n]; + else + $fields_values[] = $other['data'][$n]; + } + + $fields_descriptions_encode = io_json_mb_encode($fields_descriptions); + $fields_values_encode = io_json_mb_encode($fields_values); + + $values = array('id_group' => $id_group, + 'description' => $description, 'internal' => $internal, 'fields_descriptions' => $fields_descriptions_encode, + 'fields_values' => $fields_values_encode); + + $return = alerts_create_alert_command($id, $command, $values); + + $data['type'] = 'string'; + if ($return === false) { + $data['data'] = 0; + } + else { + $data['data'] = $return; + } + returnData('string', $data); + return; + } +} + + function api_set_new_event($trash1, $trash2, $other, $trash3) { $simulate = false; $time = get_system_time(); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b788ac4754..32de56ca12 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -6395,7 +6395,7 @@ function reporting_custom_graph($report, $content, $type = 'dinamic', $graphs = db_get_all_rows_field_filter ("tgraph", "id_graph", $content['id_gs']); $id_graph = $content['id_gs']; } - else if($type_report == "automatic_graph"){ + else if($type_report == "automatic_graph") { $graphs[0]["stacked"] = ''; $graphs[0]["summatory_series"] = ''; $graphs[0]["average_series"] = ''; @@ -6403,15 +6403,14 @@ function reporting_custom_graph($report, $content, $type = 'dinamic', $graphs[0]["fullscale"] = $content['style']['fullscale']; $modules = $content['id_agent_module']; - if(!$modules){ + if (is_metaconsole()) { $module_source = db_get_all_rows_sql( - "SELECT id_agent_module, id_server - FROM tgraph_source - WHERE id_graph = " . - $content['id_gs'] - ); + "SELECT id_agent_module, id_server + FROM tgraph_source + WHERE id_graph = " . + $content['id_gs']); - if(isset($module_source) && is_array($module_source)){ + if(isset($module_source) && is_array($module_source)) { $modules = array(); foreach ($module_source as $key => $value) { $modules[$key]['module'] = $value['id_agent_module']; diff --git a/pandora_console/install.php b/pandora_console/install.php index dfd67f28f7..18a2a6d9cb 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -116,7 +116,7 @@
, I<$parameters>, I<$dbh>) >> + +Create a alert command. + +=cut +######################################################################## +sub pandora_create_alert_command ($$$) { + my ($pa_config, $parameters, $dbh) = @_; + + logger($pa_config, "Creating alert command '$parameters->{'name'}'.", 10); + + my $command_id = db_process_insert($dbh, 'id', 'talert_commands', $parameters); + + return $command_id; +} + ######################################################################## =head2 C<< pandora_update_agent_address(I<$pa_config>, I<$agent_id>, I<$address>, I<$dbh>) >> diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index dc0622c98b..20bece94e6 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -62,6 +62,7 @@ our @EXPORT = qw( get_agent_module_id get_alert_template_module_id get_alert_template_name + get_command_id get_db_rows get_db_rows_limit get_db_single_row @@ -209,6 +210,16 @@ sub get_action_id ($$) { return defined ($rc) ? $rc : -1; } +######################################################################## +## Return command ID given the command name. +######################################################################## +sub get_command_id ($$) { + my ($dbh, $command_name) = @_; + + my $rc = get_db_value ($dbh, "SELECT id FROM talert_commands WHERE name = ?", safe_input($command_name)); + return defined ($rc) ? $rc : -1; +} + ######################################################################## ## Return agent ID given the agent name. ######################################################################## diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index 69aa555bd2..6b80d054d7 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -32,7 +32,7 @@ our @ISA = qw(Exporter); # version: Defines actual version of Pandora Server for this module only my $pandora_version = "7.0NG.731"; -my $pandora_build = "190129"; +my $pandora_build = "190130"; our $VERSION = $pandora_version." ".$pandora_build; our %EXPORT_TAGS = ( 'all' => [ qw() ] ); diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index 3f8b3fcda4..a56074565c 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.731 -%define release 1 +%define release 190130 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index 6ed654d7c0..77565caae9 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.731 -%define release 1 +%define release 190130 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index baec459b7a..180aaba137 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -9,7 +9,7 @@ # ********************************************************************** PI_VERSION="7.0NG.731" -PI_BUILD="190129" +PI_BUILD="190130" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index ab57e7cd08..076991b5ff 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -34,7 +34,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.731 PS190129"; +my $version = "7.0NG.731 PS190130"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index d924a9b98e..5043a1ca9a 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.731 PS190129"; +my $version = "7.0NG.731 PS190130"; # save program name for logging my $progname = basename($0); @@ -164,6 +164,8 @@ sub help_screen{ help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)'); 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('--create_alert_command', " [ \n\t ", 'Create alert command'); + help_screen_line('--get_alert_commands', "[ \n\t ]", 'Displays all alert commands'); help_screen_line('--get_alert_actions', '[ ]', 'get all alert actions'); help_screen_line('--get_alert_actions_meta', '[ ]', 'get all alert actions in nodes'); help_screen_line('--update_alert_template', " \n\t ", 'Update a field of an alert template'); @@ -3083,6 +3085,99 @@ sub cli_delete_alert_template() { exist_check($result,'alert template',$template_name); } +############################################################################## +# Add alert command. +# Related option: --create_alert_command +############################################################################## + +sub cli_create_alert_command() { + my ($command_name,$command,$group_name,$description,$internal,$fields_descriptions,$fields_values) = @ARGV[2..8]; + + print_log "[INFO] Adding command '$command_name'\n\n"; + + my $command_id = get_command_id($dbh,$command_name); + non_exist_check($command_id,'command',$command_name); + + my $id_group; + + if (! $group_name || $group_name eq "All") { + $id_group = 0; + } + else { + $id_group = get_group_id($dbh,$group_name); + exist_check($id_group,'group',$group_name); + } + + my %parameters; + + $parameters{'name'} = $command_name; + $parameters{'command'} = $command; + $parameters{'id_group'} = $id_group; + $parameters{'description'} = $description; + $parameters{'internal'} = $internal; + $parameters{'fields_descriptions'} = $fields_descriptions; + $parameters{'fields_values'} = $fields_values; + + pandora_create_alert_command ($conf, \%parameters, $dbh); +} + +############################################################################## +# Show all the alert commands (without parameters) or the alert commands with a filter parameters +# Related option: --get_alert_commands +############################################################################## + +sub cli_get_alert_commands() { + my ($command_name, $command, $group_name, $description, $internal) = @ARGV[2..6]; + + my $id_group; + my $condition = ' 1=1 '; + + if($command_name ne '') { + my $name = safe_input ($command_name); + $condition .= " AND name LIKE '%$name%' "; + } + + if($command ne '') { + $condition .= " AND command LIKE '%$command%' "; + } + + if($group_name ne '') { + $id_group = get_group_id($dbh, $group_name); + exist_check($id_group,'group',$group_name); + + $condition .= " AND id_group = $id_group "; + } + + if($description ne '') { + $condition .= " AND description LIKE '%$description%' "; + } + + if($internal ne '') { + $condition .= " AND internal = $internal "; + } + + my @alert_command = get_db_rows ($dbh, "SELECT * FROM talert_commands WHERE $condition"); + + if(scalar(@alert_command) == 0) { + print_log "[INFO] No commands found\n\n"; + exit; + } + + my $head_print = 0; + foreach my $commands (@alert_command) { + + if($head_print == 0) { + $head_print = 1; + print "id_command, command_name\n"; + } + print $commands->{'id'}.",".safe_output($commands->{'name'})."\n"; + } + + if($head_print == 0) { + print_log "[INFO] No commands found\n\n"; + } +} + ############################################################################## # Get alert actions. # Related option: --get_alert_actions @@ -6019,9 +6114,17 @@ sub pandora_manage_main ($$$) { cli_create_alert_template(); } elsif ($param eq '--delete_alert_template') { - param_check($ltotal, 1); + param_check($ltotal, 7); cli_delete_alert_template(); } + elsif ($param eq '--create_alert_command') { + param_check($ltotal, 7, 2); + cli_create_alert_command(); + } + elsif ($param eq '--get_alert_commands') { + param_check($ltotal, 5, 5); + cli_get_alert_commands(); + } elsif ($param eq '--get_alert_actions') { param_check($ltotal, 3, 3); cli_get_alert_actions();