diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index fbea6eb404..4fff860931 100644 --- a/pandora_agents/pc/AIX/pandora_agent.conf +++ b/pandora_agents/pc/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, AIX version +# Version 7.0NG.739, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index ded3ec4b9c..f33b304a7c 100644 --- a/pandora_agents/pc/FreeBSD/pandora_agent.conf +++ b/pandora_agents/pc/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, FreeBSD Version +# Version 7.0NG.739, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/HP-UX/pandora_agent.conf b/pandora_agents/pc/HP-UX/pandora_agent.conf index 0d3e20d05e..1d627fc222 100644 --- a/pandora_agents/pc/HP-UX/pandora_agent.conf +++ b/pandora_agents/pc/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, HP-UX Version +# Version 7.0NG.739, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 5d951d984d..9501fa5222 100644 --- a/pandora_agents/pc/Linux/pandora_agent.conf +++ b/pandora_agents/pc/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, GNU/Linux +# Version 7.0NG.739, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index 1c73d12fc9..bdd4bcf425 100644 --- a/pandora_agents/pc/NT4/pandora_agent.conf +++ b/pandora_agents/pc/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, GNU/Linux +# Version 7.0NG.739, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index fc59e308e4..f80f403dd8 100644 --- a/pandora_agents/pc/SunOS/pandora_agent.conf +++ b/pandora_agents/pc/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, Solaris Version +# Version 7.0NG.739, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index f12cb5089c..86bfede9d7 100644 --- a/pandora_agents/pc/Win32/pandora_agent.conf +++ b/pandora_agents/pc/Win32/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2010 Artica Soluciones Tecnologicas -# Version 7.0NG.738 +# Version 7.0NG.739 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index 863ab92907..aa65eb24d9 100644 --- a/pandora_agents/shellscript/aix/pandora_agent.conf +++ b/pandora_agents/shellscript/aix/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.738, AIX version +# Version 7.0NG.739, AIX version # General Parameters # ================== diff --git a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf index f56402fbcc..7c225fea1c 100644 --- a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf +++ b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.738 +# Version 7.0NG.739 # FreeBSD/IPSO version # Licenced under GPL licence, 2003-2007 Sancho Lerena diff --git a/pandora_agents/shellscript/hp-ux/pandora_agent.conf b/pandora_agents/shellscript/hp-ux/pandora_agent.conf index 55576e58fd..06bd17ed45 100644 --- a/pandora_agents/shellscript/hp-ux/pandora_agent.conf +++ b/pandora_agents/shellscript/hp-ux/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.738, HPUX Version +# Version 7.0NG.739, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index a584a597cb..54b0e06dbf 100644 --- a/pandora_agents/shellscript/linux/pandora_agent.conf +++ b/pandora_agents/shellscript/linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738 +# Version 7.0NG.739 # Licensed under GPL license v2, # (c) 2003-2010 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index 18db7a174f..f5205f4d16 100644 --- a/pandora_agents/shellscript/mac_osx/pandora_agent.conf +++ b/pandora_agents/shellscript/mac_osx/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738 +# Version 7.0NG.739 # Licensed under GPL license v2, # (c) 2003-2009 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/openWRT/pandora_agent.conf b/pandora_agents/shellscript/openWRT/pandora_agent.conf index d3266f091d..7d6a12d62b 100644 --- a/pandora_agents/shellscript/openWRT/pandora_agent.conf +++ b/pandora_agents/shellscript/openWRT/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738 +# Version 7.0NG.739 # Licensed under GPL license v2, # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/solaris/pandora_agent.conf b/pandora_agents/shellscript/solaris/pandora_agent.conf index aa59a262c4..cbae89b0b5 100644 --- a/pandora_agents/shellscript/solaris/pandora_agent.conf +++ b/pandora_agents/shellscript/solaris/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.738, Solaris version +# Version 7.0NG.739, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index dedf2c366f..7f2791b05f 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, AIX version +# Version 7.0NG.739, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 096aa04464..dcd8f262ed 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.738-190924 +Version: 7.0NG.739-190927 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 8bd3a13ac4..292fdd5fab 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.738-190924" +pandora_version="7.0NG.739-190927" 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/Darwin/pandora_agent.conf b/pandora_agents/unix/Darwin/pandora_agent.conf index 4624a5ceff..7f403ae687 100644 --- a/pandora_agents/unix/Darwin/pandora_agent.conf +++ b/pandora_agents/unix/Darwin/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, GNU/Linux +# Version 7.0NG.739, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2012 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/FreeBSD/pandora_agent.conf b/pandora_agents/unix/FreeBSD/pandora_agent.conf index 0895974d7b..2871669f88 100644 --- a/pandora_agents/unix/FreeBSD/pandora_agent.conf +++ b/pandora_agents/unix/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, FreeBSD Version +# Version 7.0NG.739, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2016 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/HP-UX/pandora_agent.conf b/pandora_agents/unix/HP-UX/pandora_agent.conf index bfd0612672..1fcbc17977 100644 --- a/pandora_agents/unix/HP-UX/pandora_agent.conf +++ b/pandora_agents/unix/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, HP-UX Version +# Version 7.0NG.739, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index e1a83ed6e5..938565241d 100644 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, GNU/Linux +# Version 7.0NG.739, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2014 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NT4/pandora_agent.conf b/pandora_agents/unix/NT4/pandora_agent.conf index b0841bd0f7..f9a2b10b93 100644 --- a/pandora_agents/unix/NT4/pandora_agent.conf +++ b/pandora_agents/unix/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, GNU/Linux +# Version 7.0NG.739, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NetBSD/pandora_agent.conf b/pandora_agents/unix/NetBSD/pandora_agent.conf index 4d96ba223d..2f108c2011 100644 --- a/pandora_agents/unix/NetBSD/pandora_agent.conf +++ b/pandora_agents/unix/NetBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, NetBSD Version +# Version 7.0NG.739, NetBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/SunOS/pandora_agent.conf b/pandora_agents/unix/SunOS/pandora_agent.conf index c4a4c578d9..47f17aae0f 100644 --- a/pandora_agents/unix/SunOS/pandora_agent.conf +++ b/pandora_agents/unix/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.738, Solaris Version +# Version 7.0NG.739, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 7aa8a0b36a..9054990e06 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,8 +41,8 @@ my $Sem = undef; # Semaphore used to control the number of threads my $ThreadSem = undef; -use constant AGENT_VERSION => '7.0NG.738'; -use constant AGENT_BUILD => '190924'; +use constant AGENT_VERSION => '7.0NG.739'; +use constant AGENT_BUILD => '190927'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; @@ -239,6 +239,15 @@ my $tentacle_pid = undef; # PID of udp_server my $udp_server_pid = undef; +# BrokerFlag +my $BrokerFlag = 0; + +# Global loop counter. +my $LoopCounter = 0; + +# Define a max value for loopCounter to avoid overflow. +use constant MAX_LOOP_COUNTER => 1000000000; + ################################################################################ # Print usage information and exit. ################################################################################ @@ -1385,6 +1394,7 @@ sub sleep_agent { exit (0); } + $LoopCounter = ($LoopCounter + 1) % MAX_LOOP_COUNTER; return $iter_base_time; } @@ -1699,6 +1709,14 @@ sub exec_module { } # Check module interval + if ($BrokerFlag > 0) { + if ($LoopCounter == 0) { + $module->{'counter'} = $module->{'intensive_interval'}; + } else { + $module->{'counter'} = (($LoopCounter -1 ) % $module->{'intensive_interval'}); + } + } + if (++($module->{'counter'}) < $module->{'intensive_interval'}) { $ThreadSem->up () if (defined ($ThreadSem) && $Conf{'agent_threads'} > 1); return; @@ -2985,7 +3003,6 @@ while (1) { @BrokerPid = (); my @broker_agents = read_config ('broker_agent'); foreach my $broker_agent (@broker_agents) { - # Create broker conf file if it does not exist if (! -e "$ConfDir/${broker_agent}.conf") { write_broker_conf($broker_agent); @@ -2995,7 +3012,9 @@ while (1) { # Broker agent if ($main_agent == 0) { - + # Mark broker flag. + $BrokerFlag = 1; + # Set the configuration file $ConfFile = "${broker_agent}.conf"; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 7e2e74d76c..2196b50e31 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.738 -%define release 190924 +%define version 7.0NG.739 +%define release 190927 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 f85e093ffa..3f03f02cfe 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.738 -%define release 190924 +%define version 7.0NG.739 +%define release 190927 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 3966e0d83d..eb5c77d5cc 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -9,8 +9,8 @@ # Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.738" -PI_BUILD="190924" +PI_VERSION="7.0NG.739" +PI_BUILD="190927" 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 c74dadfff6..d6bf2f9005 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2017 Artica Soluciones Tecnologicas -# Version 7.0NG.738 +# Version 7.0NG.739 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index faf6b9ab3f..3833593502 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -3,7 +3,7 @@ AllowLanguageSelection {Yes} AppName -{Pandora FMS Windows Agent v7.0NG.738} +{Pandora FMS Windows Agent v7.0NG.739} ApplicationID {17E3D2CF-CA02-406B-8A80-9D31C17BD08F} @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{190924} +{190927} ViewReadme {Yes} diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index e7c751d367..7cbde21ca7 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -1422,48 +1422,48 @@ Pandora_Module::evaluatePreconditions () { buffer[read] = '\0'; output += (char *) buffer; } - - try { - double_output = Pandora_Strutils::strtodouble (output); - } catch (Pandora_Strutils::Invalid_Conversion e) { - double_output = 0; + + try { + double_output = Pandora_Strutils::strtodouble (output); + } catch (Pandora_Strutils::Invalid_Conversion e) { + double_output = 0; + } + + if (dwRet == WAIT_OBJECT_0) { + break; + } else if(this->getTimeout() < GetTickCount() - tickbase) { + /* STILL_ACTIVE */ + TerminateProcess(pi.hThread, STILL_ACTIVE); + pandoraLog ("evaluatePreconditions: %s timed out (retcode: %d)", this->module_name.c_str (), STILL_ACTIVE); + break; + } } - if (dwRet == WAIT_OBJECT_0) { - break; - } else if(this->getTimeout() < GetTickCount() - tickbase) { - /* STILL_ACTIVE */ - TerminateProcess(pi.hThread, STILL_ACTIVE); - pandoraLog ("evaluatePreconditions: %s timed out (retcode: %d)", this->module_name.c_str (), STILL_ACTIVE); - break; + GetExitCodeProcess (pi.hProcess, &retval); + + if (retval != 0) { + if (! TerminateJobObject (job, 0)) { + pandoraLog ("evaluatePreconditions: TerminateJobObject failed. (error %d)", + GetLastError ()); + } + if (retval != STILL_ACTIVE) { + pandoraLog ("evaluatePreconditions: %s did not executed well (retcode: %d)", + this->module_name.c_str (), retval); + } + /* Close job, process and thread handles. */ + CloseHandle (job); + CloseHandle (pi.hProcess); + CloseHandle (pi.hThread); + CloseHandle (new_stdout); + CloseHandle (out_read); + return 0; } - } - - GetExitCodeProcess (pi.hProcess, &retval); - - if (retval != 0) { - if (! TerminateJobObject (job, 0)) { - pandoraLog ("evaluatePreconditions: TerminateJobObject failed. (error %d)", - GetLastError ()); - } - if (retval != STILL_ACTIVE) { - pandoraLog ("evaluatePreconditions: %s did not executed well (retcode: %d)", - this->module_name.c_str (), retval); - } + /* Close job, process and thread handles. */ CloseHandle (job); CloseHandle (pi.hProcess); CloseHandle (pi.hThread); - CloseHandle (new_stdout); - CloseHandle (out_read); - return 0; } - - /* Close job, process and thread handles. */ - CloseHandle (job); - CloseHandle (pi.hProcess); - CloseHandle (pi.hThread); - } CloseHandle (new_stdout); CloseHandle (out_read); @@ -1693,4 +1693,18 @@ Pandora_Module::getAsync () { return this->async; } +/** + * Get current exections + */ +long +Pandora_Module::getExecutions () { + return this->executions; +} +/** + * Set current execution (global) used for brokers. + */ +void +Pandora_Module::setExecutions (long executions) { + this->executions = executions; +} diff --git a/pandora_agents/win32/modules/pandora_module.h b/pandora_agents/win32/modules/pandora_module.h index c766766950..3b9d6c15a4 100644 --- a/pandora_agents/win32/modules/pandora_module.h +++ b/pandora_agents/win32/modules/pandora_module.h @@ -234,6 +234,8 @@ namespace Pandora_Modules { int getTimeout (); string getSave (); bool getAsync (); + void setExecutions(long executions=0); + long getExecutions(); virtual string getXml (); diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 1abef1dbf8..0dab5ddb1a 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.738(Build 190924)") +#define PANDORA_VERSION ("7.0NG.739(Build 190927)") 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 275ee60724..b62fc1f70d 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -1849,7 +1849,7 @@ Pandora_Windows_Service::sendBufferedXml (string path) { } void -Pandora_Windows_Service::pandora_run_broker (string config) { +Pandora_Windows_Service::pandora_run_broker (string config, long executions) { Pandora_Agent_Conf *conf = NULL; string server_addr; unsigned char data_flag = 0; @@ -1876,7 +1876,10 @@ Pandora_Windows_Service::pandora_run_broker (string config) { Pandora_Module *module; module = this->broker_modules->getCurrentValue (); - + + /* Keep executions matching main agent */ + module->setExecutions(executions); + /* Check preconditions */ if (module->evaluatePreconditions () == 0) { pandoraDebug ("Preconditions not matched for module %s", module->getName ().c_str ()); @@ -2074,7 +2077,7 @@ Pandora_Windows_Service::pandora_run (int forced_run) { check_broker_agents(all_conf); for (i=0;i false, + 'text' => ''.html_print_image('images/integria.png', true, ['title' => __('Integria IMS')]).'', +]; + $buttons['ehorus'] = [ 'active' => false, 'text' => ''.html_print_image('images/ehorus/ehorus.png', true, ['title' => __('eHorus')]).'', @@ -167,6 +172,12 @@ switch ($section) { $help_header = 'setup_ehorus_tab'; break; + case 'integria': + $buttons['integria']['active'] = true; + $subpage = ' » '.__('Integria IMS'); + $help_header = 'setup_integria_tab'; + break; + case 'notifications': $buttons['notifications']['active'] = true; $subpage = ' » '.__('Notifications'); @@ -228,6 +239,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_ehorus.php'; break; + case 'integria': + include_once $config['homedir'].'/godmode/setup/setup_integria.php'; + break; + case 'notifications': include_once $config['homedir'].'/godmode/setup/setup_notifications.php'; break; diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php new file mode 100644 index 0000000000..95179f6add --- /dev/null +++ b/pandora_console/godmode/setup/setup_integria.php @@ -0,0 +1,702 @@ + 1]); + } else { + echo json_encode(['login' => 0]); + } + + return; +} + +$has_connection = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_login', []); + +if ($has_connection === false && $config['integria_enabled']) { + ui_print_error_message(__('Integria IMS API is not reachable')); +} + +if (get_parameter('update_config', 0) == 1) { + // Try to retrieve event response 'Create incident in IntegriaIMS from event' to check if it exists. + $event_response_exists = db_get_row_filter('tevent_response', ['name' => io_safe_input('Create ticket in IntegriaIMS from event')]); + + // Try to retrieve command 'Integia IMS Ticket' to check if it exists. + $command_exists = db_get_row_filter('talert_commands', ['name' => io_safe_input('Integria IMS Ticket')]); + + if ($config['integria_enabled'] == 1) { + if ($event_response_exists === false) { + // Create 'Create incident in IntegriaIMS from event' event response only when user enables IntegriaIMS integration and it does not exist in database. + db_process_sql_insert( + 'tevent_response', + [ + 'name' => io_safe_input('Create ticket in IntegriaIMS from event'), + 'description' => io_safe_input('Create a ticket in Integria IMS from an event'), + 'target' => io_safe_input('index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&from_event=_event_id_'), + 'type' => 'url', + 'id_group' => '0', + 'modal_width' => '0', + 'modal_height' => '0', + 'new_window' => '1', + 'params' => '', + 'server_to_exec' => '0', + ] + ); + } + + if ($command_exists === false) { + // Create 'Integria IMS Ticket' command only when user enables IntegriaIMS integration and it does not exist in database. + $id_command_inserted = db_process_sql_insert( + 'talert_commands', + [ + 'name' => io_safe_input('Integria IMS Ticket'), + 'command' => io_safe_input('Internal type'), + 'internal' => 1, + 'description' => io_safe_input('Create a ticket in Integria IMS'), + 'fields_descriptions' => '["'.io_safe_input('Ticket title').'","'.io_safe_input('Ticket group ID').'","'.io_safe_input('Ticket priority').'","'.io_safe_input('Ticket owner').'","'.io_safe_input('Ticket type').'","'.io_safe_input('Ticket status').'","'.io_safe_input('Ticket description').'"]', + ] + ); + + // Create 'Create Integria IMS Ticket' action only when user enables IntegriaIMS integration and command exists in database. + $action_values = [ + 'field1' => io_safe_input($config['incident_title']), + 'field1_recovery' => io_safe_input($config['incident_title']), + 'field2' => io_safe_input($config['default_group']), + 'field2_recovery' => io_safe_input($config['default_group']), + 'field3' => io_safe_input($config['default_criticity']), + 'field3_recovery' => io_safe_input($config['default_criticity']), + 'field4' => io_safe_input($config['default_owner']), + 'field4_recovery' => io_safe_input($config['default_owner']), + 'field5' => io_safe_input($config['incident_type']), + 'field5_recovery' => io_safe_input($config['incident_type']), + 'field6' => io_safe_input($config['incident_status']), + 'field6_recovery' => io_safe_input($config['incident_status']), + 'field7' => io_safe_input($config['incident_content']), + 'field7_recovery' => io_safe_input($config['incident_content']), + 'id_group' => 0, + 'action_threshold' => 0, + ]; + + alerts_create_alert_action(io_safe_input('Create Integria IMS ticket'), $id_command_inserted, $action_values); + } else { + // Update 'Create Integria IMS Ticket' action when setup data is updated, user enables IntegriaIMS integration and command does exist in database. + db_process_sql_update( + 'talert_actions', + [ + 'field1' => io_safe_input($config['incident_title']), + 'field1_recovery' => io_safe_input($config['incident_title']), + 'field2' => io_safe_input($config['default_group']), + 'field2_recovery' => io_safe_input($config['default_group']), + 'field3' => io_safe_input($config['default_criticity']), + 'field3_recovery' => io_safe_input($config['default_criticity']), + 'field4' => io_safe_input($config['default_owner']), + 'field4_recovery' => io_safe_input($config['default_owner']), + 'field5' => io_safe_input($config['incident_type']), + 'field5_recovery' => io_safe_input($config['incident_type']), + 'field6' => io_safe_input($config['incident_status']), + 'field6_recovery' => io_safe_input($config['incident_status']), + 'field7' => io_safe_input($config['incident_content']), + 'field7_recovery' => io_safe_input($config['incident_content']), + ], + ['name' => io_safe_input('Create Integria IMS ticket')] + ); + } + } else { + if ($event_response_exists != false) { + // Delete 'Create incident in IntegriaIMS from event' event response if it does exist and IntegriaIMS integration is disabled. + db_process_sql_delete('tevent_response', ['name' => io_safe_input('Create ticket in IntegriaIMS from event')]); + } + + if ($command_exists != false) { + // Delete 'Integria IMS Ticket' command if it does exist and IntegriaIMS integration is disabled. + db_process_sql_delete('talert_commands', ['name' => io_safe_input('Integria IMS Ticket')]); + + // Delete 'Create Integria IMS Ticket' action if command exists and IntegriaIMS integration is disabled. + db_process_sql_delete('talert_actions', ['name' => io_safe_input('Create Integria IMS ticket')]); + } + } +} + +// Get parameters from Integria IMS API. +$integria_group_values = []; +$integria_criticity_values = []; +$integria_users_values = []; +$integria_types_values = []; +$integria_status_values = []; + +$integria_groups_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_groups', []); + +get_array_from_csv_data_pair($integria_groups_csv, $integria_group_values); + +$integria_status_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incidents_status', []); + +get_array_from_csv_data_pair($integria_status_csv, $integria_status_values); + +$integria_criticity_levels_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_priorities', []); + +get_array_from_csv_data_pair($integria_criticity_levels_csv, $integria_criticity_values); + +$integria_users_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_users', []); + +$csv_array = explode("\n", $integria_users_csv); + +foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $integria_users_values[$csv_line] = $csv_line; + } +} + +$integria_types_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_types', []); + +get_array_from_csv_data_pair($integria_types_csv, $integria_types_values); + +// Enable table. +$table_enable = new StdClass(); +$table_enable->data = []; +$table_enable->width = '100%'; +$table_enable->id = 'integria-enable-setup'; +$table_enable->class = 'databox filters'; +$table_enable->size['name'] = '30%'; +$table_enable->style['name'] = 'font-weight: bold'; + +// Enable Integria. +$row = []; +$row['name'] = __('Enable Integria IMS'); +$row['control'] = html_print_checkbox_switch('integria_enabled', 1, $config['integria_enabled'], true); +$table_enable->data['integria_enabled'] = $row; + +// Remote config table. +$table_remote = new StdClass(); +$table_remote->data = []; +$table_remote->width = '100%'; +$table_remote->styleTable = 'margin-bottom: 10px;'; +$table_remote->id = 'integria-remote-setup'; +$table_remote->class = 'databox filters'; +$table_remote->size['name'] = '30%'; +$table_remote->style['name'] = 'font-weight: bold'; + +// Integria user. +$row = []; +$row['name'] = __('User'); +$row['control'] = html_print_input_text('integria_user', $config['integria_user'], '', 30, 100, true); +$table_remote->data['integria_user'] = $row; + +// Integria password. +$row = []; +$row['name'] = __('Password'); +$row['control'] = html_print_input_password('integria_pass', io_output_password($config['integria_pass']), '', 30, 100, true); +$table_remote->data['integria_pass'] = $row; + +// Integria hostname. +$row = []; +$row['name'] = __('API Hostname'); +$row['control'] = html_print_input_text('integria_hostname', $config['integria_hostname'], '', 30, 100, true); +$row['control'] .= ui_print_help_tip(__('Hostname of Integria IMS\' API (scheme must be specified. Example: http://192.168.0.0)'), true); +$table_remote->data['integria_hostname'] = $row; + +// API password. +$row = []; +$row['name'] = __('API Password'); +$row['control'] = html_print_input_password('integria_api_pass', io_output_password($config['integria_api_pass']), '', 30, 100, true); +$row['control'] .= ui_print_help_tip(__('Password of Integria IMS\' API'), true); +$table_remote->data['integria_api_pass'] = $row; + +// Request timeout. +$row = []; +$row['name'] = __('Request timeout'); +$row['control'] = html_print_input_text('integria_req_timeout', $config['integria_req_timeout'], '', 3, 10, true); +$row['control'] .= ui_print_help_tip(__('Time in seconds to set the maximum time of the requests to the Integria API').'. '.__('0 to disable'), true); +$table_remote->data['integria_req_timeout'] = $row; + +// Alert settings. +$table_alert_settings = new StdClass(); +$table_alert_settings->data = []; +$table_alert_settings->width = '100%'; +$table_alert_settings->styleTable = 'margin-bottom: 10px;'; +$table_alert_settings->id = 'integria-cr-settings-setup'; +$table_alert_settings->class = 'databox filters'; +$table_alert_settings->size['name'] = '30%'; +$table_alert_settings->style['name'] = 'font-weight: bold'; + +// Alert incident title. +$row = []; +$row['name'] = __('Title'); +$row['control'] = html_print_input_text( + 'incident_title', + $config['incident_title'], + __('Name'), + 50, + 100, + true, + false, + false +).ui_print_help_icon('alert_macros', true); +$table_alert_settings->data['custom_response_incident_title'] = $row; + +// Alert incident description. +$row = []; +$row['name'] = __('Description'); +$row['control'] = html_print_input_text( + 'incident_content', + $config['incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('alert_macros', true); +$table_alert_settings->data['custom_response_incident_content'] = $row; + +// Alert default group. +$row = []; +$row['name'] = __('Group'); +$row['control'] = html_print_select( + $integria_group_values, + 'default_group', + $config['default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_def_group'] = $row; + +// Alert default criticity. +$row = []; +$row['name'] = __('Priority'); +$row['control'] = html_print_select( + $integria_criticity_values, + 'default_criticity', + $config['default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_def_criticity'] = $row; + +// Alert default owner. +$row = []; +$row['name'] = __('Owner'); +$row['control'] = html_print_autocomplete_users_from_integria( + 'default_owner', + $config['default_owner'], + true +); + +$table_alert_settings->data['custom_response_def_owner'] = $row; + +// Alert default incident type. +$row = []; +$row['name'] = __('Type'); +$row['control'] = html_print_select( + $integria_types_values, + 'incident_type', + $config['incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_incident_type'] = $row; + +// Alert default incident status. +$row = []; +$row['name'] = __('Status'); +$row['control'] = html_print_select( + $integria_status_values, + 'incident_status', + $config['incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_incident_status'] = $row; + +// Custom response settings. +$table_cr_settings = new StdClass(); +$table_cr_settings->data = []; +$table_cr_settings->width = '100%'; +$table_cr_settings->styleTable = 'margin-bottom: 10px;'; +$table_cr_settings->id = 'integria-cr-settings-setup'; +$table_cr_settings->class = 'databox filters'; +$table_cr_settings->size['name'] = '30%'; +$table_cr_settings->style['name'] = 'font-weight: bold'; + +// Custom response incident title. +$row = []; +$row['name'] = __('Title'); +$row['control'] = html_print_input_text( + 'cr_incident_title', + $config['cr_incident_title'], + __('Name'), + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_title'] = $row; + +// Custom response incident description. +$row = []; +$row['name'] = __('Description'); +$row['control'] = html_print_input_text( + 'cr_incident_content', + $config['cr_incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_content'] = $row; + +// Custom response default group. +$row = []; +$row['name'] = __('Group'); +$row['control'] = html_print_select( + $integria_group_values, + 'cr_default_group', + $config['cr_default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_group'] = $row; + +// Custom response default criticity. +$row = []; +$row['name'] = __('Priority'); +$row['control'] = html_print_select( + $integria_criticity_values, + 'cr_default_criticity', + $config['cr_default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_criticity'] = $row; + +// Custom response default owner. +$row = []; +$row['name'] = __('Owner'); +$row['control'] = html_print_autocomplete_users_from_integria( + 'cr_default_owner', + $config['cr_default_owner'], + true +); + +$table_cr_settings->data['custom_response_def_owner'] = $row; + +// Custom response default incident type. +$row = []; +$row['name'] = __('Type'); +$row['control'] = html_print_select( + $integria_types_values, + 'cr_incident_type', + $config['cr_incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_incident_type'] = $row; + +// Custom response default incident status. +$row = []; +$row['name'] = __('Status'); +$row['control'] = html_print_select( + $integria_status_values, + 'cr_incident_status', + $config['cr_incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_incident_status'] = $row; + +// Test. +$row = []; +$row['name'] = __('Test'); +$row['control'] = html_print_button(__('Start'), 'test-integria', false, '', 'class="sub next"', true); +$row['control'] .= ''; +$row['control'] .= ''; +$row['control'] .= ''; +$row['control'] .= ' '; +$table_remote->data['integria_test'] = $row; + +// Print. +echo '
'; +echo ''; +html_print_image('images/integria_logo.png'); +echo ''; +echo '
'; +echo '
'; +echo __('Integria IMS'); +echo '
'; +echo ''; +echo 'https://integriaims.com'; +echo ''; +echo '
'; + +echo "
"; +html_print_input_hidden('update_config', 1); + +// Form enable. +echo '
'; +html_print_table($table_enable); +echo '
'; + +// Form remote. +echo '
'; +echo '
'; +echo ''.__('Integria API settings').''; + +html_print_table($table_remote); + +echo '
'; +echo '
'; + +if ($has_connection != false) { + // Form alert default settings. + echo '
'; + echo '
'; + echo ''.__('Alert default values').''; + + html_print_table($table_alert_settings); + + echo '
'; + echo '
'; + + // Form custom response default settings. + echo '
'; + echo '
'; + echo ''.__('Event custom response default values').''; + + html_print_table($table_cr_settings); + + echo '
'; + echo '
'; + + echo '
'; + html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); + echo '
'; +} else { + echo '
'; + html_print_submit_button(__('Update and continue'), 'update_button', false, 'class="sub next"'); + echo '
'; +} + + +echo '
'; + +?> + + diff --git a/pandora_console/images/integria.png b/pandora_console/images/integria.png new file mode 100644 index 0000000000..9dcad27e3b Binary files /dev/null and b/pandora_console/images/integria.png differ diff --git a/pandora_console/images/integria_logo.png b/pandora_console/images/integria_logo.png new file mode 100644 index 0000000000..f56ecfdab5 Binary files /dev/null and b/pandora_console/images/integria_logo.png differ diff --git a/pandora_console/images/integria_logo_gray.png b/pandora_console/images/integria_logo_gray.png new file mode 100644 index 0000000000..d901e72493 Binary files /dev/null and b/pandora_console/images/integria_logo_gray.png differ diff --git a/pandora_console/include/ajax/integria_incidents.ajax.php b/pandora_console/include/ajax/integria_incidents.ajax.php new file mode 100644 index 0000000000..3991ecf51c --- /dev/null +++ b/pandora_console/include/ajax/integria_incidents.ajax.php @@ -0,0 +1,60 @@ +notify( [ 'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG', 'title' => __('Remote configuration directory is not readable'), 'message' => __( 'Remote configuration directory %s is not readable. Please, adjust configuration.', - $config['remote_config'] + $remote_config_dir ), 'url' => ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup§ion=general'), ] @@ -896,14 +898,14 @@ class ConsoleSupervisor ); } - if (is_writable($config['remote_config'].'/conf') !== true) { + if (is_writable($remote_config_dir.'/conf') !== true) { $this->notify( [ 'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG.CONF', 'title' => __('Remote configuration directory is not writable'), 'message' => __( 'Remote configuration directory %s is not writable. Please, adjust configuration.', - $config['remote_config'].'/conf' + $remote_config_dir.'/conf' ), 'url' => ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup§ion=general'), ] @@ -914,14 +916,14 @@ class ConsoleSupervisor ); } - if (is_writable($config['remote_config'].'/collections') !== true) { + if (is_writable($remote_config_dir.'/collections') !== true) { $this->notify( [ 'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG.COLLECTIONS', 'title' => __('Remote collections directory is not writable'), 'message' => __( 'Collections directory %s is not writable. Please, adjust configuration.', - $config['remote_config'].'/collections' + $remote_config_dir.'/collections' ), 'url' => ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup§ion=general'), ] @@ -932,14 +934,14 @@ class ConsoleSupervisor ); } - if (is_writable($config['remote_config'].'/md5') !== true) { + if (is_writable($remote_config_dir.'/md5') !== true) { $this->notify( [ 'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG.MD5', 'title' => __('Remote md5 directory is not writable'), 'message' => __( 'MD5 directory %s is not writable. Please, adjust configuration.', - $config['remote_config'].'/md5' + $remote_config_dir.'/md5' ), 'url' => ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup§ion=general'), ] @@ -957,7 +959,7 @@ class ConsoleSupervisor $MAX_BADXML_FILES_DATA_IN = 150; $filecount = $this->countFiles( - $config['remote_config'], + $remote_config_dir, '', $MAX_FILES_DATA_IN ); @@ -970,7 +972,7 @@ class ConsoleSupervisor 'message' => __( 'There are more than %d files in %s. Consider checking DataServer performance', $MAX_FILES_DATA_IN, - $config['remote_config'] + $remote_config_dir ), 'url' => ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup§ion=perf'), ] @@ -980,7 +982,7 @@ class ConsoleSupervisor } $filecount = $this->countFiles( - $config['remote_config'], + $remote_config_dir, '/^.*BADXML$/', $MAX_BADXML_FILES_DATA_IN ); @@ -993,7 +995,7 @@ class ConsoleSupervisor 'message' => __( 'There are more than %d files in %s. Consider checking software agents.', $MAX_BADXML_FILES_DATA_IN, - $config['remote_config'] + $remote_config_dir ), 'url' => ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup§ion=perf'), ] @@ -1266,7 +1268,8 @@ class ConsoleSupervisor $PHPSerialize_precision = ini_get('serialize_precision'); // PhantomJS status. - $result_ejecution = exec($config['phantomjs_bin'].'/phantomjs --version'); + $phantomjs_dir = io_safe_output($config['phantomjs_bin']); + $result_ejecution = exec($phantomjs_dir.'/phantomjs --version'); // PHP version checks. $php_version = phpversion(); @@ -1451,8 +1454,9 @@ class ConsoleSupervisor 'type' => 'NOTIF.PHP.SERIALIZE_PRECISION', 'title' => sprintf( __("Not recommended '%s' value in PHP configuration"), - 'serialze_precision' - ), 'message' => sprintf( + 'serialize_precision' + ), + 'message' => sprintf( __('Recommended value is: %s'), sprintf('-1') ).'

'.__('Please, change it on your PHP configuration file (php.ini) or contact with administrator'), @@ -2061,8 +2065,10 @@ class ConsoleSupervisor { global $config; - if (($config['fontpath'] == '') - || (file_exists($config['fontpath']) === false) + $fontpath = io_safe_output($config['fontpath']); + + if (($fontpath == '') + || (file_exists($fontpath) === false) ) { $this->notify( [ diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index b5cd920680..392862a1ed 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,8 +20,8 @@ /** * Pandora build version and version */ -$build_version = 'PC190924'; -$pandora_version = 'v7.0NG.738'; +$build_version = 'PC190927'; +$pandora_version = 'v7.0NG.739'; // Do not overwrite default timezone set if defined. $script_tz = @date_default_timezone_get(); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index b1027bc4af..70eb7b8728 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3789,11 +3789,20 @@ function series_type_graph_array($data, $show_elements_graph) } else if (strpos($key, 'percentil') !== false) { $data_return['series_type'][$key] = 'percentil'; if ($show_elements_graph['percentil']) { - $data_return['legend'][$key] = __('Percentil').' '.$config['percentil'].'º '.__('of module').' '; if ($show_elements_graph['unit']) { - $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].' / '.__('Unit ').' '.$show_elements_graph['unit'].': '; + $name_legend = __('Percentil').' '; + $name_legend .= $config['percentil'].'º '; + $name_legend .= __('of module').' '; + $name_legend .= $value['agent_alias'].' / '; + $name_legend .= $value['module_name'].' / '; + $name_legend .= __('Unit ').' '; + $name_legend .= $show_elements_graph['unit'].': '; } else { - $name_legend = $data_return['legend'][$key] = $value['agent_alias'].' / '.$value['module_name'].': '; + $name_legend = __('Percentil').' '; + $name_legend .= $config['percentil'].'º '; + $name_legend .= __('of module').' '; + $name_legend .= $value['agent_alias'].' / '; + $name_legend .= $value['module_name'].': '; } $data_return['legend'][$key] .= $name_legend; @@ -4086,7 +4095,7 @@ function mask2cidr($mask) function get_help_info($section_name) { global $config; - // hd($section_name); + $user_language = get_user_language($id_user); $es = false; @@ -5412,7 +5421,6 @@ function get_help_info($section_name) break; } - // hd($result); return $result; } diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index bc5e64190d..6563a6def2 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1434,6 +1434,92 @@ function config_update_config() } break; + case 'integria': + if (!config_update_value('integria_enabled', (int) get_parameter('integria_enabled', 0))) { + $error_update[] = __('Enable Integria IMS'); + } + + if (!config_update_value('integria_user', (string) get_parameter('integria_user', $config['integria_user']))) { + $error_update[] = __('Integria user'); + } + + if (!config_update_value('integria_pass', io_input_password((string) get_parameter('integria_pass', $config['integria_pass'])))) { + $error_update[] = __('Integria password'); + } + + if (!config_update_value('integria_hostname', (string) get_parameter('integria_hostname', $config['integria_hostname']))) { + $error_update[] = __('integria API hostname'); + } + + if (!config_update_value('integria_api_pass', io_input_password((string) get_parameter('integria_api_pass', $config['integria_api_pass'])))) { + $error_update[] = __('Integria API password'); + } + + if (!config_update_value('integria_req_timeout', (int) get_parameter('integria_req_timeout', $config['integria_req_timeout']))) { + $error_update[] = __('Integria request timeout'); + } + + if (!config_update_value('default_group', (int) get_parameter('default_group', $config['default_group']))) { + $error_update[] = __('Integria default group'); + } + + if (!config_update_value('cr_default_group', (int) get_parameter('cr_default_group', $config['cr_default_group']))) { + $error_update[] = __('Integria custom response default group'); + } + + if (!config_update_value('default_criticity', (int) get_parameter('default_criticity', $config['default_criticity']))) { + $error_update[] = __('Integria default priority'); + } + + if (!config_update_value('cr_default_criticity', (int) get_parameter('cr_default_criticity', $config['cr_default_criticity']))) { + $error_update[] = __('Integria custom response default priority'); + } + + if (!config_update_value('default_creator', (string) get_parameter('default_creator', $config['default_creator']))) { + $error_update[] = __('Integria default creator'); + } + + if (!config_update_value('default_owner', (string) get_parameter('default_owner', $config['default_owner']))) { + $error_update[] = __('Integria default owner'); + } + + if (!config_update_value('cr_default_owner', (string) get_parameter('cr_default_owner', $config['cr_default_owner']))) { + $error_update[] = __('Integria custom response default owner'); + } + + if (!config_update_value('incident_type', (int) get_parameter('incident_type', $config['incident_type']))) { + $error_update[] = __('Integria default ticket type'); + } + + if (!config_update_value('cr_incident_type', (int) get_parameter('cr_incident_type', $config['cr_incident_type']))) { + $error_update[] = __('Integria custom response default ticket type'); + } + + if (!config_update_value('incident_status', (int) get_parameter('incident_status', $config['incident_status']))) { + $error_update[] = __('Integria default ticket status'); + } + + if (!config_update_value('cr_incident_status', (int) get_parameter('cr_incident_status', $config['cr_incident_status']))) { + $error_update[] = __('Integria custom response default ticket status'); + } + + if (!config_update_value('incident_title', (string) get_parameter('incident_title', $config['incident_title']))) { + $error_update[] = __('Integria default ticket title'); + } + + if (!config_update_value('cr_incident_title', (string) get_parameter('cr_incident_title', $config['cr_incident_title']))) { + $error_update[] = __('Integria custom response default ticket title'); + } + + if (!config_update_value('incident_content', (string) get_parameter('incident_content', $config['incident_content']))) { + $error_update[] = __('Integria default ticket content'); + } + + if (!config_update_value('cr_incident_content', (string) get_parameter('cr_incident_content', $config['cr_incident_content']))) { + $error_update[] = __('Integria custom response default ticket content'); + } + break; + default: // Ignore. break; @@ -1500,7 +1586,7 @@ function config_process_config() if (!isset($config['remote_config'])) { if ($is_windows) { - $default = 'C:\\PandoraFMS\\Pandora_Server\\data_in'; + $default = 'C:\PandoraFMS\Pandora_Server\data_in'; } else { $default = '/var/spool/pandora/data_in'; } @@ -1510,7 +1596,7 @@ function config_process_config() if (!isset($config['phantomjs_bin'])) { if ($is_windows) { - $default = 'C:\\PandoraFMS\\phantomjs'; + $default = 'C:\PandoraFMS\Pandora_Server\bin'; } else { $default = '/usr/bin'; } @@ -1760,7 +1846,13 @@ function config_process_config() } if (!isset($config['auditdir'])) { - config_update_value('auditdir', '/var/www/html/pandora_console'); + $auditdir = '/var/www/html/pandora_console'; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + // Windows. + $auditdir = $config['homedir']; + } + + config_update_value('auditdir', $auditdir); } if (!isset($config['elasticsearch_ip'])) { @@ -1794,6 +1886,7 @@ function config_process_config() /* * Parse the ACL IP list for access API */ + $temp_list_ACL_IPs_for_API = []; if (isset($config['list_ACL_IPs_for_API'])) { if (!empty($config['list_ACL_IPs_for_API'])) { @@ -1804,13 +1897,16 @@ function config_process_config() $config['list_ACL_IPs_for_API'] = $temp_list_ACL_IPs_for_API; $keysConfig = array_keys($config); - // This is not set here. The first time, when no - // setup is done, update_manager extension manage it - // the first time make a conenction and disable itself - // Not Managed here ! - // if (!isset ($config["autoupdate"])) { - // config_update_value ('autoupdate', true);. - // } + /* + * This is not set here. The first time, when no + * setup is done, update_manager extension manage it + * the first time make a conenction and disable itself + * Not Managed here ! + * if (!isset ($config["autoupdate"])) { + * config_update_value ('autoupdate', true);. + * } + */ + include_once $config['homedir'].'/include/auth/mysql.php'; include_once $config['homedir'].'/include/functions_io.php'; @@ -1819,10 +1915,16 @@ function config_process_config() // user, and should be in pandora root. By default, Pandora adds // /attachment to this, so by default is the pandora console home // dir. + $attachment_store_path = $config['homedir'].'/attachment'; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + // Windows. + $attachment_store_path = $config['homedir'].'\attachment'; + } + if (!isset($config['attachment_store'])) { config_update_value( 'attachment_store', - io_safe_input($config['homedir']).'/attachment' + $attachment_store_path ); } else { // Fixed when the user moves the pandora console to another dir @@ -1830,16 +1932,23 @@ function config_process_config() if (!is_dir($config['attachment_store'])) { config_update_value( 'attachment_store', - $config['homedir'].'/attachment' + $attachment_store_path ); } } if (!isset($config['fontpath'])) { - $home = str_replace('\\', '/', $config['homedir']); + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + // Windows. + $fontpath = $config['homedir'].'\include\fonts\smallfont.ttf'; + } else { + $home = str_replace('\\', '/', $config['homedir']); + $fontpath = $home.'/include/fonts/smallfont.ttf'; + } + config_update_value( 'fontpath', - $home.'/include/fonts/smallfont.ttf' + $fontpath ); } @@ -2077,7 +2186,7 @@ function config_process_config() if (!isset($config['netflow_path'])) { if ($is_windows) { - $default = 'C:\\PandoraFMS\\Pandora_Server\\data_in\\netflow'; + $default = 'C:\PandoraFMS\Pandora_Server\data_in\netflow'; } else { $default = '/var/spool/pandora/data_in/netflow'; } @@ -2639,6 +2748,10 @@ function config_process_config() config_update_value('zoom_graph', 1); } + if (!isset($config['percentil'])) { + config_update_value('percentil', 95); + } + if (!isset($config['render_proc_ok'])) { config_update_value('render_proc_ok', __('Ok')); } @@ -2820,6 +2933,19 @@ function config_process_config() } } + // Integria. + if (!isset($config['integria_enabled'])) { + config_update_value('integria_enabled', 0); + } + + if (!isset($config['integria_req_timeout'])) { + config_update_value('integria_req_timeout', 5); + } + + if (!isset($config['integria_hostname'])) { + config_update_value('integria_hostname', ''); + } + // Finally, check if any value was overwritten in a form. config_update_config(); } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 75533f7f56..b10b38702f 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -6638,3 +6638,244 @@ function events_get_secondary_groups_left_join($table) return 'LEFT JOIN tmetaconsole_agent_secondary_group tasg ON te.id_agente = tasg.id_tagente AND te.server_id = tasg.id_tmetaconsole_setup'; } + + +/** + * Replace macros in any string given an event id. + * If server_id > 0, it's a metaconsole query. + * + * @param integer $event_id Event identifier. + * @param integer $value String value in which we want to apply macros. + * + * @return string The response text with the macros applied. + */ +function events_get_field_value_by_event_id( + int $event_id, + $value +) { + global $config; + + $meta = false; + $event = db_get_row('tevento', 'id_evento', $event_id); + + // Replace each macro. + if (strpos($value, '_agent_address_') !== false) { + if ($meta) { + $agente_table_name = 'tmetaconsole_agent'; + $filter = [ + 'id_tagente' => $event['id_agente'], + 'id_tmetaconsole_setup' => $server_id, + ]; + } else { + $agente_table_name = 'tagente'; + $filter = ['id_agente' => $event['id_agente']]; + } + + $ip = db_get_value_filter('direccion', $agente_table_name, $filter); + // If agent does not have an IP, display N/A. + if ($ip === false) { + $ip = __('N/A'); + } + + $value = str_replace('_agent_address_', $ip, $value); + } + + if (strpos($value, '_agent_id_') !== false) { + $value = str_replace('_agent_id_', $event['id_agente'], $value); + } + + if (strpos($value, '_module_address_') !== false) { + if ($event['id_agentmodule'] != 0) { + if ($meta) { + $server = metaconsole_get_connection_by_id($server_id); + metaconsole_connect($server); + } + + $module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']); + if (empty($module['ip_target'])) { + $module['ip_target'] = __('N/A'); + } + + $value = str_replace('_module_address_', $module['ip_target'], $value); + if (empty($module['nombre'])) { + $module['nombre'] = __('N/A'); + } + + if ($meta) { + metaconsole_restore_db(); + } + } else { + $value = str_replace('_module_address_', __('N/A'), $value); + } + } + + if (strpos($value, '_module_name_') !== false) { + if ($event['id_agentmodule'] != 0) { + if ($meta) { + $server = metaconsole_get_connection_by_id($server_id); + metaconsole_connect($server); + } + + $module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']); + if (empty($module['ip_target'])) { + $module['ip_target'] = __('N/A'); + } + + $value = str_replace( + '_module_name_', + io_safe_output($module['nombre']), + $value + ); + + if ($meta) { + metaconsole_restore_db(); + } + } else { + $value = str_replace('_module_name_', __('N/A'), $value); + } + } + + if (strpos($value, '_event_id_') !== false) { + $value = str_replace('_event_id_', $event['id_evento'], $value); + } + + if (strpos($value, '_user_id_') !== false) { + if (!empty($event['id_usuario'])) { + $value = str_replace('_user_id_', $event['id_usuario'], $value); + } else { + $value = str_replace('_user_id_', __('N/A'), $value); + } + } + + if (strpos($value, '_group_id_') !== false) { + $value = str_replace('_group_id_', $event['id_grupo'], $value); + } + + if (strpos($value, '_group_name_') !== false) { + $value = str_replace( + '_group_name_', + groups_get_name($event['id_grupo'], true), + $value + ); + } + + if (strpos($value, '_event_utimestamp_') !== false) { + $value = str_replace( + '_event_utimestamp_', + $event['utimestamp'], + $value + ); + } + + if (strpos($value, '_event_date_') !== false) { + $value = str_replace( + '_event_date_', + date($config['date_format'], $event['utimestamp']), + $value + ); + } + + if (strpos($value, '_event_text_') !== false) { + $value = str_replace( + '_event_text_', + events_display_name($event['evento']), + $value + ); + } + + if (strpos($value, '_event_type_') !== false) { + $value = str_replace( + '_event_type_', + events_print_type_description($event['event_type'], true), + $value + ); + } + + if (strpos($value, '_alert_id_') !== false) { + $value = str_replace( + '_alert_id_', + empty($event['is_alert_am']) ? __('N/A') : $event['is_alert_am'], + $value + ); + } + + if (strpos($value, '_event_severity_id_') !== false) { + $value = str_replace('_event_severity_id_', $event['criticity'], $value); + } + + if (strpos($value, '_event_severity_text_') !== false) { + $value = str_replace( + '_event_severity_text_', + get_priority_name($event['criticity']), + $value + ); + } + + if (strpos($value, '_module_id_') !== false) { + $value = str_replace('_module_id_', $event['id_agentmodule'], $value); + } + + if (strpos($value, '_event_tags_') !== false) { + $value = str_replace('_event_tags_', $event['tags'], $value); + } + + if (strpos($value, '_event_extra_id_') !== false) { + if (empty($event['id_extra'])) { + $value = str_replace('_event_extra_id_', __('N/A'), $value); + } else { + $value = str_replace('_event_extra_id_', $event['id_extra'], $value); + } + } + + if (strpos($value, '_event_source_') !== false) { + $value = str_replace('_event_source_', $event['source'], $value); + } + + if (strpos($value, '_event_instruction_') !== false) { + $value = str_replace( + '_event_instruction_', + events_display_instructions($event['event_type'], $event, false), + $value + ); + } + + if (strpos($value, '_owner_user_') !== false) { + if (empty($event['owner_user'])) { + $value = str_replace('_owner_user_', __('N/A'), $value); + } else { + $value = str_replace('_owner_user_', $event['owner_user'], $value); + } + } + + if (strpos($value, '_event_status_') !== false) { + $event_st = events_display_status($event['estado']); + $value = str_replace('_event_status_', $event_st['title'], $value); + } + + if (strpos($value, '_group_custom_id_') !== false) { + $group_custom_id = db_get_value_sql( + sprintf( + 'SELECT custom_id FROM tgrupo WHERE id_grupo=%s', + $event['id_grupo'] + ) + ); + $event_st = events_display_status($event['estado']); + $value = str_replace('_group_custom_id_', $group_custom_id, $value); + } + + // Parse the event custom data. + if (!empty($event['custom_data'])) { + $custom_data = json_decode(base64_decode($event['custom_data'])); + foreach ($custom_data as $key => $val) { + $value = str_replace('_customdata_'.$key.'_', $val, $value); + } + } + + // This will replace the macro with the current logged user. + if (strpos($value, '_current_user_') !== false) { + $value = str_replace('_current_user_', $config['id_user'], $value); + } + + return $value; + +} diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d0e844c3bf..cbc0bceee5 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -302,6 +302,15 @@ function grafico_modulo_sparse_data( $array_data['sum'.$series_suffix]['agent_alias'] = $data_module_graph['agent_alias']; $array_data['sum'.$series_suffix]['unit'] = $data_module_graph['unit']; + if ($params['percentil']) { + $array_data['percentil'.$series_suffix]['agent_module_id'] = $agent_module_id; + $array_data['percentil'.$series_suffix]['id_module_type'] = $data_module_graph['id_module_type']; + $array_data['percentil'.$series_suffix]['agent_name'] = $data_module_graph['agent_name']; + $array_data['percentil'.$series_suffix]['module_name'] = $data_module_graph['module_name']; + $array_data['percentil'.$series_suffix]['agent_alias'] = $data_module_graph['agent_alias']; + $array_data['percentil'.$series_suffix]['unit'] = $data_module_graph['unit']; + } + // This is for a specific type of report that consists in passing // an interval and doing the average sum and avg. if ($params['force_interval'] != '') { @@ -378,12 +387,6 @@ function grafico_modulo_sparse_data( $array_data['sum1']['data'] = $acum_array_data; } - if ($params['percentil']) { - $percentil_value = $array_data['percentil'.$series_suffix]['data'][0][1]; - } else { - $percentil_value = 0; - } - $events = []; if (isset($array_data['sum'.$series_suffix]['max'])) { $max = $array_data['sum'.$series_suffix]['max']; @@ -1471,8 +1474,6 @@ function graphic_combined_module( $min = $array_data['sum'.$i]['min']; $avg = $array_data['sum'.$i]['avg']; - $percentil_value = $array_data['percentil'.$i]['data'][0][1]; - if ($config['fixed_graph'] == false) { $water_mark = [ 'file' => $config['homedir'].'/images/logo_vertical_water.png', diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 12d4aecc01..ab3aad9c7a 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3383,3 +3383,116 @@ function html_print_input($data, $wrapper='div', $input_only=false) return $output; } + + +/** + * Print an autocomplete input filled out with Integria IMS users. + * + * @param string $name The name of ajax control, by default is "users". + * @param string $default The default value to show in the ajax control. + * @param boolean $return If it is true return a string with the output instead to echo the output. + * @param string $size Size. + * + * @return mixed If the $return is true, return the output as string. + */ +function html_print_autocomplete_users_from_integria( + $name='users', + $default='', + $return=false, + $size='30', + $disable=false, + $required=false +) { + global $config; + + ob_start(); + + $attrs = ['style' => 'background: url(images/user_green.png) no-repeat right;']; + + if ($required) { + $attrs['required'] = 'required'; + } + + html_print_input_text_extended( + $name, + $default, + 'text-'.$name, + '', + $size, + 100, + $disable, + '', + $attrs + ); + html_print_input_hidden($name.'_hidden', $id_agent_module); + + ui_print_help_tip(__('Type at least two characters to search the user.'), false); + + $javascript_ajax_page = ui_get_full_url('ajax.php', false, false, false, false); + ?> + + '.html_print_image('images/setup.png', true, ['title' => __('Configure Integria IMS')]).''; + $list_tab['text'] = ''.html_print_image('images/list.png', true, ['title' => __('Ticket list')]).''; + $create_tab['text'] = ''.html_print_image('images/pencil.png', true, ['title' => __('New ticket')]).''; + + switch ($active_tab) { + case 'setup_tab': + $setup_tab['active'] = true; + $list_tab['active'] = false; + $create_tab['active'] = false; + break; + + case 'list_tab': + $setup_tab['active'] = false; + $list_tab['active'] = true; + $create_tab['active'] = false; + break; + + case 'create_tab': + $setup_tab['active'] = false; + $list_tab['active'] = false; + $create_tab['active'] = true; + break; + + default: + $setup_tab['active'] = false; + $list_tab['active'] = false; + $create_tab['active'] = false; + break; + } + + if ($view) { + $create_tab['text'] = ''.html_print_image('images/pencil.png', true, ['title' => __('Edit ticket')]).''; + $view_tab['text'] = ''.html_print_image('images/operation.png', true, ['title' => __('View ticket')]).''; + // When the current page is the View page. + if (!$active_tab) { + $view_tab['active'] = true; + } + } + + $onheader = []; + + if (check_acl($config['id_user'], 0, 'IR') && $view) { + $onheader['view'] = $view_tab; + } + + if (check_acl($config['id_user'], 0, 'PM')) { + $onheader['configure'] = $setup_tab; + } + + if (check_acl($config['id_user'], 0, 'IR')) { + $onheader['list'] = $list_tab; + } + + if (check_acl($config['id_user'], 0, 'IW')) { + $onheader['create'] = $create_tab; + } + + return $onheader; +} + + +/** + * Gets all the details of Integria IMS API + * + * @param string $details Type of API call. + * @param number $detail_index Send index if you want return the text. + * + * @return string or array with result of API call. + */ +function integriaims_get_details($details, $detail_index=false) +{ + global $config; + + switch ($details) { + case 'status': + $operation = 'get_incidents_status'; + break; + + case 'group': + $operation = 'get_groups'; + break; + + case 'priority': + $operation = 'get_incident_priorities'; + break; + + case 'resolution': + $operation = 'get_incidents_resolutions'; + break; + + case 'type': + $operation = 'get_types'; + break; + + default: + // code... + break; + } + + $api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], $operation); + $result = []; + get_array_from_csv_data_pair($api_call, $result); + + if ($detail_index !== false) { + if ($result[$detail_index] == '' || $result[$detail_index] === null) { + return __('None'); + } else { + return $result[$detail_index]; + } + } else { + return $result; + } +} + + +/** + * Perform an API call to Integria IMS. + * + * @param string API host URL. + * @param string User name. + * @param string User password. + * @param string API password. + * @param string API Operation. + * @param array Array with parameters required by the API function. + * + * @return boolean True if API request succeeded, false if API request failed. + */ +function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array=[], $show_credentials_error_msg=false) +{ + $params_string = implode(',', $params_array); + + $url_data = [ + 'user' => $user, + 'user_pass' => $user_pass, + 'pass' => $api_pass, + 'op' => $operation, + 'params' => html_entity_decode($params_string), + ]; + + // Build URL for API request. + $url = $api_hostname.'/integria/include/api.php'; + + // ob_start(); + // $out = fopen('php://output', 'w'); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $url_data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_STDERR, $out); + $result = curl_exec($ch); + + // fclose($out); + // $debug = ob_get_clean(); + $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + $error = false; + + if ($result === false) { + $error = curl_error($ch); + } + + curl_close($ch); + + if ($error === true || $http_status !== 200) { + if ($show_credentials_error_msg === true) { + ui_print_error_message(__('API request failed. Please check Integria IMS\' access credentials in Pandora setup.')); + } + + return false; + } else { + return $result; + } +} + + +// Parse CSV consisting of one or more lines of the form key-value pair into an array. +function get_array_from_csv_data_pair($csv_data, &$array_values) +{ + $csv_array = explode("\n", $csv_data); + + foreach ($csv_array as $csv_value) { + if (empty($csv_value)) { + continue; + } + + $new_csv_value = str_getcsv($csv_value); + + $array_values[$new_csv_value[0]] = $new_csv_value[1]; + } +} + + +/** + * Parse CSV consisting of all lines into an array. + * + * @param string $csv_data Data returned of csv api call. + * @param string $array_values Returned array. + * @param array $index Array to create an associative index (opcional). + */ +function get_array_from_csv_data_all($csv_data, &$array_values, $index=false) +{ + $csv_array = explode("\n", $csv_data); + + foreach ($csv_array as $csv_value) { + if (empty($csv_value)) { + continue; + } + + $new_csv_value = str_getcsv($csv_value); + + if ($index !== false) { + foreach ($new_csv_value as $key => $value) { + $new_csv_value_index[$index[$key]] = str_replace(':::', ',', $value); + ; + } + + $array_values[$new_csv_value[0]] = $new_csv_value_index; + } else { + $new_csv_value_comma = array_map( + function ($item) { + return str_replace(':::', ',', $item); + }, + $new_csv_value + ); + $array_values[$new_csv_value[0]] = $new_csv_value_comma; + } + } +} + + +/** + * Print priority for Integria IMS with colors. + * + * @param string $priority value of priority in Integria IMS. + * @param string $priority_label text shown in color box. + * + * @return HTML code to print the color box. + */ +function ui_print_integria_incident_priority($priority, $priority_label) +{ + global $config; + + $output = ''; + switch ($priority) { + case 0: + $color = COL_UNKNOWN; + break; + + case 1: + $color = COL_NORMAL; + break; + + case 10: + $color = COL_NOTINIT; + break; + + case 2: + $color = COL_WARNING; + break; + + case 3: + $color = COL_ALERTFIRED; + break; + + case 4: + $color = COL_CRITICAL; + break; + } + + $output = '
'; + $output .= $priority_label; + $output .= '
'; + + return $output; +} + + +/** + * Get tickets from Integria IMS. + * + * @param array $tickets_filters Filters to send to API. + * + * @return array Tickets returned by API call. + */ +function get_tickets_integriaims($tickets_filters) +{ + global $config; + + // Filters. + $incident_text = $tickets_filters['incident_text']; + $incident_status = $tickets_filters['incident_status']; + $incident_group = $tickets_filters['incident_group']; + $incident_owner = $tickets_filters['incident_owner']; + $incident_creator = $tickets_filters['incident_creator']; + $incident_priority = $tickets_filters['incident_priority']; + $incident_resolution = $tickets_filters['incident_resolution']; + $created_from = $tickets_filters['created_from']; + $created_to = $tickets_filters['created_to']; + + // API call. + $result_api_call_list = integria_api_call( + $config['integria_hostname'], + $config['integria_user'], + $config['integria_pass'], + $config['integria_api_pass'], + 'get_incidents', + [ + $incident_text, + $incident_status, + $incident_group, + $incident_priority, + '0', + $incident_owner, + $incident_creator, + ] + ); + + // Return array of api call 'get_incidents'. + $array_get_incidents = []; + get_array_from_csv_data_all($result_api_call_list, $array_get_incidents); + + // Modify $array_get_incidents if filter for resolution exists. + $filter_resolution = []; + foreach ($array_get_incidents as $key => $value) { + if ($incident_resolution !== '' && ($array_get_incidents[$key][12] == $incident_resolution)) { + $filter_resolution[$key] = $array_get_incidents[$key]; + continue; + } + } + + if ($incident_resolution !== '') { + $array_get_incidents = $filter_resolution; + } + + // Modify $array_get_incidents if filter for date is selected. + if ($created_from !== '' && $created_to !== '') { + $date = []; + $date_utimestamp = []; + foreach ($array_get_incidents as $key => $value) { + // Change format date / to -. + $date[$key] = date('Y-m-d', strtotime($array_get_incidents[$key][9])); + // Covert date to utimestamp. + $date_utimestamp[$key] = strtotime($date[$key]); + } + + // Change format date / to -. + $created_from_date = date('Y-m-d', strtotime($created_from)); + $created_to_date = date('Y-m-d', strtotime($created_to)); + + // Covert date to utimestamp. + $created_from_timestamp = strtotime($created_from_date); + $created_to_timestamp = strtotime($created_to_date); + + // Dates within the selected period. + $selected_period = array_filter( + $date_utimestamp, + function ($value) use ($created_from_timestamp, $created_to_timestamp) { + return ($value >= $created_from_timestamp && $value <= $created_to_timestamp); + } + ); + + // Return incidents with the correct dates. + $filter_date = []; + foreach ($array_get_incidents as $key => $value) { + foreach ($selected_period as $index => $value) { + if ($array_get_incidents[$key][0] == $index) { + $filter_date[$key] = $array_get_incidents[$key]; + continue; + } + } + } + + $array_get_incidents = $filter_date; + } + + return $array_get_incidents; +} diff --git a/pandora_console/include/gettext.php b/pandora_console/include/gettext.php index 152040f327..5d3abd83fe 100644 --- a/pandora_console/include/gettext.php +++ b/pandora_console/include/gettext.php @@ -104,7 +104,7 @@ class gettext_reader { * @param boolean enable_cache Enable or disable caching of strings (default on) */ function gettext_reader($Reader, $enable_cache = true) { - $machine = @shell_exec('uname -m'); + $machine = php_uname("m"); $enabled64Bits = false; if (preg_match('/64/', $machine)) { diff --git a/pandora_console/include/styles/integriaims.css b/pandora_console/include/styles/integriaims.css new file mode 100644 index 0000000000..0c8440e739 --- /dev/null +++ b/pandora_console/include/styles/integriaims.css @@ -0,0 +1,125 @@ +/* --- Integria IMS --- */ +div.priority { + width: 80px; + color: #fff; + text-align: center; + border-radius: 5px; + padding: 5px; + display: table-cell; + vertical-align: middle; +} + +/* Details view */ +div.integria_details { + display: grid; + grid-column-gap: 10px; + grid-template-columns: repeat(3, minmax(min-content, auto)); + grid-auto-rows: 1fr; +} + +div.integria_details div.box-shadow.white_table_graph { + box-shadow: none; +} + +div.integria_details div.priority { + display: inline-block; +} + +div.integriaims_details_row { + display: grid; + grid-gap: 10px; + text-align: center; + margin-top: 8px; + margin-bottom: 8px; +} + +div.integriaims_details_titles { + font-weight: bold; +} + +div.integria_details_row_five { + grid-template-columns: repeat(5, 1fr); +} + +div.integria_details_row_three { + grid-template-columns: repeat(3, 1fr); +} + +div.integria_details_description { + width: 100%; +} + +div.integria_details_description textarea { + width: 100%; + background-color: #fbfbfb; + resize: vertical; +} + +.integriaims_details_box { + display: grid; + grid-column-gap: 10px; + grid-row-gap: 5px; + align-items: center; + width: 100%; + text-align: center; +} + +.integriaims_details_box_five { + grid-template-rows: repeat(3, 1fr); + grid-template-columns: repeat(5, 1fr); +} + +.integriaims_details_box_three { + grid-template-rows: repeat(3, 1fr); + grid-template-columns: repeat(3, 1fr); +} + +/* ui_toggles */ +.integria_details_shadow { + background-color: #fff; + border-bottom: 1px solid #e2e2e2; + border-left: 1px solid #e2e2e2; + border-top-left-radius: 5px; + border-right: 1px solid #e2e2e2; + border-top-right-radius: 5px; +} + +.integria_details_shadow .white_table_graph_header { + border-left: none; + border-right: none; +} + +.integria_details_content { + border-bottom: none; + border-left: none; + border-right: none; +} + +/* Inputs type text shown as a black line */ +.integria_incidents_options input[type="text"] { + background-color: transparent; + border: none; + border-radius: 0; + border-bottom: 1px solid #ccc; + font-family: "lato-bolder", "Open Sans", sans-serif; + font-size: 10pt; + padding: 2px 5px; + box-sizing: border-box; + background-repeat: no-repeat; + background-position: left bottom 2px; + margin-bottom: 4px; +} + +.integria_incident_options input[readonly] { + color: #848484; +} + +.comment_title { + padding: 5px 10px 5px 20px; + background-color: rgba(130, 185, 46, 0.16); + border-radius: 3px; +} + +.comment_body { + padding: 15px 20px 15px 20px; +} diff --git a/pandora_console/install.php b/pandora_console/install.php index 610185a0bf..50601efddf 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -128,8 +128,8 @@
width = '100%'; +$table->id = 'add_alert_table'; +$table->class = 'databox filters integria_incidents_options'; +$table->head = []; + +$table->data = []; +$table->size = []; +$table->size = []; +$table->style[0] = 'width: 33%; padding-right: 50px; padding-left: 100px;'; +$table->style[1] = 'width: 33%; padding-right: 50px; padding-left: 50px;'; +$table->style[2] = 'width: 33%; padding-right: 100px; padding-left: 50px;'; +$table->colspan[0][0] = 2; +$table->colspan[3][0] = 3; + +$help_macros = isset($_GET['from_event']) ? ui_print_help_icon('response_macros', true) : ''; + +if (isset($_GET['from_event'])) { + if ($update) { + $input_value_title = $incident_details[3]; + $input_value_type = $incident_details[17]; + $input_value_status = $incident_details[6]; + $input_value_group = $incident_details[8]; + $input_value_criticity = $incident_details[7]; + $input_value_owner = $incident_details[5]; + $input_value_content = $incident_details[4]; + } else if (isset($_GET['from_event'])) { + $input_value_title = $config['cr_incident_title']; + $input_value_type = $config['cr_incident_type']; + $input_value_status = $config['cr_incident_status']; + $input_value_group = $config['cr_default_group']; + $input_value_criticity = $config['cr_default_criticity']; + $input_value_owner = $config['cr_default_owner']; + $input_value_content = $config['cr_incident_content']; + } else { + $input_value_title = ''; + $input_value_type = ''; + $input_value_status = ''; + $input_value_group = ''; + $input_value_criticity = ''; + $input_value_owner = ''; + $input_value_content = ''; + } +} + +$table->data[0][0] = '

'.__('Title').': '.$help_macros.'

'; +$table->data[0][0] .= '
'.html_print_input_text( + 'incident_title', + $input_value_title, + __('Name'), + 50, + 100, + true, + false, + true, + '', + 'w100p' +).'
'; + +$table->data[0][2] = html_print_image('images/integria_logo_gray.png', true, ['style' => 'width: 70%; float: right;'], false); + +$table->data[1][0] = '

'.__('Type').':

'; +$table->data[1][0] .= '
'.html_print_select( + $integria_types_values, + 'type', + $input_value_type, + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][0] = '

'.__('Status').':

'; +$table->data[2][0] .= '
'.html_print_select( + $integria_status_values, + 'status', + $input_value_status, + '', + __('Select'), + 1, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[1][1] = '

'.__('Group').':

'; +$table->data[1][1] .= '
'.html_print_select( + $integria_group_values, + 'group', + $input_value_group, + '', + '', + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][1] = '

'.__('Creator').':

'; +$table->data[2][1] .= '
'.html_print_input_text( + 'creator', + $config['integria_user'], + '', + '30', + 100, + true, + true, + false, + '', + 'w100p' +).ui_print_help_tip(__('This field corresponds to the Integria IMS user specified in Integria IMS setup'), true).'
'; + +$table->data[1][2] = '

'.__('Priority').':

'; +$table->data[1][2] .= '
'.html_print_select( + $integria_criticity_values, + 'criticity', + $input_value_criticity, + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][2] = '

'.__('Owner').':

'; + +$table->data[2][2] .= '
'.html_print_autocomplete_users_from_integria( + 'owner', + $input_value_owner, + true +).'
'; + +$table->data[3][0] = '

'.__('Description').': '.$help_macros.'

'; +$table->data[3][0] .= '
'.html_print_textarea( + 'incident_content', + 3, + 20, + $input_value_content, + '', + true +).'
'; + +// Print forms and stuff. +echo '
'; +html_print_table($table); + +if (!$update) { + html_print_input_hidden('create_incident', 1); +} else { + html_print_input_hidden('update_incident', 1); +} + +echo '
'; + +echo '
'; +if ($update) { + html_print_submit_button(__('Update'), 'accion', false, 'form="create_integria_incident_form" class="sub wand"'); +} else { + html_print_submit_button(__('Create'), 'accion', false, 'form="create_integria_incident_form" class="sub wand"'); +} + +echo '
'; diff --git a/pandora_console/operation/incidents/dashboard_detail_integriaims_incident.php b/pandora_console/operation/incidents/dashboard_detail_integriaims_incident.php new file mode 100644 index 0000000000..aab95b4cd7 --- /dev/null +++ b/pandora_console/operation/incidents/dashboard_detail_integriaims_incident.php @@ -0,0 +1,488 @@ +width = '100%'; +$table_files_section->id = 'files_section_table'; +$table_files_section->class = 'databox filters'; +$table_files_section->head = []; + +$table_files_section->data = []; +$table_files_section->size = []; +$table_files_section->colspan[2][0] = 3; + +// Files list table. +$table_files = new stdClass(); +$table_files->width = '100%'; +$table_files->class = 'info_table'; +$table_files->head = []; + +$table_files->head[0] = __('Filename'); +$table_files->head[1] = __('Timestamp'); +$table_files->head[2] = __('Description'); +$table_files->head[3] = __('User'); +$table_files->head[4] = __('Size'); + +if (check_acl($config['id_user'], 0, 'IW')) { + $table_files->head[5] = __('Delete'); +} + +$table_files->data = []; + +// Upload file. +if ($upload_file && ($_FILES['userfile']['name'] != '')) { + $filedescription = get_parameter('file_description', __('No description available')); + + $filename = io_safe_input($_FILES['userfile']['name']); + $filesize = io_safe_input($_FILES['userfile']['size']); + + $extension = pathinfo($filename, PATHINFO_EXTENSION); + $invalid_extensions = '/^(bat|exe|cmd|sh|php|php1|php2|php3|php4|php5|pl|cgi|386|dll|com|torrent|js|app|jar|iso| + pif|vb|vbscript|wsf|asp|cer|csr|jsp|drv|sys|ade|adp|bas|chm|cpl|crt|csh|fxp|hlp|hta|inf|ins|isp|jse|htaccess| + htpasswd|ksh|lnk|mdb|mde|mdt|mdw|msc|msi|msp|mst|ops|pcd|prg|reg|scr|sct|shb|shs|url|vbe|vbs|wsc|wsf|wsh)$/i'; + + if (!preg_match($invalid_extensions, $extension)) { + // The following is if you have clamavlib installed. + // (php5-clamavlib) and enabled in php.ini + // http://www.howtoforge.com/scan_viruses_with_php_clamavlib + if (extension_loaded('clamav')) { + cl_setlimits(5, 1000, 200, 0, 10485760); + $malware = cl_scanfile($_FILES['file']['tmp_name']); + if ($malware) { + $error = 'Malware detected: '.$malware.'
ClamAV version: '.clam_get_version(); + die($error); + // On malware, we die because it's not good to handle it + } + } + + $filecontent = base64_encode(file_get_contents($_FILES['userfile']['tmp_name'])); + + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'attach_file', [$incident_id, $filename, $filesize, $filedescription, $filecontent]); + + // API method returns '0' string if success. + $file_added = ($result_api_call === '0') ? true : false; + + ui_print_result_message( + $file_added, + __('File successfully added'), + __('File could not be added') + ); + } else { + ui_print_error_message(__('File has an invalid extension')); + } +} + +// Delete file. +if (isset($_GET['delete_file'])) { + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'delete_file', [$delete_file_id]); + + $file_deleted = false; + + if ($result_api_call === '0') { + $file_deleted = true; + } + + ui_print_result_message( + $file_deleted, + __('File successfully deleted'), + __('File could not be deleted') + ); +} + +// Download file. +if (isset($_GET['download_file'])) { + $file_base64 = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'download_file', [$download_file_id]); + ob_end_clean(); + + $decoded = base64_decode($file_base64); + + file_put_contents($download_file_name, $decoded); + ob_end_clean(); + + if (file_exists($download_file_name)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="'.basename($download_file_name).'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: '.filesize($download_file_name)); + ob_end_clean(); + readfile($download_file_name); + unlink($download_file_name); + exit; + } + + header('Location: index.php?sec=incident&sec2=operation/incidents/dashboard_detail_integriaims_incident&incident_id='.$incident_id); +} + +// Retrieve files belonging to incident and create list table. +$result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_files', [$incident_id]); + +if ($result_api_call != false && strlen($result_api_call) > 0) { + $files = []; + $csv_array = explode("\n", $result_api_call); + + foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $files[] = explode(',', $csv_line); + } + } +} + +$i = 0; + +foreach ($files as $key => $value) { + $table_files->data[$i][0] = ''.$value[11].''; + $table_files->data[$i][1] = $value[14]; + $table_files->data[$i][2] = $value[12]; + $table_files->data[$i][3] = $value[8]; + $table_files->data[$i][4] = $value[13]; + if (check_acl($config['id_user'], 0, 'IW')) { + $table_files->data[$i][5] .= ''; + $table_files->data[$i][5] .= html_print_image('images/cross.png', true, ['title' => __('Delete')]); + } + + $table_files->data[$i][5] .= ''; + + $i++; +} + +$table_files_section->data[0][0] = '

'.__('File name').':

'; +$table_files_section->data[0][0] .= html_print_input_file('userfile', true); +$table_files_section->data[1][0] = '

'.__('Description').':

'; +$table_files_section->data[1][0] .= html_print_textarea( + 'file_description', + 3, + 20, + '', + '', + true +); + +$table_files_section->data[2][0] .= '
'.html_print_submit_button(__('Upload'), 'accion', false, 'class="sub wand"', true).'
'; + +$upload_file_form = '
'; + +if (check_acl($config['id_user'], 0, 'IW')) { + $upload_file_form .= '
'.'

'.__('Add attachment').'

'.html_print_table($table_files_section, true).html_print_input_hidden('upload_file', 1, true); +} + +$upload_file_form .= '

'.__('Attached files').'

'.html_print_table($table_files, true).'
'; + +// Incident comments management. +$upload_comment = get_parameter('upload_comment'); +$comment_description = get_parameter('comment_description'); + +// Comments section table. +$table_comments_section = new stdClass(); +$table_comments_section->width = '100%'; +$table_comments_section->id = 'files_section_table'; +$table_comments_section->class = 'databox filters'; +$table_comments_section->head = []; + +$table_comments_section->data = []; +$table_comments_section->size = []; + +// Comments list table. +$table_comments = new stdClass(); +$table_comments->width = '100%'; +$table_comments->class = 'info_table'; +$table_comments->head = []; + +$table_comments->head[0] = __('Filename'); +$table_comments->head[1] = __('Timestamp'); +$table_comments->head[2] = __('Description'); +$table_comments->head[3] = __('User'); +$table_comments->head[4] = __('Size'); +$table_comments->head[5] = __('Delete'); + +$table_comments->data = []; + +$comment_disabled = ($array_get_incidents[6] == 7); + +if ($comment_disabled === true) { + $attribute = 'disabled=disabled'; +} + +$table_comments_section->data[0][0] = '

'.__('Description').':

'; +$table_comments_section->data[0][0] .= html_print_textarea( + 'comment_description', + 3, + 20, + '', + $attribute, + true +); + +$table_comments_section->data[1][1] .= '
'.html_print_submit_button(__('Add'), 'accion', $comment_disabled, 'class="sub wand"', true).'
'; + +// Upload comment. If ticket is closed, this action cannot be performed. +if ($upload_comment && $array_get_incidents[6] != 7) { + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'create_workunit', [$incident_id, $comment_description, '0.00', 0, 1, '0']); + + // API method returns id of new comment if success. + $comment_added = ($result_api_call >= '0') ? true : false; + + ui_print_result_message( + $comment_added, + __('Comment successfully added'), + __('Comment could not be added') + ); +} + +// Retrieve comments belonging to incident and create comments table. +$result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_workunits', [$incident_id]); + +if ($result_api_call != false && strlen($result_api_call) > 0) { + $comments = []; + $csv_array = explode("\n", $result_api_call); + + foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $comments[] = explode(',', $csv_line); + } + } +} + +$comment_table = ''; + +if (!empty($comments)) { + foreach ($comments as $key => $value) { + $comment_table .= '
'.$value[3].' said '.$value[1].''.$value[2].' Hours
'; + $comment_table .= '
'.$value[4].'
'; + } +} else { + $comment_table = __('No comments found'); +} + +$upload_comment_form = '
'; + +if (check_acl($config['id_user'], 0, 'IW')) { + $upload_comment_form .= '

'.__('Add comment').'

'.html_print_table($table_comments_section, true).html_print_input_hidden('upload_comment', 1, true).'
'; +} + +$upload_comment_form .= '

'.__('Comments').'

'.$comment_table.'
'; + +// Details box. +$details_box = '
'; +$details_box .= ' +
'.__('Status').'
+
'.__('Resolution').'
+
'.__('Group').'
+
'.__('Priority').'
+
'.__('Type').'
'; +$details_box .= ' +
'.html_print_image('images/heart.png', true).'
+
'.html_print_image('images/builder.png', true).'
+
'.html_print_image('images/user_green.png', true).'
+
'.ui_print_integria_incident_priority($priority, $priority_text).'
+
'.html_print_image('images/incidents.png', true).'
'; +$details_box .= ' +
'.$status_text.'
+
'.$resolution_text.'
+
'.$group_text.'
+
'.$priority_text.'
+
'.$type_text.'
'; +$details_box .= '
'; + + +// People box. +$people_box = '
'; +$people_box .= ' +
'.html_print_image('images/header_user_green.png', true, ['width' => '21']).'
+
'.html_print_image('images/header_user_green.png', true, ['width' => '21']).'
+
'.html_print_image('images/header_user_green.png', true, ['width' => '21']).'
'; +$people_box .= ' +
'.__('Created by').':
+
'.__('Owned by').':
+
'.__('Closed by').':
'; +$people_box .= ' +
'.$creator.'
+
'.$owner.'
+
'.$closed_by.'
'; +$people_box .= '
'; + + +// Dates box. +$dates_box = '
'; +$dates_box .= ' +
'.html_print_image('images/tick.png', true).'
+
'.html_print_image('images/update.png', true, ['width' => '21']).'
+
'.html_print_image('images/mul.png', true).'
'; +$dates_box .= ' +
'.__('Created at').':
+
'.__('Updated at').':
+
'.__('Closed at').':
'; +$dates_box .= ' +
'.$created_at.'
+
'.$updated_at.'
+
'.$closed_at.'
'; +$dates_box .= '
'; + + +// Show details, people and dates. +echo '
'; + ui_toggle($details_box, __('Details'), '', 'details_box', false, false, '', 'integria_details_content white-box-content', 'integria_details_shadow box-shadow white_table_graph'); + ui_toggle($people_box, __('People'), '', 'people_box', false, false, '', 'integria_details_content white-box-content', 'integria_details_shadow box-shadow white_table_graph'); + ui_toggle($dates_box, __('Dates'), '', 'dates_box', false, false, '', 'integria_details_content white-box-content', 'integria_details_shadow box-shadow white_table_graph'); +echo '
'; + + // Show description. +$description_box = '
'.html_print_textarea( + 'integria_details_description', + 3, + 0, + $description, + 'disabled="disabled"', + true +).'
'; +ui_toggle($description_box, __('Description'), '', '', false); + +echo '
'; +ui_toggle( + $upload_file_form, + __('Attached files'), + '', + '', + true, + false, + 'white_box white_box_opened', + 'no-border flex' +); +echo '
'; + +echo '
'; +ui_toggle( + $upload_comment_form, + __('Comments'), + '', + '', + true, + false, + 'white_box white_box_opened', + 'no-border flex' +); +echo '
'; + +?> + \ No newline at end of file diff --git a/pandora_console/operation/incidents/integriaims_export_csv.php b/pandora_console/operation/incidents/integriaims_export_csv.php new file mode 100644 index 0000000000..03a038e58a --- /dev/null +++ b/pandora_console/operation/incidents/integriaims_export_csv.php @@ -0,0 +1,129 @@ + $value) { + // Status. + if ($tickets_csv_array[$key][6] == 0) { + $tickets_csv_array[$key][6] = 'None'; + } else { + $tickets_csv_array[$key][6] = $status_incident[$tickets_csv_array[$key][6]]; + } + + // Priority. + $tickets_csv_array[$key][7] = $priority_incident[$tickets_csv_array[$key][7]]; + + // Group. + $tickets_csv_array[$key][8] = $group_incident[$tickets_csv_array[$key][8]]; + + // Resolution. + if ($tickets_csv_array[$key][12] == 0) { + $tickets_csv_array[$key][12] = 'None'; + } else { + $tickets_csv_array[$key][12] = $resolution_incident[$tickets_csv_array[$key][12]]; + } + + $tickets_csv_array_filter[$key] = [ + 'id_incidencia' => $tickets_csv_array[$key][0], + 'titulo' => $tickets_csv_array[$key][3], + 'id_grupo' => $tickets_csv_array[$key][8], + 'estado' => $tickets_csv_array[$key][6], + 'resolution' => $tickets_csv_array[$key][12], + 'prioridad' => $tickets_csv_array[$key][7], + 'actualizacion' => $tickets_csv_array[$key][9], + 'inicio' => $tickets_csv_array[$key][1], + 'id_creator' => $tickets_csv_array[$key][10], + 'owner' => $tickets_csv_array[$key][5], + ]; +} + +// Header for CSV file. +$header = [ + __('ID Ticket'), + __('Title'), + __('Group/Company'), + __('Status'), + __('Resolution'), + __('Priority'), + __('Updated'), + __('Started'), + __('Creator'), + __('Owner'), +]; + +$header_csv = ''; +foreach ($header as $key => $value) { + $header_csv .= $value.','; +} + +$header_csv = io_safe_output($header_csv).PHP_EOL; + + +// Join header and content. +$tickets_csv = ''; +foreach ($tickets_csv_array_filter as $key => $value) { + $tickets_csv .= implode(',', $tickets_csv_array_filter[$key]).PHP_EOL; +} + +$tickets_csv = $header_csv.$tickets_csv; + + +// Create csv file. +$filename = 'tickets_export-'.date('Ymd').'-'.date('His').'.csv'; + +ob_clean(); + +header('Content-Type: text/csv; charset=utf-8'); +header('Content-Disposition: attachment; filename='.$filename); + +// BOM. +echo pack('C*', 0xEF, 0xBB, 0xBF); + +// CSV file. +echo io_safe_output($tickets_csv); diff --git a/pandora_console/operation/incidents/list_integriaims_incidents.php b/pandora_console/operation/incidents/list_integriaims_incidents.php new file mode 100644 index 0000000000..d97276c15e --- /dev/null +++ b/pandora_console/operation/incidents/list_integriaims_incidents.php @@ -0,0 +1,335 @@ +width = '100%'; +$table->class = 'databox filters'; +$table->styleTable = 'margin-bottom:0px'; +$table->cellpadding = '0'; +$table->cellspacing = '0'; +$table->data = []; + +$table->data[0][0] = __('Text filter'); +$table->data[0][1] = html_print_input_text('incident_text', $incident_text, '', 30, 100, true); + +$table->data[0][2] = __('Status'); +$table->data[0][3] = html_print_select( + $status_incident, + 'incident_status', + $incident_status, + '', + __('All'), + 0, + true +); + +$table->data[0][4] = __('Group'); +$table->data[0][5] = html_print_select( + $group_incident, + 'incident_group', + $incident_group, + '', + __('All'), + 1, + true +); + +$table->data[1][0] = __('Owner'); +$table->data[1][1] = html_print_autocomplete_users_from_integria('incident_owner', $incident_owner, true); + +$table->data[1][2] = __('Creator'); +$table->data[1][3] = html_print_autocomplete_users_from_integria('incident_creator', $incident_creator, true); + +$table->data[1][4] = __('Priority'); +$table->data[1][5] = html_print_select( + $priority_incident, + 'incident_priority', + $incident_priority, + '', + __('All'), + -1, + true +); + +$table->data[2][0] = __('Resolution'); +$table->data[2][1] = html_print_select( + $resolution_incident, + 'incident_resolution', + $incident_resolution, + '', + __('All'), + '', + true +); + +// TODO: field type date. +$table->data[2][2] = __('Date'); +$table->data[2][3] = html_print_input_text_extended( + 'created_from', + $created_from, + 'created_from', + '', + 12, + 50, + false, + '', + 'placeholder="'.__('Created from').'"', + true +); +$table->data[2][3] .= html_print_input_text_extended( + 'created_to', + $created_to, + 'created_to', + '', + 12, + 50, + false, + '', + 'style="margin-left:5px;" placeholder="'.__('Created to').'"', + true +); + +// TODO: image of Integria IMS. +$table->data[2][4] = ''; +$table->data[2][5] = ''; + + +// Send filters to get_tickets_integriaims(). +$tickets_filters = [ + 'incident_text' => $incident_text, + 'incident_status' => $incident_status, + 'incident_group' => $incident_group, + 'incident_owner' => $incident_owner, + 'incident_creator' => $incident_creator, + 'incident_priority' => $incident_priority, + 'incident_resolution' => $incident_resolution, + 'created_from' => $created_from, + 'created_to' => $created_to, +]; + +// Data to export to csv file. +$decode_csv = base64_encode(json_encode($tickets_filters)); + + +// ---- PRINT TABLE FILTERS ---- +$integria_incidents_form = '
'; +$integria_incidents_form .= html_print_table($table, true); +$integria_incidents_form .= '
'; +$integria_incidents_form .= '
'.html_print_button( + __('Export to CSV'), + 'csv_export', + false, + "location.href='operation/incidents/integriaims_export_csv.php?tickets_filters=$decode_csv'", + 'class="sub next"', + true +).'
'; +$integria_incidents_form .= '
'.html_print_submit_button(__('Filter'), 'filter_button', false, 'class="sub filter"', true).'
'; +$integria_incidents_form .= '
'; +$integria_incidents_form .= '
'; + +ui_toggle($integria_incidents_form, __('Filter'), '', '', false); + +/* + * Order api call 'get_incidents'. + * + * resolution = $array_get_incidents[$key][12] + * id_incidencia = $array_get_incidents[$key][0] + * titulo = $array_get_incidents[$key][3] + * id_grupo = $array_get_incidents[$key][8] + * estado = $array_get_incidents[$key][6] + * prioridad = $array_get_incidents[$key][7] + * actualizacion = $array_get_incidents[$key][9] + * id_creator = $array_get_incidents[$key][10] + * + */ + +// ---- LIST OF INCIDENTS ---- +// Get list of incidents. +$array_get_incidents = get_tickets_integriaims($tickets_filters); + +// Prepare pagination. +$incidents_limit = $config['block_size']; +$incidents_paginated = array_slice($array_get_incidents, $offset, $incidents_limit, true); + +// TABLE INCIDENTS. +$table = new stdClass(); +$table->width = '100%'; +$table->class = 'info_table'; +$table->head = []; + +$table->head[0] = __('ID'); +$table->head[1] = __('Ticket'); +$table->head[2] = __('Group/Company'); +$table->head[3] = __('Status/Resolution'); +$table->head[4] = __('Prior'); +$table->head[5] = __('Updated/Started'); +$table->head[6] = __('Creator'); +$table->head[7] = __('Owner'); +if (check_acl($config['id_user'], 0, 'IW') || check_acl($config['id_user'], 0, 'IM')) { + $table->head[8] = ''; +} + +$table->data = []; +$i = 0; + +foreach ($incidents_paginated as $key => $value) { + if ($array_get_incidents[$key][6] == 0) { + $status_incident[$array_get_incidents[$key][6]] = __('None'); + } + + if ($array_get_incidents[$key][12] == 0) { + $resolution_incident[$array_get_incidents[$key][12]] = __('None'); + } + + $table->data[$i][0] = '#'.$array_get_incidents[$key][0]; + $table->data[$i][1] = ''; + $table->data[$i][1] .= $array_get_incidents[$key][3]; + $table->data[$i][1] .= ''; + $table->data[$i][2] = $group_incident[$array_get_incidents[$key][8]]; + $table->data[$i][3] = $status_incident[$array_get_incidents[$key][6]].' / '.$resolution_incident[$array_get_incidents[$key][12]]; + $table->data[$i][4] = ui_print_integria_incident_priority($array_get_incidents[$key][7], $priority_incident[$array_get_incidents[$key][7]]); + $table->data[$i][5] = $array_get_incidents[$key][9].' / '.$array_get_incidents[$key][1]; + $table->data[$i][6] = $array_get_incidents[$key][10]; + $table->data[$i][7] = $array_get_incidents[$key][5]; + $table->data[$i][8] = ''; + $table->cellclass[$i][8] = 'action_buttons'; + if (check_acl($config['id_user'], 0, 'IW')) { + $table->data[$i][8] .= ''; + $table->data[$i][8] .= html_print_image('images/config.png', true, ['title' => __('Edit')]); + $table->data[$i][8] .= ''; + } + + if (check_acl($config['id_user'], 0, 'IM')) { + $table->data[$i][8] .= ''; + $table->data[$i][8] .= html_print_image('images/cross.png', true, ['title' => __('Delete')]); + $table->data[$i][8] .= ''; + } + + $i++; +} + +// Show table incidents. +ui_pagination(count($array_get_incidents), $url, $offset); +if (empty($table->data) === true) { + ui_print_info_message(['no_close' => true, 'message' => __('No tickets to show').'.' ]); +} else { + html_print_table($table); + ui_pagination(count($array_get_incidents), $url, $offset, 0, false, 'offset', true, 'pagination-bottom'); +} + +// Show button to create incident. +if (check_acl($config['id_user'], 0, 'IR')) { + echo '
'; + echo '
'; + html_print_submit_button(__('Create'), 'create_new_incident', false, 'class="sub next"'); + echo '
'; + echo '
'; +} + +// Datapicker library for show calendar. +ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/'); +?> + + + \ No newline at end of file diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 936cb6a814..58213ed8ee 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -479,6 +479,7 @@ if (check_acl($config['id_user'], 0, 'IR') $sub2 = []; $sub2['operation/incidents/incident']['text'] = __('List of Incidents'); $sub2[$sec2sub]['text'] = __('Statistics'); + $sub2['operation/incidents/list_integriaims_incidents']['text'] = __('Integria IMS Tickets'); $sub[$sec2]['sub2'] = $sub2; $sec2 = $temp_sec2; diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index e25c49aa2f..4170f62045 100644 --- a/pandora_console/pandora_console.redhat.spec +++ b/pandora_console/pandora_console.redhat.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.738 -%define release 190924 +%define version 7.0NG.739 +%define release 190927 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.rhel7.spec b/pandora_console/pandora_console.rhel7.spec index 13fc340121..e317811dd0 100644 --- a/pandora_console/pandora_console.rhel7.spec +++ b/pandora_console/pandora_console.rhel7.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.738 -%define release 190924 +%define version 7.0NG.739 +%define release 190927 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec index c56f8c41c9..b474f27d89 100644 --- a/pandora_console/pandora_console.spec +++ b/pandora_console/pandora_console.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.738 -%define release 190924 +%define version 7.0NG.739 +%define release 190927 %define httpd_name httpd # User and Group under which Apache is running %define httpd_name apache2 diff --git a/pandora_console/pandora_console_install b/pandora_console/pandora_console_install index bda06177d6..9ed0bd594a 100644 --- a/pandora_console/pandora_console_install +++ b/pandora_console/pandora_console_install @@ -9,7 +9,7 @@ # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.738" +PI_VERSION="7.0NG.739" FORCE=0 DESTDIR="" LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 01f069b8b6..686f4aa487 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -109,14 +109,36 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_report_front_logo', 'images/pandora_logo_white.jpg'), ('custom_report_front_header', ''), ('custom_report_front_footer', ''), -('MR', 31), +('MR', 32), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), -('current_package_enterprise', '738'), +('current_package_enterprise', '739'), ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'), ('custom_docs_logo', 'default_docs.png'), ('custom_support_logo', 'default_support.png'), -('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'); +('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'), +('integria_enabled', 0), +('integria_user', ''), +('integria_pass', ''), +('integria_hostname', ''), +('integria_api_pass', ''), +('integria_req_timeout', 5), +('default_group', ''), +('default_criticity', ''), +('default_creator', ''), +('default_owner', ''), +('incident_type', ''), +('incident_status', ''), +('incident_title', ''), +('incident_content', ''), +('cr_default_group', ''), +('cr_default_criticity', ''), +('cr_default_creator', ''), +('cr_default_owner', ''), +('cr_incident_type', ''), +('cr_incident_status', ''), +('cr_incident_title', ''), +('cr_incident_content', ''); UNLOCK TABLES; -- diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index 7cd9b0c5cd..9e11f8049e 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 7.0NG.738-190924 +Version: 7.0NG.739-190927 Architecture: all Priority: optional Section: admin diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh index 79c391dbb1..a943240231 100644 --- a/pandora_server/DEBIAN/make_deb_package.sh +++ b/pandora_server/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.738-190924" +pandora_version="7.0NG.739-190927" package_cpan=0 package_pandora=1 diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index 6d92d7417d..3aa61de07f 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -1,7 +1,7 @@ ############################################################################# # Pandora FMS Server Parameters # Pandora FMS, the Flexible Monitoring System. -# Version 7.0NG.738 +# Version 7.0NG.739 # Licensed under GPL license v2, # (c) 2003-2017 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 20934859c7..0765908d81 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -44,8 +44,8 @@ our @EXPORT = qw( ); # version: Defines actual version of Pandora Server for this module only -my $pandora_version = "7.0NG.738"; -my $pandora_build = "190924"; +my $pandora_version = "7.0NG.739"; +my $pandora_build = "190927"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash @@ -357,7 +357,15 @@ sub pandora_load_config { # Xprobe2 for recon OS fingerprinting and tcpscan (optional) $pa_config->{"xprobe2"} = "/usr/bin/xprobe2"; + # Winexe allows to exec commands on remote windows systems (optional) + $pa_config->{"winexe"} = "/usr/bin/winexe"; + + # PsExec allows to exec commands on remote windows systems from windows servers (optional) + $pa_config->{"psexec"} = 'C:\PandoraFMS\Pandora_Server\bin\PsExec.exe'; + # plink allows to exec commands on remote linux systems from windows servers (optional) + $pa_config->{"plink"} = 'C:\PandoraFMS\Pandora_Server\bin\plink.exe'; + # Snmpget for snmpget system command (optional) $pa_config->{"snmpget"} = "/usr/bin/snmpget"; @@ -838,6 +846,15 @@ sub pandora_load_config { elsif ($parametro =~ m/^xprobe2\s(.*)/i) { $pa_config->{'xprobe2'}= clean_blank($1); } + elsif ($parametro =~ m/^winexe\s(.*)/i) { + $pa_config->{'winexe'}= clean_blank($1); + } + elsif ($parametro =~ m/^psexec\s(.*)/i) { + $pa_config->{'psexec'}= clean_blank($1); + } + elsif ($parametro =~ m/^plink\s(.*)/i) { + $pa_config->{'plink'}= clean_blank($1); + } elsif ($parametro =~ m/^snmpget\s(.*)/i) { $pa_config->{'snmpget'}= clean_blank($1); } diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 667cd7c909..644b983a5c 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1137,7 +1137,9 @@ sub pandora_execute_action ($$$$$$$$$;$) { load_module_macros ($module->{'module_macros'}, \%macros); } - # User defined alerts + + #logger($pa_config, "Clean name ".$clean_name, 10); + # User defined alert if ($action->{'internal'} == 0) { $macros{_field1_} = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); $macros{_field2_} = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module); @@ -1442,55 +1444,70 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Integria IMS Ticket } elsif ($clean_name eq "Integria IMS Ticket") { + my $config_api_path = pandora_get_tconfig_token ($dbh, 'integria_hostname', ''); + my $config_api_pass = pandora_get_tconfig_token ($dbh, 'integria_api_pass', ''); + my $config_integria_user = pandora_get_tconfig_token ($dbh, 'integria_user', ''); + my $config_integria_user_pass = pandora_get_tconfig_token ($dbh, 'integria_pass', ''); $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); + $field2 = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module); $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module); + $field4 = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module); $field5 = subst_alert_macros ($field5, \%macros, $pa_config, $dbh, $agent, $module); + $field6 = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module); $field7 = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module); - $field8 = subst_alert_macros ($field8, \%macros, $pa_config, $dbh, $agent, $module); - $field9 = subst_alert_macros ($field9, \%macros, $pa_config, $dbh, $agent, $module); - $field10 = subst_alert_macros ($field10, \%macros, $pa_config, $dbh, $agent, $module); - + # Field 1 (Integria IMS API path) - my $api_path = $field1; + my $api_path = $config_api_path . "/integria/include/api.php"; # Field 2 (Integria IMS API pass) - my $api_pass = $field2; + my $api_pass = $config_api_pass; # Field 3 (Integria IMS user) - my $integria_user = $field3; + my $integria_user = $config_integria_user; # Field 4 (Integria IMS user password) - my $integria_user_pass = $field4; + my $integria_user_pass = $config_integria_user_pass; - # Field 5 (Ticket name) - my $ticket_name = $field5; + # Field 1 (Ticket name) + my $ticket_name = safe_output($field1); if ($ticket_name eq "") { $ticket_name = $pa_config->{'rb_product_name'} . " alert action created by API"; } - # Field 6 (Ticket group ID) - my $ticket_group_id = $field6; + # Field 2 (Ticket group ID) + my $ticket_group_id = $field2; if ($ticket_group_id eq '') { $ticket_group_id = 0; } - # Field 7 (Ticket priority); - my $ticket_priority = $field7; - if ($ticket_priority eq '') { - $ticket_priority = 0; + # Field 3 (Ticket priority); + my $ticket_priority = $field3; + if ($ticket_priority eq '0') { + $ticket_priority = 1; + } + + # Field 4 (Ticket owner) + my $ticket_owner = $field4; + if ($ticket_owner eq '') { + $ticket_owner = 'admin'; } - # Field 8 (Ticket email) - my $ticket_email = $field8; - - # Field 9 (Ticket owner) - my $ticket_owner = $field9; - - # Field 10 (Ticket description); - my $ticket_description = $field10; + # Field 5 (Ticket type) + my $ticket_type = $field5; + if ($ticket_type eq '') { + $ticket_type = 0; + } - pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_email, $ticket_owner, $ticket_description); + # Field 6 (Ticket status) + my $ticket_status = $field6; + if ($ticket_status eq '0') { + $ticket_status = 1; + } + # Field 7 (Ticket description); + my $ticket_description = safe_output($field7); + + pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_owner, $ticket_type, $ticket_status, $ticket_description); # Generate notification } elsif ($clean_name eq "Generate Notification") { @@ -5849,55 +5866,21 @@ sub pandora_edit_custom_graph ($$$$$$$$$$$) { } sub pandora_create_integria_ticket ($$$$$$$$$$$) { - my ($pa_config,$api_path,$api_pass,$integria_user,$user_pass,$ticket_name,$group_id,$ticket_priority,$ticket_email,$ticket_owner,$ticket_description) = @_; - + my ($pa_config,$api_path,$api_pass,$integria_user,$user_pass,$ticket_name,$ticket_group_id,$ticket_priority,$ticket_owner,$ticket_type,$ticket_status,$ticket_description) = @_; + my $data_ticket; my $call_api; - if ($api_path eq "") { - return 0; - } - if ($user_pass eq "") { - return 0; - } - if ($integria_user eq "") { - $integria_user = "admin"; - } - if ($ticket_name eq "") { - $ticket_name = "Ticket created by " . $pa_config->{'rb_product_name'}; - } - if ($group_id eq "") { - $group_id = 1; - } - if ($ticket_priority eq "") { - $ticket_priority = 1; - } - if ($ticket_owner eq "") { - $ticket_owner = "admin"; - } - - #~ $data_ticket = $ticket_name . - #~ "|;|" . $group_id . - #~ "|;|" . $ticket_priority . - #~ "|;|" . $ticket_description . - #~ "|;|" . #Id inventory - #~ "|;|" . #Id incident type - #~ "|;|" . $ticket_email . - #~ "|;|" . $ticket_owner . - #~ "|;|" . #Father ticket id - #~ "|;|" . #Status - #~ "|;|" . #Extra info - #~ "|;|"; #Resolution $data_ticket = $ticket_name . - "|;|" . $group_id . + "|;|" . $ticket_group_id . "|;|" . $ticket_priority . "|;|" . $ticket_description . "|;|" . - "|;|" . - "|;|" . $ticket_email . + "|;|" . $ticket_type . + "|;|" . "|;|" . $ticket_owner . "|;|" . - "|;|" . '1' . + "|;|" . $ticket_status . "|;|" . "|;|"; @@ -5908,9 +5891,9 @@ sub pandora_create_integria_ticket ($$$$$$$$$$$) { 'op=create_incident&' . 'params=' . $data_ticket .'&' . 'token=|;|'; - logger($pa_config, "Integria ticket call:" . $call_api . "", 3); + my $content = get($call_api); - logger($pa_config, "Integria ticket res:" . $content . "", 3); + if (is_numeric($content) && $content ne "-1") { return $content; } diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 6f7eab4c68..b2d8e71619 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -343,6 +343,9 @@ sub exec_recon_script ($$$) { sub PandoraFMS::Recon::Base::guess_os($$) { my ($self, $device) = @_; + $DEVNULL = '/dev/null' if (!defined($DEVNULL)); + $DEVNULL = '/NUL' if ($^O =~ /win/i && !defined($DEVNULL)); + # OS detection disabled. Use the device type. if ($self->{'os_detection'} == 0) { my $device_type = $self->get_device_type($device); @@ -354,17 +357,20 @@ sub PandoraFMS::Recon::Base::guess_os($$) { } # Use xprobe2 if available - if (-e $self->{pa_config}->{xprobe2}) { - my $output = `"$self->{pa_config}->{xprobe2}" $device 2>$DEVNULL | grep 'Running OS' | head -1`; + if (-x $self->{'pa_config'}->{'xprobe2'}) { + my $return = `"$self->{pa_config}->{xprobe2}" $device 2>$DEVNULL`; if ($? == 0) { + my ($output) = $a =~ /Running OS:(.*)/; return pandora_get_os($self->{'dbh'}, $output); } } # Use nmap by default - if (-e $self->{pa_config}->{nmap}) { - my $output = `"$self->{pa_config}->{nmap}" -F -O $device 2>$DEVNULL | grep 'Aggressive OS guesses'`; + if (-x $self->{'pa_config'}->{'nmap'}) { + my $return = `"$self->{pa_config}->{nmap}" -F -O $device 2>$DEVNULL`; return OS_OTHER if ($? != 0); + + my ($output) = $return =~ /Aggressive OS guesses:\s*(.*)/; return pandora_get_os($self->{'dbh'}, $output); } @@ -377,7 +383,11 @@ sub PandoraFMS::Recon::Base::guess_os($$) { sub PandoraFMS::Recon::Base::tcp_scan ($$) { my ($self, $host) = @_; - my $open_ports = `"$self->{pa_config}->{nmap}" -p$self->{recon_ports} $host | grep open | wc -l`; + my $r = `"$self->{pa_config}->{nmap}" -p$self->{recon_ports} $host`; + + # Same as ""| grep open | wc -l" but multi-OS; + my $open_ports = () = $r =~ /open/gm; + return $open_ports; } diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index d96e359a76..81cef73c05 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -31,8 +31,8 @@ use base 'Exporter'; our @ISA = qw(Exporter); # version: Defines actual version of Pandora Server for this module only -my $pandora_version = "7.0NG.738"; -my $pandora_build = "190924"; +my $pandora_version = "7.0NG.739"; +my $pandora_build = "190927"; our $VERSION = $pandora_version." ".$pandora_build; our %EXPORT_TAGS = ( 'all' => [ qw() ] ); diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 223c36f248..335504821e 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -36,7 +36,7 @@ use constant { DISCOVERY_DEPLOY_AGENTS => 9, }; -# /dev/null +# $DEVNULL my $DEVNULL = ($^O eq 'MSWin32') ? '/Nul' : '/dev/null'; # Some useful OIDs. @@ -852,7 +852,7 @@ sub get_routes($) { $self->{'routes'} = []; # Parse route's output. - my @output = `route -n 2>/dev/null`; + my @output = `route -n 2>$DEVNULL`; foreach my $line (@output) { chomp($line); if ($line =~ /^0\.0\.0\.0\s+(\d+\.\d+\.\d+\.\d+).*/) { @@ -1220,7 +1220,7 @@ sub snmp_responds_v3($$) { sub local_arp($) { my ($self) = @_; - my @output = `arp -an 2>/dev/null`; + my @output = `arp -an 2>$DEVNULL`; foreach my $line (@output) { next unless ($line =~ m/\((\S+)\) at ([0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+)/); $self->add_mac(parse_mac($2), $1); @@ -1286,7 +1286,7 @@ sub ping ($$$) { for (my $i = 0; $i < $retries; $i++) { # Note: There is no timeout option. - `$ping_command -s -n $host 56 $packets >/dev/null 2>&1`; + `$ping_command -s -n $host 56 $packets >$DEVNULL 2>&1`; return 1 if ($? == 0); } @@ -1299,7 +1299,7 @@ sub ping ($$$) { for (my $i = 0; $i < $retries; $i++) { # Note: There is no timeout option for ping6. - `$ping_command -q -n -c $packets $host >/dev/null 2>&1`; + `$ping_command -q -n -c $packets $host >$DEVNULL 2>&1`; return 1 if ($? == 0); } @@ -1312,7 +1312,7 @@ sub ping ($$$) { for (my $i = 0; $i < $retries; $i++) { # Note: There is no timeout option for ping6. - `$ping_command -q -n -c $packets $host >/dev/null 2>&1`; + `$ping_command -q -n -c $packets $host >$DEVNULL 2>&1`; if ($? == 0) { return 1; } @@ -1324,7 +1324,7 @@ sub ping ($$$) { # Assume Linux by default. my $ping_command = $host =~ /\d+:|:\d+/ ? "ping6" : "ping"; for (my $i = 0; $i < $retries; $i++) { - `$ping_command -q -W $timeout -n -c $packets $host >/dev/null 2>&1`; + `$ping_command -q -W $timeout -n -c $packets $host >$DEVNULL 2>&1`; return 1 if ($? == 0); } @@ -1529,99 +1529,101 @@ sub app_scan($) { $self->{'task_data'} ); - if (!$dbObj->is_connected()) { - call('message', 'Cannot connect to target ' . $target, 3); - $global_percent += $global_step; - $self->{'c_network_percent'} = 90; - # Update progress - $self->call('update_progress', $global_percent + (90 / (scalar @targets))); - $self->{'summary'}->{'not_alive'} += 1; - push @modules, { - name => $type . ' connection', - type => 'generic_proc', - data => 0, - description => $type . ' availability' - }; + if (defined($dbObj)) { + if (!$dbObj->is_connected()) { + call('message', 'Cannot connect to target ' . $target, 3); + $global_percent += $global_step; + $self->{'c_network_percent'} = 90; + # Update progress + $self->call('update_progress', $global_percent + (90 / (scalar @targets))); + $self->{'summary'}->{'not_alive'} += 1; + push @modules, { + name => $type . ' connection', + type => 'generic_proc', + data => 0, + description => $type . ' availability' + }; - } else { - my $dbObjCfg = $dbObj->get_config(); + } else { + my $dbObjCfg = $dbObj->get_config(); - $self->{'summary'}->{'discovered'} += 1; - $self->{'summary'}->{'alive'} += 1; + $self->{'summary'}->{'discovered'} += 1; + $self->{'summary'}->{'alive'} += 1; - push @modules, { - name => $type . ' connection', - type => 'generic_proc', - data => 1, - description => $type . ' availability' - }; + push @modules, { + name => $type . ' connection', + type => 'generic_proc', + data => 1, + description => $type . ' availability' + }; - # Analyze. - $self->{'step'} = STEP_STATISTICS; - $self->{'c_network_percent'} = 30; - $self->call('update_progress', $global_percent + (30 / (scalar @targets))); - $self->{'c_network_name'} = $dbObj->get_host(); + # Analyze. + $self->{'step'} = STEP_STATISTICS; + $self->{'c_network_percent'} = 30; + $self->call('update_progress', $global_percent + (30 / (scalar @targets))); + $self->{'c_network_name'} = $dbObj->get_host(); - # Retrieve connection statistics. - # Retrieve uptime statistics - # Retrieve query stats - # Retrieve connections - # Retrieve innodb - # Retrieve cache - $self->{'c_network_percent'} = 50; - $self->call('update_progress', $global_percent + (50 / (scalar @targets))); - push @modules, $dbObj->get_statistics(); + # Retrieve connection statistics. + # Retrieve uptime statistics + # Retrieve query stats + # Retrieve connections + # Retrieve innodb + # Retrieve cache + $self->{'c_network_percent'} = 50; + $self->call('update_progress', $global_percent + (50 / (scalar @targets))); + push @modules, $dbObj->get_statistics(); - # Custom queries. - $self->{'step'} = STEP_CUSTOM_QUERIES; - $self->{'c_network_percent'} = 80; - $self->call('update_progress', $global_percent + (80 / (scalar @targets))); - push @modules, $dbObj->execute_custom_queries(); + # Custom queries. + $self->{'step'} = STEP_CUSTOM_QUERIES; + $self->{'c_network_percent'} = 80; + $self->call('update_progress', $global_percent + (80 / (scalar @targets))); + push @modules, $dbObj->execute_custom_queries(); - if (defined($dbObjCfg->{'scan_databases'}) - && $dbObjCfg->{'scan_databases'} == 1) { - # Skip database scan in Oracle tasks - next if $self->{'type'} == DISCOVERY_APP_ORACLE; + if (defined($dbObjCfg->{'scan_databases'}) + && "$dbObjCfg->{'scan_databases'}" eq "1") { + # Skip database scan in Oracle tasks + next if $self->{'type'} == DISCOVERY_APP_ORACLE; - my $__data = $dbObj->scan_databases(); + my $__data = $dbObj->scan_databases(); - if (ref($__data) eq "ARRAY") { - if (defined($dbObjCfg->{'agent_per_database'}) - && $dbObjCfg->{'agent_per_database'} == 1) { - # Agent per database detected. - push @data, @{$__data}; - } else { - # Merge modules into engine agent. - my @_modules = map { - map { $_ } @{$_->{'module_data'}} - } @{$__data}; + if (ref($__data) eq "ARRAY") { + if (defined($dbObjCfg->{'agent_per_database'}) + && $dbObjCfg->{'agent_per_database'} == 1) { + # Agent per database detected. + push @data, @{$__data}; + } else { + # Merge modules into engine agent. + my @_modules = map { + map { $_ } @{$_->{'module_data'}} + } @{$__data}; - push @modules, @_modules; + push @modules, @_modules; + } } } } + + # Put engine agent at the beginning of the list. + my $version = $dbObj->get_version(); + unshift @data,{ + 'agent_data' => { + 'agent_name' => $dbObj->get_agent_name(), + 'os' => $type, + 'os_version' => (defined($version) ? $version : 'Discovery'), + 'interval' => $self->{'task_data'}->{'interval_sweep'}, + 'id_group' => $self->{'task_data'}->{'id_group'}, + 'address' => $dbObj->get_host(), + 'description' => '', + }, + 'module_data' => \@modules, + }; + + $self->call('create_agents', \@data); + + # Destroy item. + undef($dbObj); } - # Put engine agent at the beginning of the list. - my $version = $dbObj->get_version(); - unshift @data,{ - 'agent_data' => { - 'agent_name' => $dbObj->get_agent_name(), - 'os' => $type, - 'os_version' => (defined($version) ? $version : 'Discovery'), - 'interval' => $self->{'task_data'}->{'interval_sweep'}, - 'id_group' => $self->{'task_data'}->{'id_group'}, - 'address' => $dbObj->get_host(), - 'description' => '', - }, - 'module_data' => \@modules, - }; - - $self->call('create_agents', \@data); - - # Destroy item. - undef($dbObj); - $global_percent += $global_step; $self->{'c_network_percent'} = 100; $self->call('update_progress', $global_percent); @@ -1674,7 +1676,7 @@ sub deploy_scan($) { ########################################################################## sub scan($) { my ($self) = @_; - my ($progress, $step); + my ($progress, $step) = 1, 0; # 1% $self->call('update_progress', 1); @@ -1697,7 +1699,7 @@ sub scan($) { } # Find devices. - $self->call('message', "[1/5] Scanning the network...", 3); + $self->call('message', "[1/4] Scanning the network...", 3); $self->{'step'} = STEP_SCANNING; $self->call('update_progress', $progress); $self->scan_subnet(); @@ -1713,7 +1715,7 @@ sub scan($) { $self->call('delete_connections'); # Connectivity from address forwarding tables. - $self->call('message', "[1/4] Finding address forwarding table connectivity...", 3); + $self->call('message', "[2/4] Finding address forwarding table connectivity...", 3); $self->{'step'} = STEP_AFT; ($progress, $step) = (50, 20.0 / scalar(@hosts)); # From 50% to 70%. for (my $i = 0; defined($hosts[$i]); $i++) { @@ -1831,7 +1833,7 @@ sub snmp_get_command { my ($self, $device, $oid, $community, $vlan) = @_; $vlan = defined($vlan) ? "\@" . $vlan : ''; - my $command = "snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v$self->{'snmp_version'} -On -Oe "; + my $command = "snmpwalk -M$DEVNULL -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v$self->{'snmp_version'} -On -Oe "; if ($self->{'snmp_version'} eq "3") { if ($self->{'community'}) { # Context $command .= " -N $self->{'community'} "; @@ -1847,7 +1849,7 @@ sub snmp_get_command { $command .= " -c$community$vlan "; } - return "$command $device $oid 2>/dev/null"; + return "$command $device $oid 2>$DEVNULL"; } diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 715703b5b6..e07a4e9ae6 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -994,7 +994,8 @@ sub load_average { $load_average = ((split(/\s+/, `/sbin/sysctl -n vm.loadavg`))[1]); } elsif ($OSNAME eq "MSWin32") { # Windows hasn't got load average. - $load_average = undef; + $load_average = `powershell "(Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average).average"`; + chop($load_average); } # by default LINUX calls else { diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index 08a4ee2de5..caf81c57fb 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -2,8 +2,8 @@ # Pandora FMS Server # %define name pandorafms_server -%define version 7.0NG.738 -%define release 190924 +%define version 7.0NG.739 +%define release 190927 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index 089fece9fc..d7a2024451 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -2,8 +2,8 @@ # Pandora FMS Server # %define name pandorafms_server -%define version 7.0NG.738 -%define release 190924 +%define version 7.0NG.739 +%define release 190927 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 6afd51d072..a2032b8926 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -8,8 +8,8 @@ # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.738" -PI_BUILD="190924" +PI_VERSION="7.0NG.739" +PI_BUILD="190927" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/integria_rticket.pl b/pandora_server/util/integria_rticket.pl index 609dd516b0..f296fd9145 100644 --- a/pandora_server/util/integria_rticket.pl +++ b/pandora_server/util/integria_rticket.pl @@ -38,6 +38,7 @@ Where options: Optional parameters: [-priority ] : 10 Maintance, 0 Informative, 1 Low, 2 Medium, 3 Serious, 4 Very serious + [-owner ] : Free text [-desc ] : Free text [-type ] : Type ID (must exist in Integria IMS) [-inventory ] : Inventory ID (must exist in Integria IMS) @@ -94,6 +95,7 @@ sub tool_api_main () { my $ticket_name = ""; my $group_id = -1; my $ticket_priority = 0; + my $ticket_owner = ''; my $ticket_description = ''; my $ticket_type = ''; my $ticket_inventory = ''; @@ -155,6 +157,9 @@ sub tool_api_main () { if ($line eq '-priority') { $ticket_priority = $ARGV[$i + 1]; } + if ($line eq '-owner') { + $ticket_owner = $ARGV[$i + 1]; + } if ($line eq '-desc') { $ticket_description = $ARGV[$i + 1]; } @@ -193,6 +198,7 @@ sub tool_api_main () { $data_ticket = $ticket_name . "|;|" . $group_id . "|;|" . $ticket_priority . + "|;|" . $ticket_owner . "|;|" . $ticket_description . "|;|" . $ticket_inventory . "|;|" . $ticket_type . diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 0ac8ad2b9e..8a5f42f4be 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.738 PS190924"; +my $version = "7.0NG.739 PS190927"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index d82f947ef6..878ec570ad 100755 --- 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.738 PS190924"; +my $version = "7.0NG.739 PS190927"; # save program name for logging my $progname = basename($0);