diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 236064b4e3..041c5ed98a 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.764-220927 +Version: 7.0NG.764-220928 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 9f086f5251..357f109d1b 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.764-220927" +pandora_version="7.0NG.764-220928" 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/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index a0e473063e..62e785b74e 100644 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -165,9 +165,15 @@ remote_config 0 # should consider changing the temporal directory, since /tmp is world writable. xml_buffer 1 -# Minimum available bytes in the temporal directory to enable the XML buffer +# Minimum available megabytes in the temporal directory to enable the XML buffer temporal_min_size 1024 +# Maximum size (in megabytes) allowed for the XML buffer. +temporal_max_size 1024 + +# Maximum number of files allowed for the XML buffer. +temporal_max_files 1024 + # Agent mode: Learn (default), No-learn, Autodisable # agent_mode autodisable diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 87cfd2c8cf..6e878f0d73 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1015,7 +1015,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.764'; -use constant AGENT_BUILD => '220927'; +use constant AGENT_BUILD => '220928'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; @@ -1145,7 +1145,9 @@ my %DefaultConf = ( 'secondary_server_opts' => '', 'secondary_temporal' => '/var/spool/pandora', 'autotime' => 0, - 'temporal_min_size' => 1, + 'temporal_min_size' => 1024, + 'temporal_max_files' => 1024, + 'temporal_max_size' => 1024, 'timezone_offset' => 0, 'pandora_exec' => 'pandora_agent_exec', 'agent_threads' => 1, @@ -2110,13 +2112,13 @@ sub send_xml_file ($) { swap_servers(); # Secondary buffer. - if ($rc_sec != 0 && $Conf{'xml_buffer'} == 1 && temporal_freedisk () > $Conf{'temporal_min_size'}) { + if ($rc_sec != 0 && write_to_buffer($Conf{'secondary_temporal'}) == 1) { copy($file, $Conf{'secondary_temporal'}) || die("Error copying file $file to " . $Conf{'secondary_temporal'} . ": $!"); } } # Primary buffer. - if ($rc == 0 || $Conf{'xml_buffer'} == 0 || temporal_freedisk () <= $Conf{'temporal_min_size'}) { + if ($rc == 0 || write_to_buffer($Conf{'temporal'}) == 0) { if ($Conf{'debug'} eq '1') { rename($file, $file . "sent"); } else { @@ -3761,20 +3763,45 @@ sub kill_signal_handler (){ } ################################################################################ -# Get the free disk space in the temporal directory (in bytes). +# Get the free disk space in the temporal directory (in megabytes). ################################################################################ -sub temporal_freedisk () { +sub temporal_freedisk { + my ($temporal) = @_; # Call df return 0 unless defined (DF_CMDS->{$OS}); - my $cmd = DF_CMDS->{$OS} . ' ' . $Conf{'temporal'} . ' | awk \'NR > 1 {print $4}\''; + my $cmd = DF_CMDS->{$OS} . ' ' . $temporal . ' | awk \'NR > 1 {print $4}\''; my $temporal_freedisk = `$cmd`; # Check for errors return 0 unless ($? eq 0); - # Convert to bytes - return 1024 * int ($temporal_freedisk); + # Convert from KB to MB. + return $temporal_freedisk / 1024; +} + +################################################################################ +# Return the number of data files in the temporal directory and their total +# size (in megabytes). +################################################################################ +sub temporal_stats { + my ($temporal) = @_; + + my $file_count = 0; + my $file_size = 0; + opendir(my $dir, $temporal) or die($!); + while (my $f = readdir($dir)) { + if ($f =~ m/.data$/ || $f =~ m/.datasent$/) { + $file_count += 1; + $file_size += (stat $temporal . '/' . $f)[7]; + } + } + closedir($dir); + + # Convert from B to MB. + $file_size /= 1048576; + + return ($file_count, $file_size); } ################################################################################ @@ -3960,6 +3987,27 @@ sub get_ehkey { return ''; } +################################################################################ +# Return 1 if XML files should be written to the buffer. 0 otherwise. +################################################################################ +sub write_to_buffer { + my ($temporal) = @_; + + # The XML buffer is disabled. + return 0 if ($Conf{'xml_buffer'} == 0); + + # Check available disk space. + return 0 if ($Conf{'temporal_min_size'} != 0 && temporal_freedisk($temporal) < $Conf{'temporal_min_size'}); + + # Check buffer file count and size limits. + my ($file_count, $file_size) = temporal_stats($temporal); + return 0 if ($Conf{'temporal_max_files'} != 0 && $file_count > $Conf{'temporal_max_files'}); + return 0 if ($Conf{'temporal_max_size'} != 0 && $file_size > $Conf{'temporal_max_size'}); + + # It's OK to write to the buffer. + return 1; +} + ################################################################################ # Main. ################################################################################ diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 97bcbf4a2d..791d552104 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.764 -%define release 220927 +%define release 220928 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 e0096d54cc..42c0fa606d 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.764 -%define release 220927 +%define release 220928 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 0c07e243f0..5e2fb23f0e 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.764" -PI_BUILD="220927" +PI_BUILD="220928" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index 549b0e7ac9..200a31d57d 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -55,9 +55,15 @@ address auto # or setting a fixed IP address, like for example: #address 192.168.36.73 -# This limits operation if temporal dir has not enough free disk. +# This limits operation if temporal dir has not enough free disk (in megabytes). #temporal_min_size 1024 +# Maximum size (in megabytes) allowed for the XML buffer. +temporal_max_size 1024 + +# Maximum number of files allowed for the XML buffer. +temporal_max_files 1024 + # Delay start execution X second before start to monitoring nothing #startup_delay 30 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index ebcb1fe62d..acd552c566 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{220927} +{220928} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index a2cc6c75fc..f79828bb02 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.764 Build 220927") +#define PANDORA_VERSION ("7.0NG.764 Build 220928") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index f047eb17ff..f369935aac 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -1696,7 +1696,7 @@ Pandora_Windows_Service::checkConfig (string file) { int Pandora_Windows_Service::sendXml (Pandora_Module_List *modules, string extra /* = ""*/) { - int rc = 0, rc_sec = 0, xml_buffer; + int rc = 0, rc_sec = 0, xml_buffer; string data_xml; string xml_filename, random_integer; string tmp_filename, tmp_filepath; @@ -1705,12 +1705,10 @@ Pandora_Windows_Service::sendXml (Pandora_Module_List *modules, string extra /* string ehorus_conf, eh_key; static HANDLE mutex = 0; ULARGE_INTEGER free_bytes; - double min_free_bytes = 0; Pandora_Agent_Conf *conf = NULL; FILE *conf_fh = NULL; conf = this->getConf (); - min_free_bytes = 1024 * atoi (conf->getValue ("temporal_min_size").c_str ()); xml_buffer = atoi (conf->getValue ("xml_buffer").c_str ()); if (mutex == 0) { @@ -1814,14 +1812,14 @@ Pandora_Windows_Service::sendXml (Pandora_Module_List *modules, string extra /* rc_sec = this->copyToSecondary (tmp_filename, false); /* Secondary buffer. */ - if (rc_sec != 0 && xml_buffer == 1 && (GetDiskFreeSpaceEx (conf->getValue ("secondary_temporal").c_str (), &free_bytes, NULL, NULL) != 0 && free_bytes.QuadPart >= min_free_bytes)) { + if (rc_sec != 0 && this->writeToBuffer(conf->getValue ("secondary_temporal").c_str ())) { secondary_filepath = conf->getValue ("secondary_temporal") + "\\" + tmp_filename; CopyFile (tmp_filepath.c_str(), secondary_filepath.c_str(), false); } } /* Primary buffer. Delete the file if successfully copied, buffer disabled or not enough space available. */ - if (rc == 0 || xml_buffer == 0 || (GetDiskFreeSpaceEx (tmp_filepath.c_str (), &free_bytes, NULL, NULL) != 0 && free_bytes.QuadPart < min_free_bytes)) { + if (rc == 0 || !writeToBuffer(conf->getValue ("temporal").c_str ())) { /* Rename the file if debug mode is enabled*/ if (getPandoraDebug ()) { string tmp_filepath_sent = tmp_filepath; @@ -2218,3 +2216,60 @@ Pandora_Windows_Service::generateAgentName () { sha256(data.str().c_str(), digest); return std::string(digest); } + +bool +Pandora_Windows_Service::writeToBuffer (string temporal) { + int xml_buffer; + long int temporal_max_files; + double temporal_min_size, temporal_max_size; + string dir, file_name; + ULARGE_INTEGER free_bytes; + Pandora_Agent_Conf *conf = NULL; + + conf = this->getConf (); + + dir = temporal; + if (dir[dir.length () - 1] != '\\') { + dir += "\\"; + } + file_name = dir + "*.data"; + + // Is the XML buffer disabled? + xml_buffer = atoi (conf->getValue ("xml_buffer").c_str ()); + if (xml_buffer == 0) { + return false; + } + + // Check available disk space. + temporal_min_size = atoi (conf->getValue ("temporal_min_size").c_str ()); + if (GetDiskFreeSpaceEx (dir.c_str (), &free_bytes, NULL, NULL) && (free_bytes.QuadPart / 1048576) < temporal_min_size) { // Convert free_bytes.QuadPart from B to MB. + pandoraLog ("[writeToBuffer] Disk full."); + return false; + } + + // Check buffer file count and size limits. + temporal_max_size = atoi (conf->getValue ("temporal_max_size").c_str ()); + temporal_max_files = atol (conf->getValue ("temporal_max_files").c_str ()); + if (temporal_max_size != 0 || temporal_max_files != 0) { + long int file_count = 0; + ULONGLONG file_size = 0; + HANDLE hFind; + WIN32_FIND_DATA FindFileData; + if ((hFind = FindFirstFile(file_name.c_str(), &FindFileData)) != INVALID_HANDLE_VALUE) { + do { + file_count += 1; + file_size += (FindFileData.nFileSizeHigh * (MAXDWORD + 1)) + FindFileData.nFileSizeLow; + } while (FindNextFile(hFind, &FindFileData)); + FindClose(hFind); + } + + file_size /= 1048576; // Convert from B to MB. + if ((temporal_max_size != 0 && file_size > temporal_max_size) || + (temporal_max_files != 0 && file_count > temporal_max_files)) { + pandoraLog ("[writeToBuffer] Too many files or buffer full."); + return false; + } + } + + return true; +} diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index 39ad2e8e44..f863ae2c27 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -124,6 +124,7 @@ namespace Pandora { long getInterval (); long getIntensiveInterval (); string generateAgentName (); + bool writeToBuffer (string temporal); }; } diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 6aaaf1203f..e59fef9655 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.764(Build 220927))" + VALUE "ProductVersion", "(7.0NG.764(Build 220928))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index d45bd6a8f5..7f85b72cfb 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.764-220927 +Version: 7.0NG.764-220928 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 1e4f6092e6..834fb47321 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.764-220927" +pandora_version="7.0NG.764-220928" package_pear=0 package_pandora=1 diff --git a/pandora_console/extras/mr/57.sql b/pandora_console/extras/mr/57.sql index 131a02ce89..5b3f4d9648 100644 --- a/pandora_console/extras/mr/57.sql +++ b/pandora_console/extras/mr/57.sql @@ -9,6 +9,16 @@ ALTER TABLE `tusuario` ADD COLUMN `allowed_ip_list` TEXT; SET @id_config := (SELECT id_config FROM tconfig WHERE `token` = 'metaconsole_node_id' AND `value` IS NOT NULL ORDER BY id_config DESC LIMIT 1); DELETE FROM tconfig WHERE `token` = 'metaconsole_node_id' AND (id_config < @id_config OR `value` IS NULL); +ALTER TABLE `tpolicies` ADD COLUMN `apply_to_secondary_groups` TINYINT NOT NULL DEFAULT 0; + +INSERT INTO `talert_commands` (`name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES ('Send report by e-mail','Internal type','This command allows you to send a report by email.',1,'[\"Report\",\"e-mail address\",\"Subject\",\"Text\",\"Report type\",\"\",\"\",\"\",\"\",\"\"]','[\"_reports_\",\"\",\"\",\"_html_editor_\",\"xml,XML;pdf,PDF;json,JSON;csv,CSV\",\"\",\"\",\"\",\"\",\"\"]'); +SET @send_report_command_id := LAST_INSERT_ID(); +INSERT INTO `talert_actions` (`name`, `id_alert_command`, `field1`, `field2`, `field3`, `field4`, `field5`, `field6`, `field7`, `field8`, `field9`, `field10`, `id_group`, `action_threshold`, `field1_recovery`, `field2_recovery`, `field3_recovery`, `field4_recovery`, `field5_recovery`, `field6_recovery`, `field7_recovery`, `field8_recovery`, `field9_recovery`, `field10_recovery`) VALUES ('Send Report by e-mail',@send_report_command_id,'','yourmail@domain.es','','<div style="background-color: #eaf0f6; font-family: Arial, Helvetica, sans-serif; padding: 30px; margin: 0;"><table style="max-width: 560px; background-color: white; border-radius: 10px; padding: 10px 20px 40px;" cellspacing="0" cellpadding="0" align="center"><thead><tr><td style="padding: 0px 0px 5px;"><a href="https://pandorafms.com/en/" target="_blank"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Pandora-FMS.png" width="206px"></a></td><td style="padding: 0px 0px 5px;"><p style="text-align: right; color: #223549; font-weight: bold; line-height: 36px; padding: 0px; font-size: 12px;">Automatic alert system</p></td></tr><tr><td style="padding: 0px 0px 5px;" colspan="2"><hr style="border: 1px solid #f5f5f5; width: 100%; margin: 0px;"></td></tr></thead><tbody><tr><td colspan="2"><img onerror="this.style.display=&quot;none&quot;;" src="_statusimage_" style="display: block; margin-left: auto; margin-right: auto; width: 105px; margin-top: 20px; padding: 0px;" width="105px"></td></tr><tr><td colspan="2"><p style="font-size: 24px; text-align: center; color: #223549; padding: 0px 10%; line-height: 34px; margin: 20px 0px;">We have bad news for you, something is on <span style="text-transform: uppercase; font-weight: 800;">_modulestatus_</span> status!</p><div><!--[if mso]><v:rect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="#" style="height:33px;v-text-anchor:middle;width:100px;" stroke="f" fillcolor="#D84A38"><w:anchorlock/><center><![endif]--><a style="background-color: #223549; border: none; color: white; padding: 15px 30px; text-align: center; text-decoration: none; display: block; font-size: 16px; margin-left: auto; margin-right: auto; border-radius: 100px; max-width: 50%; margin-top: 0px; font-weight: bold;" href="_homeurl_">Go to Pandora FMS Console</a><!--[if mso]></center></v:rect><![endif]--></div></td></tr><tr><td colspan="2"><div style="background-color: #f6f6f6; border-radius: 10px; padding: 10px 20px; margin-top: 40px;"><p style="font-size: 18px; line-height: 30px; color: #223549;">Monitoring details</p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Data: <span style="font-weight: 400!important;">_data_ <em>(_modulestatus_)</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Agent: <span style="font-weight: 400!important;">_agent_ <em>_address_</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Module: <span style="font-weight: 400!important;">_module_ <em>_moduledescription_</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Timestamp: <span style="font-weight: 400!important;">_timestamp_</span></p></div></td></tr><tr><td style="padding: 20px 0px;" colspan="2"><p style="font-size: 18px; line-height: 30px; color: #223549;">Report details</p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Generated:&nbsp;<span style="font-weight: 400!important;">_report_generated_date_<em><br></em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Report date:&nbsp;<span style="font-weight: 400!important;">_report_date_<em><br></em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Description:&nbsp;<span style="font-weight: 400!important;">_report_description_</span></p></td></tr></tbody></table><div style="text-align: center; margin-top: 10px;"><p style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;"><a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/en/contact/">Contact Us</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/community/forums/forum/english/">Support</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/manual/en/start">Docs</a></p></div></div>','','','','','','',0,0,'','','','<div style="background-color: #eaf0f6; font-family: Arial, Helvetica, sans-serif; padding: 30px; margin: 0;"> <table style="max-width: 560px; background-color: white; border-radius: 10px; padding: 10px 20px 40px;" cellspacing="0" cellpadding="0" align="center"> <thead> <tr> <td style="padding: 0px 0px 5px;"><a href="https://pandorafms.com/en/" target="_blank"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Pandora-FMS.png" width="206px"></a></td> <td style="padding: 0px 0px 5px;"> <p style="text-align: right; color: #223549; font-weight: bold; line-height: 36px; padding: 0px; font-size: 12px;">Automatic alert system</p> </td> </tr> <tr> <td style="padding: 0px 0px 5px;" colspan="2"><hr style="border: 1px solid #f5f5f5; width: 100%; margin: 0px;"></td> </tr> </thead> <tbody> <tr> <td colspan="2"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Good-news.png" style="display: block; margin-left: auto; margin-right: auto; width: 105px; margin-top: 20px; padding: 0px;" width="105px"></td> </tr> <tr> <td colspan="2"> <p style="font-size: 24px; text-align: center; color: #223549; padding: 0px 10%; line-height: 34px; margin: 20px 0px;">We have good news for you, alert has been <span style="text-transform: uppercase; font-weight: 800;">recovered</span></p> <div><!--[if mso]><v:rect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="#" style="height:33px;v-text-anchor:middle;width:100px;" stroke="f" fillcolor="#D84A38"><w:anchorlock/><center><![endif]--><a style="background-color: #223549; border: none; color: white; padding: 15px 30px; text-align: center; text-decoration: none; display: block; font-size: 16px; margin-left: auto; margin-right: auto; border-radius: 100px; max-width: 50%; margin-top: 0px; font-weight: bold;" href="_homeurl_">Go to Pandora FMS Console</a><!--[if mso]></center></v:rect><![endif]--></div> </td> </tr> <tr> <td colspan="2"> <div style="background-color: #f6f6f6; border-radius: 10px; padding: 10px 20px; margin-top: 40px;"> <p style="font-size: 18px; line-height: 30px; color: #223549;">Monitoring details</p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Data: <span style="font-weight: 400!important;">_data_ <em>(_modulestatus_)</em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Agent: <span style="font-weight: 400!important;">_agent_ <em>_address_</em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Module: <span style="font-weight: 400!important;">_module_ <em>_moduledescription_</em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Timestamp: <span style="font-weight: 400!important;">_timestamp_</span></p> </div> </td> </tr> <tr> <td style="padding: 20px 0px;" colspan="2"> <p style="font-size: 18px; line-height: 30px; color: #223549;">Report details</p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Generated:&nbsp;<span style="font-weight: 400!important;">_report_generated_date_<em><br></em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Report date:&nbsp;<span style="font-weight: 400!important;">_report_date_<em><br></em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Description:&nbsp;<span style="font-weight: 400!important;">_report_description_</span></p> </td> </tr> </tbody> </table> <div style="text-align: center; margin-top: 10px;"> <p style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;"><a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/en/contact/">Contact Us</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/community/forums/forum/english/">Support</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/manual/en/start">Docs</a></p> </div> </div>','','','','','',''); + +INSERT INTO `talert_commands` (`name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES ('Send report by e-mail (from template)','Internal type','This command allows you to send a report generated from a template by email.',1,'[\"Template\",\"Regexp agent filter\",\"e-mail address\",\"Subject\",\"Text\",\"Report type\",\"\",\"\",\"\",\"\"]','[\"_report_templates_\",\"\",\"\",\"\",\"_html_editor_\",\"xml,XML;pdf,PDF;json,JSON;csv,CSV\",\"\",\"\",\"\",\"\"]'); +SET @send_report_by_temp_command_id := LAST_INSERT_ID(); +INSERT INTO `talert_actions` (`name`, `id_alert_command`, `field1`, `field2`, `field3`, `field4`, `field5`, `field6`, `field7`, `field8`, `field9`, `field10`, `id_group`, `action_threshold`, `field1_recovery`, `field2_recovery`, `field3_recovery`, `field4_recovery`, `field5_recovery`, `field6_recovery`, `field7_recovery`, `field8_recovery`, `field9_recovery`, `field10_recovery`) VALUES ('Send Report by e-mail (from template)',@send_report_by_temp_command_id,'','','yourmail@domain.es','','<div style="background-color: #eaf0f6; font-family: Arial, Helvetica, sans-serif; padding: 30px; margin: 0;"><table style="max-width: 560px; background-color: white; border-radius: 10px; padding: 10px 20px 40px;" cellspacing="0" cellpadding="0" align="center"><thead><tr><td style="padding: 0px 0px 5px;"><a href="https://pandorafms.com/en/" target="_blank"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Pandora-FMS.png" width="206px"></a></td><td style="padding: 0px 0px 5px;"><p style="text-align: right; color: #223549; font-weight: bold; line-height: 36px; padding: 0px; font-size: 12px;">Automatic alert system</p></td></tr><tr><td style="padding: 0px 0px 5px;" colspan="2"><hr style="border: 1px solid #f5f5f5; width: 100%; margin: 0px;"></td></tr></thead><tbody><tr><td colspan="2"><img onerror="this.style.display=&quot;none&quot;;" src="_statusimage_" style="display: block; margin-left: auto; margin-right: auto; width: 105px; margin-top: 20px; padding: 0px;" width="105px"></td></tr><tr><td colspan="2"><p style="font-size: 24px; text-align: center; color: #223549; padding: 0px 10%; line-height: 34px; margin: 20px 0px;">We have bad news for you, something is on <span style="text-transform: uppercase; font-weight: 800;">_modulestatus_</span> status!</p><div><!--[if mso]><v:rect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="#" style="height:33px;v-text-anchor:middle;width:100px;" stroke="f" fillcolor="#D84A38"><w:anchorlock/><center><![endif]--><a style="background-color: #223549; border: none; color: white; padding: 15px 30px; text-align: center; text-decoration: none; display: block; font-size: 16px; margin-left: auto; margin-right: auto; border-radius: 100px; max-width: 50%; margin-top: 0px; font-weight: bold;" href="_homeurl_">Go to Pandora FMS Console</a><!--[if mso]></center></v:rect><![endif]--></div></td></tr><tr><td colspan="2"><div style="background-color: #f6f6f6; border-radius: 10px; padding: 10px 20px; margin-top: 40px;"><p style="font-size: 18px; line-height: 30px; color: #223549;">Monitoring details</p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Data: <span style="font-weight: 400!important;">_data_ <em>(_modulestatus_)</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Agent: <span style="font-weight: 400!important;">_agent_ <em>_address_</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Module: <span style="font-weight: 400!important;">_module_ <em>_moduledescription_</em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Timestamp: <span style="font-weight: 400!important;">_timestamp_</span></p></div></td></tr><tr><td style="padding: 20px 0px;" colspan="2"><p style="font-size: 18px; line-height: 30px; color: #223549;">Report details</p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Generated:&nbsp;<span style="font-weight: 400!important;">_report_generated_date_<em><br></em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Report date:&nbsp;<span style="font-weight: 400!important;">_report_date_<em><br></em></span></p><p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Description:&nbsp;<span style="font-weight: 400!important;">_report_description_</span></p></td></tr></tbody></table><div style="text-align: center; margin-top: 10px;"><p style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;"><a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/en/contact/">Contact Us</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/community/forums/forum/english/">Support</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/manual/en/start">Docs</a></p></div></div>','','','','','',0,0,'','','','','<div style="background-color: #eaf0f6; font-family: Arial, Helvetica, sans-serif; padding: 30px; margin: 0;"> <table style="max-width: 560px; background-color: white; border-radius: 10px; padding: 10px 20px 40px;" cellspacing="0" cellpadding="0" align="center"> <thead> <tr> <td style="padding: 0px 0px 5px;"><a href="https://pandorafms.com/en/" target="_blank"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Pandora-FMS.png" width="206px"></a></td> <td style="padding: 0px 0px 5px;"> <p style="text-align: right; color: #223549; font-weight: bold; line-height: 36px; padding: 0px; font-size: 12px;">Automatic alert system</p> </td> </tr> <tr> <td style="padding: 0px 0px 5px;" colspan="2"><hr style="border: 1px solid #f5f5f5; width: 100%; margin: 0px;"></td> </tr> </thead> <tbody> <tr> <td colspan="2"><img src="https://pandorafms.com/wp-content/uploads/2022/03/System-email-Good-news.png" style="display: block; margin-left: auto; margin-right: auto; width: 105px; margin-top: 20px; padding: 0px;" width="105px"></td> </tr> <tr> <td colspan="2"> <p style="font-size: 24px; text-align: center; color: #223549; padding: 0px 10%; line-height: 34px; margin: 20px 0px;">We have good news for you, alert has been <span style="text-transform: uppercase; font-weight: 800;">recovered</span></p> <div><!--[if mso]><v:rect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="#" style="height:33px;v-text-anchor:middle;width:100px;" stroke="f" fillcolor="#D84A38"><w:anchorlock/><center><![endif]--><a style="background-color: #223549; border: none; color: white; padding: 15px 30px; text-align: center; text-decoration: none; display: block; font-size: 16px; margin-left: auto; margin-right: auto; border-radius: 100px; max-width: 50%; margin-top: 0px; font-weight: bold;" href="_homeurl_">Go to Pandora FMS Console</a><!--[if mso]></center></v:rect><![endif]--></div> </td> </tr> <tr> <td colspan="2"> <div style="background-color: #f6f6f6; border-radius: 10px; padding: 10px 20px; margin-top: 40px;"> <p style="font-size: 18px; line-height: 30px; color: #223549;">Monitoring details</p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Data: <span style="font-weight: 400!important;">_data_ <em>(_modulestatus_)</em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Agent: <span style="font-weight: 400!important;">_agent_ <em>_address_</em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Module: <span style="font-weight: 400!important;">_module_ <em>_moduledescription_</em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Timestamp: <span style="font-weight: 400!important;">_timestamp_</span></p> </div> </td> </tr> <tr> <td style="padding: 20px 0px;" colspan="2"> <p style="font-size: 18px; line-height: 30px; color: #223549;">Report details</p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Generated:&nbsp;<span style="font-weight: 400!important;">_report_generated_date_<em><br></em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Report date:&nbsp;<span style="font-weight: 400!important;">_report_date_<em><br></em></span></p> <p style="font-size: 15px; color: #333333; font-weight: 800; line-height: 15px;">Description:&nbsp;<span style="font-weight: 400!important;">_report_description_</span></p> </td> </tr> </tbody> </table> <div style="text-align: center; margin-top: 10px;"> <p style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;"><a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/en/contact/">Contact Us</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/community/forums/forum/english/">Support</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style="font-size: 12px; text-decoration: none; font-weight: 400; color: #777;" href="https://pandorafms.com/manual/en/start">Docs</a></p> </div> </div>','','','','',''); + ALTER TABLE `tmodule_group` MODIFY COLUMN `id_mg` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT; -COMMIT; \ No newline at end of file +COMMIT; diff --git a/pandora_console/extras/mr/58.sql b/pandora_console/extras/mr/58.sql new file mode 100644 index 0000000000..395f30f861 --- /dev/null +++ b/pandora_console/extras/mr/58.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + + + +COMMIT; diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index a10e32aeff..26dc279cb9 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -15,6 +15,7 @@ global $config; require_once $config['homedir'].'/include/functions_alerts.php'; +require_once $config['homedir'].'/include/functions_reports.php'; enterprise_include_once('meta/include/functions_alerts_meta.php'); check_login(); @@ -284,13 +285,13 @@ if (is_ajax()) { $ffield .= '
'.html_print_switch( [ 'name' => 'field'.$i.'_value[]', - 'value' => '', + 'value' => '' ] ).'
'; $rfield .= '
'.html_print_switch( [ 'name' => 'field'.$i.'_recovery_value[]', - 'value' => '', + 'value' => '' ] ).'
'; @@ -349,9 +350,94 @@ if (is_ajax()) { ); } else { $fields_value_select = []; - $fv = explode(';', $field_value); + $force_print_select = false; - if (count($fv) > 1) { + // Exception for dynamically filled select boxes. + if (preg_match('/^_reports_$/i', $field_value)) { + // Filter normal and metaconsole reports. + if (is_metaconsole() === true) { + $filter['metaconsole'] = 1; + } else { + $filter['metaconsole'] = 0; + } + + $own_info = get_user_info($config['id_user']); + if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'RM') || check_acl($config['id_user'], 0, 'RR')) { + $return_all_group = true; + } else { + $return_all_group = false; + } + + if (is_user_admin($config['id_user']) === false) { + $filter[] = sprintf( + 'private = 0 OR (private = 1 AND id_user = "%s")', + $config['id_user'] + ); + } + + $reports = reports_get_reports( + $filter, + [ + 'name', + 'id_report' + ], + $return_all_group, + 'RR' + ); + + $fv = array_map( + function ($report) { + return $report['id_report'].','.$report['name']; + }, + $reports + ); + + $force_print_select = true; + } else if (preg_match('/^_report_templates_$/i', $field_value)) { + // Filter normal and metaconsole reports. + if (is_metaconsole() === true) { + $filter['metaconsole'] = 1; + } else { + $filter['metaconsole'] = 0; + } + + $own_info = get_user_info($config['id_user']); + if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'RM') || check_acl($config['id_user'], 0, 'RR')) { + $return_all_group = true; + } else { + $return_all_group = false; + } + + if (is_user_admin($config['id_user']) === false) { + $filter[] = sprintf( + 'private = 0 OR (private = 1 AND id_user = "%s")', + $config['id_user'] + ); + } + + $templates = reports_get_report_templates( + $filter, + [ + 'name', + 'id_report' + ], + $return_all_group, + 'RR' + ); + + $fv = array_map( + function ($template) { + return $template['id_report'].','.$template['name']; + }, + $templates + ); + + $force_print_select = true; + } else { + $fv = explode(';', $field_value); + } + + if (count($fv) > 1 || $force_print_select === true) { if (!empty($fv)) { foreach ($fv as $fv_option) { $fv_option = explode(',', $fv_option); diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 2bcdbf7af4..5b7262be83 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -647,7 +647,12 @@ if ($get_agent_alerts_datatable === true) { $order = get_datatable_order(true); $url = get_parameter('url', '#'); - $free_search_alert = $filter_alert['free_search_alert']; + if (empty($filter_alert['free_search']) === false) { + $free_search_alert = $filter_alert['free_search']; + } else { + $free_search_alert = $filter_alert['free_search_alert']; + } + $idGroup = $filter_alert['ag_group']; $tag_filter = $filter_alert['tag_filter']; $action_filter = $filter_alert['action']; @@ -676,7 +681,7 @@ if ($get_agent_alerts_datatable === true) { $selectLastFiredDown = false; switch ($sortField) { - case 'module': + case 'agent_module_name': switch ($sort) { case 'asc': $selectModuleasc = $selected; @@ -696,7 +701,7 @@ if ($get_agent_alerts_datatable === true) { } break; - case 'template': + case 'template_name': switch ($sort) { case 'asc': $selectTemplateasc = $selected; @@ -736,7 +741,7 @@ if ($get_agent_alerts_datatable === true) { } break; - case 'agent': + case 'agent_name': switch ($sort) { case 'asc': $selectLastFiredasc = $selected; @@ -857,7 +862,7 @@ if ($get_agent_alerts_datatable === true) { if (is_metaconsole() === true) { include_once $config['homedir'].'/enterprise/meta/include/functions_alerts_meta.php'; if ($idAgent != 0) { - $alerts['alerts_simple'] = alerts_meta_get_alerts($agents, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter); + $alerts['alerts_simple'] = alerts_meta_get_alerts($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter); $countAlertsSimple = alerts_meta_get_alerts($agents, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter); } else { @@ -865,7 +870,7 @@ if ($get_agent_alerts_datatable === true) { users_get_groups($config['id_user'], 'AR', false) ); - $alerts['alerts_simple'] = alerts_meta_get_group_alerts($id_groups, $filter_alert, $options_simple, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter); + $alerts['alerts_simple'] = alerts_meta_get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, false, $strict_user, $tag_filter, $action_filter); $countAlertsSimple = alerts_meta_get_group_alerts($id_groups, $filter_alert, false, $whereAlertSimple, false, false, $idGroup, true, $strict_user, $tag_filter, $action_filter); } @@ -885,12 +890,60 @@ if ($get_agent_alerts_datatable === true) { } } + // Order and pagination metacosole. + if (is_metaconsole() === true) { + + + /** + * Auxiliar Ordenation function + * + * @param string $sort Direction of sort. + * @param string $sortField Field for perform the sorting. + */ + function arrayOutputSorting($sort, $sortField) + { + return function ($a, $b) use ($sort, $sortField) { + if ($sort === 'asc') { + if (is_string($a[$sortField]) === true) { + return strnatcasecmp($a[$sortField], $b[$sortField]); + } else { + return ($a[$sortField] - $b[$sortField]); + } + } else { + if (is_string($a[$sortField]) === true) { + return strnatcasecmp($b[$sortField], $a[$sortField]); + } else { + return ($a[$sortField] + $b[$sortField]); + } + } + }; + } + + + // Status order. + if ($sortField === 'status') { + foreach ($alerts['alerts_simple'] as $i => $alert) { + if ($alert['times_fired'] > 0) { + $alerts['alerts_simple'][$i]['status'] = '3'; + } else if ($alert['disabled'] > 0) { + $alerts['alerts_simple'][$i]['status'] = '1'; + } else { + $alerts['alerts_simple'][$i]['status'] = '2'; + } + } + } + + usort($alerts['alerts_simple'], arrayOutputSorting($sort, $sortField)); + $alerts['alerts_simple'] = array_slice($alerts['alerts_simple'], $start, $length); + } + $data = []; if ($alerts['alerts_simple']) { foreach ($alerts['alerts_simple'] as $alert) { $data[] = ui_format_alert_row($alert, true, $url, 'font-size: 7pt;'); } + $data = array_reduce( $data, function ($carry, $row) { @@ -902,11 +955,11 @@ if ($get_agent_alerts_datatable === true) { $tmp->policy = $row[0]; $tmp->standby = $row[1]; $tmp->force = $row[2]; - $tmp->agent = $row[3]; - $tmp->module = $row[4]; - $tmp->template = $row[5]; + $tmp->agent_name = $row[3]; + $tmp->agent_module_name = $row[4]; + $tmp->template_name = $row[5]; $tmp->action = $row[6]; - $tmp->lastFired = $row[7]; + $tmp->last_fired = $row[7]; $tmp->status = $row[8]; $tmp->validate = $row[9]; @@ -916,6 +969,7 @@ if ($get_agent_alerts_datatable === true) { ); } + // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( [ diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index b06f18a17b..181574aadc 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,7 +20,7 @@ /** * Pandora build version and version */ -$build_version = 'PC220927'; +$build_version = 'PC220928'; $pandora_version = 'v7.0NG.764'; // 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 d711432ef9..3bf6845eae 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -46,12 +46,18 @@ require_once $config['homedir'].'/include/functions_planned_downtimes.php'; require_once $config['homedir'].'/include/functions_db.php'; require_once $config['homedir'].'/include/functions_event_responses.php'; require_once $config['homedir'].'/include/functions_tactical.php'; +require_once $config['homedir'].'/include/functions_reporting.php'; +require_once $config['homedir'].'/include/functions_reporting_xml.php'; +require_once $config['homedir'].'/include/functions_reports.php'; enterprise_include_once('include/functions_local_components.php'); 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'); +enterprise_include_once('include/functions_reporting_pdf.php'); +enterprise_include_once('include/functions_reporting_csv.php'); +enterprise_include_once('include/functions_cron.php'); // Clases. use PandoraFMS\Agent; @@ -17542,3 +17548,302 @@ function api_set_enable_disable_discovery_task($id_task, $thrash2, $other) } } } + +/** + * Make report (PDF, CSV or XML) and send it via e-mail (this method is intended to be used by server's execution + * of alert actions that involve sending reports by e-mail). + * @param [string] $server_id id server (Node) + * @param [string] $console_event_id console Id node event in tevent + * @param [string] $trash2 don't use + * @param [string] $returnType + * + * --Internal use-- + * + * @return void + */ +function api_set_send_report($thrash1, $thrash2, $other, $returnType) +{ + global $config; + + $id_item = (int) $other['data'][0]; + $report_type = $other['data'][1]; + $email = $other['data'][2]; + $subject_email = $other['data'][3]; + $body_email = $other['data'][4]; + $make_report_from_template = (bool) $other['data'][5]; + $template_regex_agents = $other['data'][6]; + + // Filter normal and metaconsole reports. + if (is_metaconsole() === true) { + $filter['metaconsole'] = 1; + } else { + $filter['metaconsole'] = 0; + } + + $own_info = get_user_info($config['id_user']); + if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'RM') || check_acl($config['id_user'], 0, 'RR')) { + $return_all_group = true; + } else { + $return_all_group = false; + } + + if (is_user_admin($config['id_user']) === false) { + $filter[] = sprintf( + 'private = 0 OR (private = 1 AND id_user = "%s")', + $config['id_user'] + ); + } + + $date_today = date($config['date_format']); + $date_today = preg_split('/[\s,]+/', io_safe_output($date_today)); + $date_today = __($date_today[0]).' '.$date_today[1].' '.$date_today[2].' '.$date_today[3].' '.$date_today[4]; + + + if ($make_report_from_template === true) { + $filter['id_report'] = $id_item; + + $template = reports_get_report_templates( + $filter, + [ + 'description' + ], + $return_all_group, + 'RR' + )[0]; + + $description = $template['description']; + + // Report macros post-process. + $body_email = str_replace([ + '_report_description_', + '_report_generated_date_', + '_report_date_' + ], + [ + $description, + $date_today, + $date_today + ], + $body_email + ); + + $report_type = strtoupper($report_type); + $body_email = io_safe_output(io_safe_output($body_email)); + + cron_task_generate_report_by_template( + $id_item, + '', + $template_regex_agents, + false, + '', + $email, + $subject_email, + $body_email, + $report_type, + '' + ); + } else { + $report = reports_get_report($id_item); + + if ($report === false) { + // User has no grant to access this report. + return; + } + + // Report macros post-process. + $body_email = str_replace([ + '_report_description_', + '_report_generated_date_', + '_report_date_' + ], + [ + $report['description'], + $date_today, + $date_today + ], + $body_email + ); + + $body_email = io_safe_output(io_safe_output($body_email)); + + // Set the languaje of user. + global $l10n; + + if (isset($l10n) === false) { + $l10n = null; + $user_language = get_user_language($config['id_user']); + if (file_exists( + $config['homedir'].'/include/languages/'.$user_language.'.mo' + ) === true + ) { + $obj = new CachedFileReader( + $config['homedir'].'/include/languages/'.$user_language.'.mo' + ); + $l10n = new gettext_reader($obj); + $l10n->load_tables(); + } + } + + // Attachments. + $attachments = []; + // Set the datetime for the report. + $report['datetime'] = time(); + + $date = date('Y-m-j'); + $time = date('h:iA'); + + $tmpfile = false; + + switch ($report_type) { + case 'pdf': + $tmpfile = $config['homedir'].'/attachment/'.date('Ymd-His').'.pdf'; + + $report = reporting_make_reporting_data( + null, + $id_item, + $date, + $time, + null, + 'static', + null, + null, + true + ); + pdf_get_report($report, $tmpfile); + + $attachments[0] = [ + 'file' => $tmpfile, + 'content_type' => 'application/pdf', + ]; + break; + + case 'csv': + $report = reporting_make_reporting_data( + null, + $id_item, + $date, + $time, + null, + 'data' + ); + + $name = explode(' - ', $report['name']); + $tmpfile = $config['homedir'].'/attachment/'.$name[0].'.csv'; + + // Remove unused fields. + unset($report['header']); + unset($report['first_page']); + unset($report['footer']); + unset($report['custom_font']); + unset($report['id_template']); + unset($report['id_group_edit']); + unset($report['metaconsole']); + unset($report['private']); + unset($report['custom_logo']); + + ob_start(); + csv_get_report($report, true); + $output = ob_get_clean(); + + file_put_contents($tmpfile, $output); + ob_end_clean(); + + $attachments[0] = [ + 'file' => $tmpfile, + 'content_type' => 'text/csv', + ]; + break; + + case 'json': + $report = reporting_make_reporting_data( + null, + $id_item, + $date, + $time, + null, + 'data' + ); + + // Remove unused fields. + unset($report['header']); + unset($report['first_page']); + unset($report['footer']); + unset($report['custom_font']); + unset($report['id_template']); + unset($report['id_group_edit']); + unset($report['metaconsole']); + unset($report['private']); + unset($report['custom_logo']); + + $name = explode(' - ', $report['name']); + $tmpfile = $config['homedir'].'/attachment/'.$name[0].'.json'; + + file_put_contents($tmpfile, json_encode($report, JSON_PRETTY_PRINT)); + + $attachments[0] = [ + 'file' => $tmpfile, + 'content_type' => 'text/json', + ]; + break; + + case 'xml': + $report = reporting_make_reporting_data( + null, + $id_item, + $date, + $time, + null, + 'data' + ); + + $name = explode(' - ', $report['name']); + $tmpfile = $config['homedir'].'/attachment/'.$name[0].'.xml'; + + // Remove unused fields. + unset($report['header']); + unset($report['first_page']); + unset($report['footer']); + unset($report['custom_font']); + unset($report['id_template']); + unset($report['id_group_edit']); + unset($report['metaconsole']); + unset($report['private']); + unset($report['custom_logo']); + + ob_start(); + reporting_xml_get_report($report, true); + $output = ob_get_clean(); + + file_put_contents($tmpfile, $output); + ob_end_clean(); + + $attachments[0] = [ + 'file' => $tmpfile, + 'content_type' => 'text/xml', + ]; + break; + + default: + break; + } + + reporting_email_template( + $subject_email, + $body_email, + '', + $report['name'], + $email, + $attachments + ); + + unlink($other['data'][0]); + + $data = [ + 'type' => 'string', + 'data' => '1', + ]; + + returnData($returnType, $data, ';'); + } +} + diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index a9f9aa0b40..a91868a2c2 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2078,7 +2078,7 @@ function events_change_owner( events_comment( $id_event, '', - 'Change owner to '.$new_owner + 'Change owner to '.get_user_fullname($new_owner).' ('.$new_owner.')' ); } @@ -3284,18 +3284,9 @@ function events_page_responses($event) foreach ($users as $u) { $owners[$u['id_user']] = $u['id_user']; - } - - if (empty($event['owner_user']) === true) { - $owner_name = __('None'); - } else { - $owner_name = db_get_value( - 'id_user', - 'tusuario', - 'id_user', - $event['owner_user'] - ); - $owners[$event['owner_user']] = $owner_name; + if (empty($u['fullname']) === false) { + $owners[$u['id_user']] = $u['fullname'].' ('.$u['id_user'].')'; + } } $data[1] = html_print_select( @@ -4921,7 +4912,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) '%s %s %s%s', $c['action'], __('by'), - $c['id_user'], + get_user_fullname($c['id_user']).' ('.$c['id_user'].')', $eventIdExplanation ); diff --git a/pandora_console/include/functions_groupview.php b/pandora_console/include/functions_groupview.php index 286c24b689..a87bea1650 100644 --- a/pandora_console/include/functions_groupview.php +++ b/pandora_console/include/functions_groupview.php @@ -86,7 +86,8 @@ function groupview_get_modules_counters($groups_ids=false) WHERE tasg.id_group IN ($groups_ids) GROUP BY tasg.id_group ) x GROUP BY g"; - return db_get_all_rows_sql($sql); + $data = db_get_all_rows_sql($sql); + return $data; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 5217ba2b15..ab1e64cfcf 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -11537,7 +11537,7 @@ function reporting_get_group_stats_resume($id_group=0, $access='AR', $ignore_per $data['status'] = 'critical'; } else if ($data['monitor_warning'] > 0) { $data['status'] = 'warning'; - } else if (($data['monitor_unknown'] > 0) || ($data['agents_unknown'] > 0)) { + } else if (($data['monitor_unknown'] > 0) || ($data['agent_unknown'] > 0)) { $data['status'] = 'unknown'; } else if ($data['monitor_ok'] > 0) { $data['status'] = 'ok'; diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index d52aa434f4..480403cb81 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -1408,3 +1408,77 @@ function custom_fields_macros_report($macro, $key_macro) return $result; } + +/** + * Get a list of the reports the user can view. + * + * A user can view a report by two ways: + * - The user created the report (id_user field in treport) + * - The report is not private and the user has reading privileges on + * the group associated to the report + * + * @param array Extra filter to retrieve reports. All reports are returned by + * default + * @param array Fields to be fetched on every report. + * + * @return array An array with all the reports the user can view. + */ +function reports_get_report_templates( + $filter=false, + $fields=false, + $returnAllGroup=true, + $privileges='RR', + $group=false, + $strict_user=false +) { + global $config; + + if (is_array($filter) === false) { + $filter = []; + } + + if (is_array($fields) === false) { + $fields[] = 'id_group'; + $fields[] = 'id_user'; + } + + $templates = []; + $all_templates = @db_get_all_rows_filter('treport_template', $filter, $fields); + + if (empty($all_templates) === true) { + $all_templates = []; + } + + if ($group) { + $groups = $group; + } else { + $groups = users_get_groups($config['id_user'], $privileges, $returnAllGroup); + if ($strict_user) { + $groups = users_get_strict_mode_groups($config['id_user'], $returnAllGroup); + } + } + + foreach ($all_templates as $template) { + // If the template is not in all group. + if ($template['id_group'] != 0) { + if (!in_array($template['id_group'], array_keys($groups))) { + continue; + } + + if ($config['id_user'] != $template['id_user'] + && !check_acl($config['id_user'], $template['id_group'], $privileges) + ) { + continue; + } + } else { + if ($returnAllGroup === false) { + continue; + } + } + + array_push($templates, $template); + } + + return $templates; +} + diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 8bd84d0e02..1490a6607e 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1075,7 +1075,7 @@ function ui_format_alert_row( } } - if (is_metaconsole() === true) { + if (is_metaconsole() === true && (int) $server_id !== 0) { $server = db_get_row('tmetaconsole_setup', 'id', $alert['server_data']['id']); if (metaconsole_connect($server) == NOERR) { diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 0ff126ed8a..fbe1289537 100755 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -3788,6 +3788,7 @@ function visual_map_get_user_layouts( unset($filter['can_manage_group_all']); } + $where = ''; if ($check_user_groups === true && !empty($groups)) { if (empty($where)) { $where = ''; @@ -4080,7 +4081,7 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0) // When the status calculation type is 'default', only one critical // element is required to set the layout status as critical, so we can // return the critical status right now. - if ($status_data['linked_layout_status_type'] === 'default' + if ((isset($status_data['linked_layout_status_type']) === true && $status_data['linked_layout_status_type'] === 'default') && ($status == VISUAL_MAP_STATUS_CRITICAL_BAD || $status == VISUAL_MAP_STATUS_CRITICAL_ALERT) ) { @@ -4104,71 +4105,73 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0) metaconsole_restore_db(); } - // Status calculation. - switch ($status_data['linked_layout_status_type']) { - default: - case 'default': - $num_items_critical_alert = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_ALERT]; - $num_items_critical = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_BAD]; - $num_items_warning_alert = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING_ALERT]; - $num_items_warning = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING]; - $num_items_unknown = $num_elements_by_status[VISUAL_MAP_STATUS_UNKNOWN]; + if (isset($status_data['linked_layout_status_type']) === true) { + // Status calculation. + switch ($status_data['linked_layout_status_type']) { + default: + case 'default': + $num_items_critical_alert = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_ALERT]; + $num_items_critical = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_BAD]; + $num_items_warning_alert = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING_ALERT]; + $num_items_warning = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING]; + $num_items_unknown = $num_elements_by_status[VISUAL_MAP_STATUS_UNKNOWN]; - if ($num_items_critical_alert > 0) { - return VISUAL_MAP_STATUS_CRITICAL_ALERT; - } else if ($num_items_critical > 0) { - return VISUAL_MAP_STATUS_CRITICAL_BAD; - } else if ($num_items_warning_alert > 0) { - return VISUAL_MAP_STATUS_WARNING_ALERT; - } else if ($num_items_warning > 0) { - return VISUAL_MAP_STATUS_WARNING; - } else if ($num_items_unknown > 0) { - return VISUAL_MAP_STATUS_UNKNOWN; - } else { - return VISUAL_MAP_STATUS_NORMAL; - } - break; - case 'weight': - $weight = $status_data['id_layout_linked_weight']; - $num_items = count($valid_layout_items); - $num_items_critical_alert = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_ALERT]; - $num_items_critical = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_BAD]; - $num_items_warning_alert = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING_ALERT]; - $num_items_warning = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING]; - $num_items_unknown = $num_elements_by_status[VISUAL_MAP_STATUS_UNKNOWN]; + if ($num_items_critical_alert > 0) { + return VISUAL_MAP_STATUS_CRITICAL_ALERT; + } else if ($num_items_critical > 0) { + return VISUAL_MAP_STATUS_CRITICAL_BAD; + } else if ($num_items_warning_alert > 0) { + return VISUAL_MAP_STATUS_WARNING_ALERT; + } else if ($num_items_warning > 0) { + return VISUAL_MAP_STATUS_WARNING; + } else if ($num_items_unknown > 0) { + return VISUAL_MAP_STATUS_UNKNOWN; + } else { + return VISUAL_MAP_STATUS_NORMAL; + } + break; + case 'weight': + $weight = $status_data['id_layout_linked_weight']; + $num_items = count($valid_layout_items); + $num_items_critical_alert = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_ALERT]; + $num_items_critical = $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_BAD]; + $num_items_warning_alert = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING_ALERT]; + $num_items_warning = $num_elements_by_status[VISUAL_MAP_STATUS_WARNING]; + $num_items_unknown = $num_elements_by_status[VISUAL_MAP_STATUS_UNKNOWN]; - if (($num_items_critical > 0 || $num_items_critical_alert > 0) - && ((($num_items_critical_alert + $num_items_critical) * 100) / $num_items) >= $weight - ) { - return ($num_items_critical_alert > 0) ? VISUAL_MAP_STATUS_CRITICAL_ALERT : VISUAL_MAP_STATUS_CRITICAL_BAD; - } else if (($num_items_warning > 0 || $num_items_warning_alert > 0) - && (($num_items_warning_alert + $num_items_warning * 100) / $num_items) >= $weight - ) { - return ($num_items_warning_alert > 0) ? VISUAL_MAP_STATUS_WARNING_ALERT : VISUAL_MAP_STATUS_WARNING; - } else if ($num_items_unknown > 0 - && (($num_items_unknown * 100) / $num_items) >= $weight - ) { - return VISUAL_MAP_STATUS_UNKNOWN; - } else { - return VISUAL_MAP_STATUS_NORMAL; - } - break; + if (($num_items_critical > 0 || $num_items_critical_alert > 0) + && ((($num_items_critical_alert + $num_items_critical) * 100) / $num_items) >= $weight + ) { + return ($num_items_critical_alert > 0) ? VISUAL_MAP_STATUS_CRITICAL_ALERT : VISUAL_MAP_STATUS_CRITICAL_BAD; + } else if (($num_items_warning > 0 || $num_items_warning_alert > 0) + && (($num_items_warning_alert + $num_items_warning * 100) / $num_items) >= $weight + ) { + return ($num_items_warning_alert > 0) ? VISUAL_MAP_STATUS_WARNING_ALERT : VISUAL_MAP_STATUS_WARNING; + } else if ($num_items_unknown > 0 + && (($num_items_unknown * 100) / $num_items) >= $weight + ) { + return VISUAL_MAP_STATUS_UNKNOWN; + } else { + return VISUAL_MAP_STATUS_NORMAL; + } + break; - case 'service': - $num_items_critical = ($num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_BAD] + $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_ALERT]); - $critical_percentage = (($num_items_critical * 100) / count($valid_layout_items)); + case 'service': + $num_items_critical = ($num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_BAD] + $num_elements_by_status[VISUAL_MAP_STATUS_CRITICAL_ALERT]); + $critical_percentage = (($num_items_critical * 100) / count($valid_layout_items)); - $num_items_warning = ($num_elements_by_status[VISUAL_MAP_STATUS_WARNING] + $num_elements_by_status[VISUAL_MAP_STATUS_WARNING_ALERT]); - $warning_percentage = (($num_items_warning * 100) / count($valid_layout_items)); + $num_items_warning = ($num_elements_by_status[VISUAL_MAP_STATUS_WARNING] + $num_elements_by_status[VISUAL_MAP_STATUS_WARNING_ALERT]); + $warning_percentage = (($num_items_warning * 100) / count($valid_layout_items)); - if ($critical_percentage >= $status_data['linked_layout_status_as_service_critical'] && $critical_percentage !== 0) { - return VISUAL_MAP_STATUS_CRITICAL_BAD; - } else if ($warning_percentage >= $status_data['linked_layout_status_as_service_warning'] && $warning_percentage !== 0) { - return VISUAL_MAP_STATUS_WARNING; - } else { - return VISUAL_MAP_STATUS_NORMAL; - } - break; + if ($critical_percentage >= $status_data['linked_layout_status_as_service_critical'] && $critical_percentage !== 0) { + return VISUAL_MAP_STATUS_CRITICAL_BAD; + } else if ($warning_percentage >= $status_data['linked_layout_status_as_service_warning'] && $warning_percentage !== 0) { + return VISUAL_MAP_STATUS_WARNING; + } else { + return VISUAL_MAP_STATUS_NORMAL; + } + break; + } } } diff --git a/pandora_console/include/graphs/functions_d3.php b/pandora_console/include/graphs/functions_d3.php index 8c4a1b6ade..e48babd58d 100644 --- a/pandora_console/include/graphs/functions_d3.php +++ b/pandora_console/include/graphs/functions_d3.php @@ -526,8 +526,7 @@ function print_clock_analogic_1( $color, $title=true ) { - global $config; - $output .= '