diff --git a/pandora_agents/unix/FreeBSD/pandora_agent.conf b/pandora_agents/unix/FreeBSD/pandora_agent.conf index 4ea1e428eb..62fa6bdec5 100644 --- a/pandora_agents/unix/FreeBSD/pandora_agent.conf +++ b/pandora_agents/unix/FreeBSD/pandora_agent.conf @@ -39,7 +39,9 @@ udp_server_auth_address 0.0.0.0 # To define agent name by specific command, define 'agent_name_cmd'. # (In the following example, agent name is 'hostname_IP') -#agent_name_cmd /bin/echo -n `hostname` ; /bin/echo -n "_" ; /bin/echo `/sbin/ifconfig bce0 | /usr/bin/grep 'inet' | /usr/bin/awk '{print $2;}' | cut -d: -f2` +# If set to __rand__ the agent will generate a random name. +#agent_name_cmd LANG=C; /bin/echo -n `hostname`; /bin/echo -n "_"; /bin/echo `/sbin/ifconfig eth0 | /bin/grep 'inet addr' | /usr/bin/awk '{print $2;}' | /usr/bin/cut -d: -f2` +agent_name_cmd __rand__ #Parent agent_name #parent_agent_name parent_name diff --git a/pandora_agents/unix/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index a4e2a62a2c..0fbce4900c 100644 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -39,7 +39,9 @@ udp_server_auth_address 0.0.0.0 # To define agent name by specific command, define 'agent_name_cmd'. # (In the following example, agent name is 'hostname_IP') +# If set to __rand__ the agent will generate a random name. #agent_name_cmd LANG=C; /bin/echo -n `hostname`; /bin/echo -n "_"; /bin/echo `/sbin/ifconfig eth0 | /bin/grep 'inet addr' | /usr/bin/awk '{print $2;}' | /usr/bin/cut -d: -f2` +agent_name_cmd __rand__ #Parent agent_name #parent_agent_name caprica diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent old mode 100644 new mode 100755 index 755d67a476..795ea67da7 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -100,6 +100,9 @@ use constant DF_CMDS => { aix => 'df -kP', freebsd => 'df -k' }; + +# 2 to the power of 32. +use constant POW232 => 2**32; # OS and OS version my $OS = $^O; @@ -131,8 +134,9 @@ my %DefaultConf = ( 'temporal' => '/var/spool/pandora', 'interval' => 300, 'debug' => 0, + 'agent_name' => '', + 'agent_alias' => hostname(), 'ehorus_conf' => undef, - 'agent_name' => hostname (), 'agent_name_cmd' => '', 'description' => '', 'group' => '', @@ -800,17 +804,24 @@ sub read_config (;$) { parse_conf_modules(\@file); # If agent_name_cmd is defined, agent_name is set by command result. - if ($Conf{'agent_name_cmd'} ne '') { - my $result = `$Conf{'agent_name_cmd'}`; - - # Use only the first line. - my ($temp_agent_name, $remain) = split(/\n/, $result); - chomp ($temp_agent_name); - - # Remove white spaces of the first and last. - $temp_agent_name =~ s/^ *(.*?) *$/$1/; - - $Conf{'agent_name'} = $temp_agent_name if ($temp_agent_name ne ''); + if ($Conf{'agent_name'} eq '') { + if ($Conf{'agent_name_cmd'} eq '__rand__') { + $Conf{'agent_name'} = generate_agent_name(); + config_update('agent_name', $Conf{'agent_name'}); + } elsif ($Conf{'agent_name_cmd'} ne '') { + my $result = `$Conf{'agent_name_cmd'}`; + + # Use only the first line. + my ($temp_agent_name, $remain) = split(/\n/, $result); + chomp ($temp_agent_name); + + # Remove white spaces of the first and last. + $temp_agent_name =~ s/^ *(.*?) *$/$1/; + + $Conf{'agent_name'} = $temp_agent_name if ($temp_agent_name ne ''); + } else { + $Conf{'agent_name'} = hostname(); + } } # Update the agent MD5 since agent_name may have changed @@ -1196,73 +1207,78 @@ sub check_collections () { } ############################################################################### -# MD5 leftrotate function. See http://en.wikipedia.org/wiki/MD5#Pseudocode. +# Return the MD5 checksum of the given string as a hex string. +# Pseudocode from: http://en.wikipedia.org/wiki/MD5#Pseudocode ############################################################################### -sub leftrotate ($$) { - my ($x, $c) = @_; - - return (0xFFFFFFFF & ($x << $c)) | ($x >> (32 - $c)); -} - -############################################################################### -# Initialize some variables needed by the MD5 algorithm. -# See http://en.wikipedia.org/wiki/MD5#Pseudocode. -############################################################################### -my (@R, @K); -sub md5_init () { - - # R specifies the per-round shift amounts - @R = (7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, - 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, - 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, - 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21); - - # Use binary integer part of the sines of integers (radians) as constants - for (my $i = 0; $i < 64; $i++) { - $K[$i] = floor(abs(sin($i + 1)) * MOD232); - } -} - -############################################################################### -# Return the MD5 checksum of the given string. -# Pseudocode from http://en.wikipedia.org/wiki/MD5#Pseudocode. -############################################################################### -sub md5 ($) { +my @S = ( + 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, + 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, + 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, + 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21 +); +my @K = ( + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 +); +sub md5 { my $str = shift; - # Note: All variables are unsigned 32 bits and wrap modulo 2^32 when calculating + # No input! + if (!defined($str)) { + return ""; + } - # Initialize variables + # Note: All variables are unsigned 32 bits and wrap modulo 2^32 when + # calculating. + + # Initialize variables. my $h0 = 0x67452301; my $h1 = 0xEFCDAB89; my $h2 = 0x98BADCFE; my $h3 = 0x10325476; - # Pre-processing + # Pre-processing. my $msg = unpack ("B*", pack ("A*", $str)); my $bit_len = length ($msg); - # Append "1" bit to message + # Append "1" bit to message. $msg .= '1'; - # Append "0" bits until message length in bits ≡ 448 (mod 512) + # Append "0" bits until message length in bits ≡ 448 (mod 512). $msg .= '0' while ((length ($msg) % 512) != 448); - # Append bit /* bit, not byte */ length of unpadded message as 64-bit little-endian integer to message - $msg .= unpack ("B64", pack ("VV", $bit_len)); + # Append bit /* bit, not byte */ length of unpadded message as 64-bit + # little-endian integer to message. + $msg .= unpack ("B32", pack ("V", $bit_len)); + $msg .= unpack ("B32", pack ("V", $bit_len >> 32)); - # Process the message in successive 512-bit chunks + # Process the message in successive 512-bit chunks. for (my $i = 0; $i < length ($msg); $i += 512) { my @w; my $chunk = substr ($msg, $i, 512); - # Break chunk into sixteen 32-bit little-endian words w[i], 0 <= i <= 15 + # Break chunk into sixteen 32-bit little-endian words w[i], 0 <= i <= + # 15. for (my $j = 0; $j < length ($chunk); $j += 32) { push (@w, unpack ("V", pack ("B32", substr ($chunk, $j, 32)))); } - # Initialize hash value for this chunk + # Initialize hash value for this chunk. my $a = $h0; my $b = $h1; my $c = $h2; @@ -1270,7 +1286,7 @@ sub md5 ($) { my $f; my $g; - # Main loop + # Main loop. for (my $y = 0; $y < 64; $y++) { if ($y <= 15) { $f = $d ^ ($b & ($c ^ $d)); @@ -1292,19 +1308,163 @@ sub md5 ($) { my $temp = $d; $d = $c; $c = $b; - $b = ($b + leftrotate (($a + $f + $K[$y] + $w[$g]) % MOD232, $R[$y])) % MOD232; + $b = ($b + leftrotate (($a + $f + $K[$y] + $w[$g]) % POW232, $S[$y])) % POW232; $a = $temp; } - # Add this chunk's hash to result so far - $h0 = ($h0 + $a) % MOD232; - $h1 = ($h1 + $b) % MOD232; - $h2 = ($h2 + $c) % MOD232; - $h3 = ($h3 + $d) % MOD232; + # Add this chunk's hash to result so far. + $h0 = ($h0 + $a) % POW232; + $h1 = ($h1 + $b) % POW232; + $h2 = ($h2 + $c) % POW232; + $h3 = ($h3 + $d) % POW232; } # Digest := h0 append h1 append h2 append h3 #(expressed as little-endian) - return unpack ("H*", pack ("V", $h0)) . unpack ("H*", pack ("V", $h1)) . unpack ("H*", pack ("V", $h2)) . unpack ("H*", pack ("V", $h3)); + return unpack ("H*", pack ("V", $h0)) . + unpack ("H*", pack ("V", $h1)) . + unpack ("H*", pack ("V", $h2)) . + unpack ("H*", pack ("V", $h3)); +} + +############################################################################### +# MD5 leftrotate function. See: http://en.wikipedia.org/wiki/MD5#Pseudocode +############################################################################### +sub leftrotate { + my ($x, $c) = @_; + + return (0xFFFFFFFF & ($x << $c)) | ($x >> (32 - $c)); +} + +############################################################################### +# Return the SHA256 checksum of the given string as a hex string. +# Pseudocode from: http://en.wikipedia.org/wiki/SHA-2#Pseudocode +############################################################################### +my @K2 = ( + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, + 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, + 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, + 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, + 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, + 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 +); +sub sha256 { + my $str = shift; + + # No input! + if (!defined($str)) { + return ""; + } + + # Note: All variables are unsigned 32 bits and wrap modulo 2^32 when + # calculating. + + # First 32 bits of the fractional parts of the square roots of the first 8 + # primes. + my $h0 = 0x6a09e667; + my $h1 = 0xbb67ae85; + my $h2 = 0x3c6ef372; + my $h3 = 0xa54ff53a; + my $h4 = 0x510e527f; + my $h5 = 0x9b05688c; + my $h6 = 0x1f83d9ab; + my $h7 = 0x5be0cd19; + + # Pre-processing. + my $msg = unpack ("B*", pack ("A*", $str)); + my $bit_len = length ($msg); + + # Append "1" bit to message. + $msg .= '1'; + + # Append "0" bits until message length in bits = 448 (mod 512). + $msg .= '0' while ((length ($msg) % 512) != 448); + + # Append bit /* bit, not byte */ length of unpadded message as 64-bit + # big-endian integer to message. + $msg .= unpack ("B32", pack ("N", $bit_len >> 32)); + $msg .= unpack ("B32", pack ("N", $bit_len)); + + # Process the message in successive 512-bit chunks. + for (my $i = 0; $i < length ($msg); $i += 512) { + + my @w; + my $chunk = substr ($msg, $i, 512); + + # Break chunk into sixteen 32-bit big-endian words. + for (my $j = 0; $j < length ($chunk); $j += 32) { + push (@w, unpack ("N", pack ("B32", substr ($chunk, $j, 32)))); + } + + # Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array: + for (my $i = 16; $i < 64; $i++) { + my $s0 = rightrotate($w[$i - 15], 7) ^ rightrotate($w[$i - 15], 18) ^ ($w[$i - 15] >> 3); + my $s1 = rightrotate($w[$i - 2], 17) ^ rightrotate($w[$i - 2], 19) ^ ($w[$i - 2] >> 10); + $w[$i] = ($w[$i - 16] + $s0 + $w[$i - 7] + $s1) % POW232; + } + + # Initialize working variables to current hash value. + my $a = $h0; + my $b = $h1; + my $c = $h2; + my $d = $h3; + my $e = $h4; + my $f = $h5; + my $g = $h6; + my $h = $h7; + + # Compression function main loop. + for (my $i = 0; $i < 64; $i++) { + my $S1 = rightrotate($e, 6) ^ rightrotate($e, 11) ^ rightrotate($e, 25); + my $ch = ($e & $f) ^ ((0xFFFFFFFF & (~ $e)) & $g); + my $temp1 = ($h + $S1 + $ch + $K2[$i] + $w[$i]) % POW232; + my $S0 = rightrotate($a, 2) ^ rightrotate($a, 13) ^ rightrotate($a, 22); + my $maj = ($a & $b) ^ ($a & $c) ^ ($b & $c); + my $temp2 = ($S0 + $maj) % POW232; + + $h = $g; + $g = $f; + $f = $e; + $e = ($d + $temp1) % POW232; + $d = $c; + $c = $b; + $b = $a; + $a = ($temp1 + $temp2) % POW232; + } + + # Add the compressed chunk to the current hash value. + $h0 = ($h0 + $a) % POW232; + $h1 = ($h1 + $b) % POW232; + $h2 = ($h2 + $c) % POW232; + $h3 = ($h3 + $d) % POW232; + $h4 = ($h4 + $e) % POW232; + $h5 = ($h5 + $f) % POW232; + $h6 = ($h6 + $g) % POW232; + $h7 = ($h7 + $h) % POW232; + } + + # Produce the final hash value (big-endian). + return unpack ("H*", pack ("N", $h0)) . + unpack ("H*", pack ("N", $h1)) . + unpack ("H*", pack ("N", $h2)) . + unpack ("H*", pack ("N", $h3)) . + unpack ("H*", pack ("N", $h4)) . + unpack ("H*", pack ("N", $h5)) . + unpack ("H*", pack ("N", $h6)) . + unpack ("H*", pack ("N", $h7)); +} + +############################################################################### +# Rotate a 32-bit number a number of bits to the right. +############################################################################### +sub rightrotate { + my ($x, $c) = @_; + + return (0xFFFFFFFF & ($x << (32 - $c))) | ($x >> $c); } ################################################################################ @@ -2196,6 +2356,46 @@ sub init_module ($) { $module->{'alert_template'} = undef; } +################################################################################ +# Generate a unique agent name. +################################################################################ +sub generate_agent_name { + return sha256(join('|', ($Conf{'agent_alias'}, $Conf{server_ip}, time(), sprintf("%04d", rand(10000))))); +} + +################################################################################ +# Set the value of a token in the configuration file. If the token does not +# exist, it is appended to the end of the file. +################################################################################ +sub config_update ($$) { + my ($token, $value) = @_; + + # Read the original configuration file. + open(my $fh, '<', "$ConfDir/$ConfFile") or die($!); + my @lines = <$fh>; + close ($fh); + + # Set the new value for the configuration token. + my $found = 0; + for(my $i = 0; $i < $#lines; $i++) { + if ($lines[$i] =~ m/[#\s]*$token/) { + $lines[$i] = "$token $value\n"; + $found = 1; + last; + } + } + + # Append the token to the end if it was not found in the file. + if ($found == 0) { + push(@lines, "$token $value\n"); + } + + # Write the changes to the configuration file. + open($fh, '>', "$ConfDir/$ConfFile") or die($!); + print $fh @lines; + close($fh); +} + ################################################################################ # Get the eHorus key from the eHorus agent configuration file. ################################################################################ @@ -2261,9 +2461,6 @@ if (defined ($pandora_user)) { # Guess the OS version $OS_VERSION = guess_os_version ($OS); -# Initialize MD5 variables -md5_init (); - # Start logging start_log (); log_message ('log', 'Running as user ' . getpwuid ($>)); @@ -2472,8 +2669,9 @@ while (1) { (defined($Conf{'group_id'}) ? ("' group_id='" . $Conf{'group_id'}) : '') . "' os_name='$OS' os_version='$OS_VERSION' interval='" . $Conf{'interval'} . "' version='" . AGENT_VERSION . '(Build ' . AGENT_BUILD . ')' . ($Conf{'autotime'} eq '1' ? '' : "' timestamp='" . strftime ('%Y/%m/%d %H:%M:%S', localtime ())) . - "' agent_name='" . $Conf{'agent_name'} . "' timezone_offset='". $Conf{'timezone_offset'} . - "' custom_id='" . $Conf{'custom_id'} . "' url_address='". $Conf{'url_address'}; + "' agent_name='" . $Conf{'agent_name'} . "' agent_alias='". $Conf{'agent_alias'} . + "' timezone_offset='". $Conf{'timezone_offset'} . "' custom_id='" . $Conf{'custom_id'} . + "' url_address='". $Conf{'url_address'}; if (defined ($Conf{'address'})) { $xml_header .= "' address='" .$address; diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer old mode 100644 new mode 100755 diff --git a/pandora_agents/win32/Makefile.am b/pandora_agents/win32/Makefile.am index 4623ca29b7..6e47cafcc1 100644 --- a/pandora_agents/win32/Makefile.am +++ b/pandora_agents/win32/Makefile.am @@ -1,9 +1,9 @@ bin_PROGRAMS = PandoraAgent if DEBUG -PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc debug_new.cpp +PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c misc/sha256.cc windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc debug_new.cpp PandoraAgent_CXXFLAGS=-g -O0 else -PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc +PandoraAgent_SOURCES = misc/pandora_file.cc modules/pandora_data.cc modules/pandora_module_factory.cc modules/pandora_module.cc modules/pandora_module_list.cc modules/pandora_module_plugin.cc modules/pandora_module_inventory.cc modules/pandora_module_freememory.cc modules/pandora_module_exec.cc modules/pandora_module_perfcounter.cc modules/pandora_module_proc.cc modules/pandora_module_tcpcheck.cc modules/pandora_module_freememory_percent.cc modules/pandora_module_freedisk.cc modules/pandora_module_freedisk_percent.cc modules/pandora_module_logevent.cc modules/pandora_module_service.cc modules/pandora_module_cpuusage.cc modules/pandora_module_wmiquery.cc modules/pandora_module_regexp.cc modules/pandora_module_ping.cc modules/pandora_module_snmpget.cc udp_server/udp_server.cc main.cc pandora_strutils.cc pandora.cc windows_service.cc pandora_agent_conf.cc windows/pandora_windows_info.cc windows/pandora_wmi.cc pandora_windows_service.cc misc/md5.c misc/sha256.cc windows/wmi/disphelper.c ssh/libssh2/channel.c ssh/libssh2/mac.c ssh/libssh2/session.c ssh/libssh2/comp.c ssh/libssh2/misc.c ssh/libssh2/sftp.c ssh/libssh2/crypt.c ssh/libssh2/packet.c ssh/libssh2/userauth.c ssh/libssh2/hostkey.c ssh/libssh2/publickey.c ssh/libssh2/kex.c ssh/libssh2/scp.c ssh/pandora_ssh_client.cc ssh/pandora_ssh_test.cc ftp/pandora_ftp_client.cc ftp/pandora_ftp_test.cc PandoraAgent_CXXFLAGS=-O2 endif diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index 3b0aabc91b..fb37a56175 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -33,7 +33,10 @@ temporal "%ProgramFiles%\pandora_agent\temp" # To define agent name by specific command, define 'agent_name_cmd'. # If agent_name_cmd is defined, agent_name is ignored. # (In the following example, agent name is 'hostname_IP') +# If set to __rand__ the agent will generate a random name. #agent_name_cmd cscript.exe //B "%ProgramFiles%\Pandora_Agent\util\agentname.vbs" +agent_name_cmd __rand__ + #Parent agent_name #parent_agent_name caprica diff --git a/pandora_agents/win32/misc/sha256.cc b/pandora_agents/win32/misc/sha256.cc new file mode 100644 index 0000000000..69f59b849c --- /dev/null +++ b/pandora_agents/win32/misc/sha256.cc @@ -0,0 +1,44 @@ +/* Pandora agents service for Win32. + + Copyright (C) 2016 Artica ST. + Written by Ramon Novoa. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include +#include +#include "openssl/sha.h" +#include "sha256.h" + +void +sha256(const char *data, char hex_digest[SHA256_HEX_LENGTH + 1]) +{ + int i, j; + unsigned char hash[SHA256_DIGEST_LENGTH]; + SHA256_CTX sha256; + + // Calculate the SHA-256 hash. + SHA256_Init(&sha256); + SHA256_Update(&sha256, data, strlen(data)); + SHA256_Final(hash, &sha256); + + // Convert it to a hexadecimal string. + for(i = 0, j = 0; i < SHA256_DIGEST_LENGTH, j < SHA256_HEX_LENGTH; i++, j+=2) { + sprintf(&(hex_digest[j]), "%02x", hash[i]); + } + + // Add a NULL terminator. + hex_digest[SHA256_HEX_LENGTH] = 0; +} diff --git a/pandora_agents/win32/misc/sha256.h b/pandora_agents/win32/misc/sha256.h new file mode 100644 index 0000000000..3489496366 --- /dev/null +++ b/pandora_agents/win32/misc/sha256.h @@ -0,0 +1,29 @@ +/* Pandora agents service for Win32. + + Copyright (C) 2016 Artica ST. + Written by Ramon Novoa. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef _SHA256_H_ +#define _SHA256_H_ + +// Length of the sha256 hex string. +#define SHA256_HEX_LENGTH 64 + +void sha256(const char *data, char hex_digest[SHA256_HEX_LENGTH + 1]); + +#endif diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index d33079c68c..9b49291f64 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -99,6 +99,15 @@ Key_Value::getKey () { return key; } +/** + * Set the key of the object. + * + */ +void +Key_Value::setKey (const string key) { + this->key = key; +} + /** * Get the value of the object. * @@ -109,6 +118,16 @@ Key_Value::getValue () { return value; } +/** + * Set the value of the object. + * + * @return The value + */ +void +Key_Value::setValue (const string value) { + this->value = value; +} + void pandoraWriteLog (string filename, string line) { string buffer; diff --git a/pandora_agents/win32/pandora.h b/pandora_agents/win32/pandora.h index 0469ab61dd..f1dfafc1c0 100644 --- a/pandora_agents/win32/pandora.h +++ b/pandora_agents/win32/pandora.h @@ -62,7 +62,9 @@ namespace Pandora { void parseLine (string str); void parseLineByPosition (string str, int pos); string getKey (); + void setKey (const string value); string getValue (); + void setValue (const string value); }; static const HKEY hkey = HKEY_LOCAL_MACHINE; diff --git a/pandora_agents/win32/pandora_agent_conf.cc b/pandora_agents/win32/pandora_agent_conf.cc index f44872c59f..83675cdde6 100644 --- a/pandora_agents/win32/pandora_agent_conf.cc +++ b/pandora_agents/win32/pandora_agent_conf.cc @@ -350,6 +350,70 @@ Pandora::Pandora_Agent_Conf::setFile (string filename) { file.close (); } +/** + * Update a configuration value in the configuration file. If it is not found, + * it is appended at the end of the file. + * + * @param string key Name of the configuration option. + * @param string value New value. + */ +void +Pandora::Pandora_Agent_Conf::updateFile (string key, string value){ + string buffer, filename, temp_filename; + int pos; + + /* Open the configuration file. */ + filename = Pandora::getPandoraInstallDir (); + filename += "pandora_agent.conf"; + ifstream file (filename.c_str ()); + if (!file.is_open ()) { + return; + } + + /* Open the temporary file. */ + temp_filename = filename + ".tmp"; + ofstream temp_file (temp_filename.c_str ()); + if (!temp_file.is_open ()) { + return; + } + + /* Look for the configuration value. */ + bool found = false; + while (!file.eof ()) { + getline (file, buffer); + + /* Copy the rest of the file if the key was found. */ + if (found) { + temp_file << buffer << std::endl; + continue; + } + + /* We will only look for the key in the first three characters, hoping + to catch "key", "#key" and "# key". We would also catch "..key", but + no such keys exist in the configuration file. */ + pos = buffer.find(key); + if (pos == std::string::npos || pos > 2) { + temp_file << buffer << std::endl; + continue; + } + + /* Match! */ + found = true; + temp_file << key + " " + value << std::endl; + } + + /* Append the value at the end of the file if it was not found. */ + if (!found) { + temp_file << key + " " + value << std::endl; + } + + /* Rename the temporary file. */ + file.close (); + temp_file.close (); + remove(filename.c_str()); + rename(temp_filename.c_str(), filename.c_str()); +} + /** * Queries for a configuration value. * @@ -375,6 +439,33 @@ Pandora::Pandora_Agent_Conf::getValue (const string key) return ""; } +/** + * Sets a configuration value. + * + * @param key Key to look for. + * @param string New value. + * + */ +void +Pandora::Pandora_Agent_Conf::setValue (const string key, const string value) +{ + std::list::iterator i; + + // Update. + for (i = this->key_values->begin (); i != this->key_values->end (); i++) { + if ((*i).getKey () == key) { + (*i).setValue (value); + return; + } + } + + // Append. + Key_Value kv; + kv.setKey(key); + kv.setValue(value); + this->key_values->push_back (kv); +} + /** * Queries for a collection name. * diff --git a/pandora_agents/win32/pandora_agent_conf.h b/pandora_agents/win32/pandora_agent_conf.h index f22819450e..7cc77b5203 100644 --- a/pandora_agents/win32/pandora_agent_conf.h +++ b/pandora_agents/win32/pandora_agent_conf.h @@ -55,7 +55,9 @@ namespace Pandora { void parseFile(string path_file, Collection *aux); void setFile (string *all_conf); void setFile (string filename); + void updateFile (string key, string value); string getValue (const string key); + void setValue (const string key, const string value); string getCurrentCollectionName(); unsigned char getCurrentCollectionVerify(); diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 1bbf980c35..77e6693a71 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -26,6 +26,7 @@ #include "ssh/pandora_ssh_client.h" #include "ftp/pandora_ftp_client.h" #include "misc/pandora_file.h" +#include "misc/sha256.h" #include "windows/pandora_windows_info.h" #include "udp_server/udp_server.h" @@ -39,6 +40,8 @@ #include #include #include +#include +#include #define BUFSIZE 4096 @@ -207,7 +210,7 @@ void Pandora_Windows_Service::pandora_init () { string conf_file, interval, debug, disable_logfile, intensive_interval, util_dir, path, env; string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr; - string name_agent, name; + string agent_name, agent_name_cmd, agent_alias, pandora_agent; string proxy_mode, server_ip; string *all_conf; int pos, num; @@ -255,12 +258,60 @@ Pandora_Windows_Service::pandora_init () { this->modules = new Pandora_Module_List (conf_file); delete []all_conf; - name = checkAgentName(conf_file); - if (name.empty ()) { - name = Pandora_Windows_Info::getSystemName (); + // Get the agent name. + agent_name = conf->getValue ("agent_name"); + printf("AGENT NAME: %s\n", agent_name.c_str()); + if (agent_name == "") { + agent_name_cmd = conf->getValue ("agent_name_cmd"); + + // Random name. + if (agent_name_cmd == "__rand__") { + agent_name = generateAgentName(); + this->conf->setValue("agent_name", agent_name); + conf->updateFile("agent_name", agent_name); // Write random names to disk! + } + // Name from command. + else if (agent_name_cmd != "") { + agent_name_cmd = "cmd.exe /c \"" + agent_name_cmd + "\""; + static string temp_agent_name = getAgentNameFromCmdExec(agent_name_cmd); + + // Delete new line and carriage return. + pos = temp_agent_name.find("\n"); + if(pos != string::npos) { + temp_agent_name.erase(pos, temp_agent_name.size () - pos); + } + pos = temp_agent_name.find("\r"); + if(pos != string::npos) { + temp_agent_name.erase(pos, temp_agent_name.size () - pos); + } + + // Remove leading and trailing white spaces. + temp_agent_name = trim(temp_agent_name); + if (temp_agent_name != "") { + agent_name = temp_agent_name; + this->conf->setValue("agent_name", agent_name); + } + } } - name_agent = "PANDORA_AGENT=" + name; - putenv(name_agent.c_str()); + + printf("AGENT NAME2: %s\n", agent_name.c_str()); + // Fall back to the hostname if agent_name is still empty. + if (agent_name == "") { + agent_name = Pandora_Windows_Info::getSystemName (); + this->conf->setValue("agent_name", agent_name); + } + printf("AGENT NAME3: %s\n", agent_name.c_str()); + printf("AGENT NAME4: %s\n", this->conf->getValue("agent_name").c_str()); + + // Get the agent alias. + conf->getValue ("agent_alias"); + if (agent_alias == "") { + agent_alias = Pandora_Windows_Info::getSystemName (); + this->conf->setValue("agent_alias", agent_alias); + } + + pandora_agent = "PANDORA_AGENT=" + agent_name; + putenv(pandora_agent.c_str()); debug = conf->getValue ("debug"); setPandoraDebug (is_enabled (debug)); @@ -383,7 +434,7 @@ Pandora_Windows_Service::launchTentacleProxy() { string Pandora_Windows_Service::getXmlHeader () { char timestamp[20]; - string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd; + string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd, agent_alias; string custom_id, url_address, latitude, longitude, altitude, position_description, gis_exec, gis_result, agent_mode; string group_password, group_id, ehorus_conf; time_t ctime; @@ -392,30 +443,9 @@ Pandora_Windows_Service::getXmlHeader () { // Get agent name agent_name = conf->getValue ("agent_name"); - if (agent_name == "") { - agent_name = Pandora_Windows_Info::getSystemName (); - } - agent_name_cmd = conf->getValue ("agent_name_cmd"); - if (agent_name_cmd != "") { - agent_name_cmd = "cmd.exe /c \"" + agent_name_cmd + "\""; - static string temp_agent_name = getAgentNameFromCmdExec(agent_name_cmd); - // Delete carriage return if is provided - pos = temp_agent_name.find("\n"); - if(pos != string::npos) { - temp_agent_name.erase(pos, temp_agent_name.size () - pos); - } - pos = temp_agent_name.find("\r"); - if(pos != string::npos) { - temp_agent_name.erase(pos, temp_agent_name.size () - pos); - } - // Remove white spaces of the first and last. - temp_agent_name = trim(temp_agent_name); - - if (temp_agent_name != "") { - agent_name = temp_agent_name; - } - } + // Get agent alias + conf->getValue ("agent_alias"); // Get parent agent name parent_agent_name = conf->getValue ("parent_agent_name"); @@ -443,6 +473,7 @@ Pandora_Windows_Service::getXmlHeader () { xml = "\n" + "getValue ("description") + "\" version=\"" + getPandoraAgentVersion (); @@ -1492,35 +1523,8 @@ Pandora_Windows_Service::checkConfig (string file) { } /* Get agent name */ - tmp = checkAgentName(file); - if (tmp.empty ()) { - tmp = Pandora_Windows_Info::getSystemName (); - } - agent_name = tmp; + tmp = conf->getValue ("agent_name"); - /* Get agent name cmd */ - tmp = conf->getValue ("agent_name_cmd"); - if (!tmp.empty ()) { - tmp = "cmd.exe /c \"" + tmp + "\""; - tmp = getCoordinatesFromCmdExec(tmp); - - // Delete carriage return if is provided - pos = tmp.find("\n"); - if(pos != string::npos) { - tmp.erase(pos, tmp.size () - pos); - } - pos = tmp.find("\r"); - if(pos != string::npos) { - tmp.erase(pos, tmp.size () - pos); - } - - // Remove white spaces of the first and last. - tmp = trim (tmp); - - if (tmp != "") { - agent_name = tmp; - } - } /* Error getting agent name */ if (agent_name.empty ()) { @@ -1722,10 +1726,6 @@ Pandora_Windows_Service::sendXml (Pandora_Module_List *modules) { /* Generate temporal filename */ random_integer = inttostr (rand()); tmp_filename = conf->getValue ("agent_name"); - - if (tmp_filename == "") { - tmp_filename = Pandora_Windows_Info::getSystemName (); - } tmp_filename += "." + random_integer + ".data"; xml_filename = conf->getValue ("temporal"); @@ -2098,3 +2098,17 @@ Pandora_Windows_Service::getIntensiveInterval () { return this->intensive_interval; } +string +Pandora_Windows_Service::generateAgentName () { + stringstream data; + char digest[SHA256_HEX_LENGTH + 1]; + + std::srand(std::time(0)); + data << this->conf->getValue("agent_alias") << + this->conf->getValue("server_ip") << + time(NULL) << + std::rand(); + + sha256(data.str().c_str(), digest); + return std::string(digest); +} diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index ecce0d501e..be9a7a4eb3 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -44,6 +44,7 @@ namespace Pandora { Pandora_Module_List *modules; long execution_number; string agent_name; + string alias; time_t timestamp; time_t run_time; bool started; @@ -117,6 +118,7 @@ namespace Pandora { string getEHKey (string ehorus_conf); long getInterval (); long getIntensiveInterval (); + string generateAgentName (); }; } diff --git a/pandora_console/extensions/agents_alerts.php b/pandora_console/extensions/agents_alerts.php index de0cf38530..32c92053b0 100755 --- a/pandora_console/extensions/agents_alerts.php +++ b/pandora_console/extensions/agents_alerts.php @@ -223,9 +223,10 @@ function mainAgentsAlerts() { } foreach ($agents as $agent) { + $alias = db_get_row ('tagente', 'id_agente', $agent['id_agente']); echo ''; // Name of the agent - echo ''.$agent['nombre'].''; + echo ''.$alias['alias'].''; // Alerts of the agent $anyfired = false; diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index f36bf39ac7..1349497e0a 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -386,6 +386,10 @@ function mainAgentsModules() { foreach ($agents as $agent) { // Get stats for this group $agent_status = agents_get_status($agent['id_agente']); + $alias = db_get_row ("tagente", "id_agente", $agent['id_agente']); + if (empty($alias['alias'])){ + $alias['alias'] = $agent['nombre']; + } switch($agent_status) { case 4: // Alert fired status @@ -411,7 +415,7 @@ function mainAgentsModules() { echo " " . - ui_print_truncate_text(io_safe_output($agent['nombre']), 'agent_size_text_small', true, true, true, '...', 'font-size:10px; font-weight: bold;') . + $alias['alias'] . ""; $agent_modules = agents_get_modules($agent['id_agente'], false, $filter_module_group, true, true); @@ -639,4 +643,4 @@ extensions_add_main_function('mainAgentsModules'); "json" ); } - \ No newline at end of file + diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php index 494bbdd0d2..33659b0c71 100644 --- a/pandora_console/extensions/insert_data.php +++ b/pandora_console/extensions/insert_data.php @@ -37,10 +37,12 @@ function createXMLData($agent, $agentModule, $time, $data) { $xml = sprintf($xmlTemplate, io_safe_output(get_os_name($agent['id_os'])), io_safe_output($agent['os_version']), $agent['intervalo'], io_safe_output($agent['agent_version']), $time, - io_safe_output($agent['nombre']), $agent['timezone_offset'], + io_safe_output($agent['nombre']), + io_safe_output($agent['alias']), $agent['timezone_offset'], io_safe_output($agentModule['nombre']), io_safe_output($agentModule['descripcion']), modules_get_type_name($agentModule['id_tipo_modulo']), $data); - - if (false === @file_put_contents($config['remote_config'] . '/' . io_safe_output($agent['nombre']) . '.' . strtotime($time) . '.data', $xml)) { + + + if (false === @file_put_contents($config['remote_config'] . '/' . io_safe_output($agent['alias']) . '.' . strtotime($time) . '.data', $xml)) { return false; } else { @@ -61,6 +63,14 @@ function mainInsertData() { $save = (bool)get_parameter('save', false); $id_agent = (string)get_parameter('id_agent', ''); + + foreach ($_POST as $key => $value) { + if(strpos($key,"agent_autocomplete_idagent")!== false){ + $id_agente = $value; + } + } + + $id_agent_module = (int)get_parameter('id_agent_module', ''); $data = (string)get_parameter('data'); $date = (string) get_parameter('date', date(DATE_FORMAT)); @@ -83,7 +93,8 @@ function mainInsertData() { ui_print_error_message(__('You haven\'t privileges for insert data in the agent.')); } else { - $agent = db_get_row_filter('tagente', array('nombre' => $id_agent)); + + $agent = db_get_row_filter('tagente', array('id_agente' => $id_agente)); $agentModule = db_get_row_filter('tagente_modulo', array('id_agente_modulo' => $id_agent_module)); $done = 0; @@ -116,14 +127,14 @@ function mainInsertData() { } if ($errors > 0) { - $msg = sprintf(__('Can\'t save agent (%s), module (%s) data xml.'), $agent['nombre'], $agentModule['nombre']); + $msg = sprintf(__('Can\'t save agent (%s), module (%s) data xml.'), $agent['alias'], $agentModule['nombre']); if ($errors > 1) { $msg .= " ($errors)"; } ui_print_error_message($msg); } if ($done > 0) { - $msg = sprintf(__('Save agent (%s), module (%s) data xml.'), $agent['nombre'], $agentModule['nombre']); + $msg = sprintf(__('Save agent (%s), module (%s) data xml.'), $agent['alias'], $agentModule['nombre']); if ($done > 1) { $msg .= " ($done)"; } @@ -153,14 +164,19 @@ function mainInsertData() { $params['javascript_is_function_select'] = true; $params['javascript_name_function_select'] = 'custom_select_function'; $params['javascript_code_function_select'] = ''; + $params['use_hidden_input_idagent'] = true; + $params['print_hidden_input_idagent'] = true; + $params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent'; + $table->data[0][1] = ui_print_agent_autocomplete_input($params); $table->data[1][0] = __('Module'); $modules = array (); - if ($id_agent) - $modules = agents_get_modules ($id_agent, false, array("delete_pending" => 0)); + if ($id_agente){ + $modules = agents_get_modules ($id_agente, false, array("delete_pending" => 0)); + } $table->data[1][1] = html_print_select ($modules, 'id_agent_module', $id_agent_module, true, - __('Select'), 0, true, false, true, '', ($id_agent === '')); + __('Select'), 0, true, false, true, '', ($id_agente === '')); $table->data[2][0] = __('Data'); $table->data[2][1] = html_print_input_text('data', $data, __('Data'), 40, 60, true); $table->data[3][0] = __('Date'); @@ -206,9 +222,10 @@ function mainInsertData() { function custom_select_function(agent_name) { $('#id_agent_module').empty (); - var inputs = []; - inputs.push ("agent_name=" + agent_name); + var id_agent = $('#hidden-autocomplete_id_agent').val(); + + inputs.push ("id_agent=" + id_agent); inputs.push ("delete_pending=0"); inputs.push ("get_agent_modules_json=1"); inputs.push ("page=operation/agentes/ver_agente"); diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php index 0a1aedebdd..4bdc7d2046 100755 --- a/pandora_console/extensions/resource_exportation.php +++ b/pandora_console/extensions/resource_exportation.php @@ -97,12 +97,12 @@ function output_xml_report($id) { echo "" . io_safe_output($item['description']) . "\n"; echo "" . io_safe_output($item['period']) . "\n"; if ($item['id_agent'] != 0) { - $agent = agents_get_name($item['id_agent']); + $agent = db_get_value ("alias","tagente","id_agente",$item['id_agent']); } if ($item['id_agent_module'] != 0) { $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']); $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']); - $agent = agents_get_name($item['id_agent']); + $agent = db_get_value ("alias","tagente","id_agente",$item['id_agent']); echo "\n"; } @@ -140,7 +140,7 @@ function output_xml_report($id) { foreach ($slas as $sla) { $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']); $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']); - $agent = agents_get_name($item['id_agent']); + $agent = db_get_value ("alias","tagente","id_agente",$item['id_agent']); echo ""; echo "\n"; echo "\n"; @@ -245,8 +245,14 @@ function output_xml_visual_console($id) { foreach ($items as $item) { echo "\n"; echo "" . $item['id'] . "\n"; //OLD ID USE FOR parent item + $agent = ''; + if ($item['id_agent'] != 0) { + $agent = db_get_value ("alias","tagente","id_agente",$item['id_agent']); + } if (!empty($item['label'])) { - echo "\n"; + $aux = explode("-",$item['label']); + $label = $agent .' -'. $aux[1]; + echo "\n"; } echo "" . $item['pos_x'] . "\n"; echo "" . $item['pos_y'] . "\n"; @@ -263,15 +269,11 @@ function output_xml_visual_console($id) { if ($item['period'] != 0) { echo "" . $item['period'] . "\n"; } - $agent = ''; - if ($item['id_agent'] != 0) { - $agent = agents_get_name($item['id_agent']); - } if (isset($item['id_agente_modulo'])) { if ($item['id_agente_modulo'] != 0) { $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']); $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']); - $agent = agents_get_name($id_agent); + $agent = db_get_value ("alias","tagente","id_agente",$id_agent); echo "\n"; } diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index f2be7ee94f..fa0a9cf261 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -219,7 +219,9 @@ ALTER TABLE tnetwork_component ADD COLUMN `dynamic_two_tailed` tinyint(1) unsign ALTER TABLE tagente ADD `transactional_agent` tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD `remote` tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD `cascade_protection_module` int(10) unsigned default '0'; +ALTER TABLE tagente ADD COLUMN (alias varchar(600) not null default ''); +UPDATE tagente SET tagente.alias = tagente.nombre; -- --------------------------------------------------------------------- -- Table `tlayout` -- --------------------------------------------------------------------- diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.oracle.sql index adbd512800..3a33516c72 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.oracle.sql @@ -134,7 +134,9 @@ ALTER TABLE tnetwork_component ADD COLUMN dynamic_two_tailed tinyint(1) unsigned ALTER TABLE tagente ADD transactional_agent tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD remoteto tinyint(1) NOT NULL default 0; ALTER TABLE tagente ADD cascade_protection_module int(10) unsigned default '0'; +ALTER TABLE tagente ADD COLUMN (alias VARCHAR2(600) not null DEFAULT ''); +UPDATE `tagente` SET tagente.alias = tagente.nombre; -- --------------------------------------------------------------------- -- Table `tlayout` -- --------------------------------------------------------------------- diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 3e815f7240..947ca6e1dd 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -30,10 +30,10 @@ if (is_ajax ()) { switch ($config['dbtype']) { case "mysql": case "postgresql": - $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%' . $string . '%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")'; + $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%' . $string . '%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%" OR alias LIKE "%'.$string.'%")'; break; case "oracle": - $filter[] = '(upper(nombre) LIKE upper(\'%'.$string.'%\') OR upper(direccion) LIKE upper(\'%'.$string.'%\') OR upper(comentarios) LIKE upper(\'%'.$string.'%\'))'; + $filter[] = '(upper(nombre) LIKE upper(\'%'.$string.'%\') OR upper(direccion) LIKE upper(\'%'.$string.'%\') OR upper(comentarios) LIKE upper(\'%'.$string.'%\') OR upper(alias) LIKE upper(\'%'.$string.'%\'))'; break; } $filter[] = 'id_agente != ' . $id_agent; @@ -151,21 +151,26 @@ $table->data = array (); $table->align[2] = 'center'; -$table->data[0][0] = __('Agent name') . - ui_print_help_tip (__("The agent's name must be the same as the one defined at the console"), true); -$table->data[0][1] = html_print_input_text ('agente', $nombre_agente, '', 50, 100,true); +if(!$new_agent && $alias != ''){ + $table->data[0][0] = __('Agent name') . + ui_print_help_tip (__("The agent's name must be the same as the one defined at the console"), true); + $table->data[0][1] = html_print_input_text ('agente', $nombre_agente, '', 50, 100,true); -$table->data[0][2] = __('QR Code Agent view'); + $table->data[0][2] = __('QR Code Agent view'); -if ($id_agente) { - - $table->data[0][1] .= " " . __("ID") . "  $id_agente  "; - $table->data[0][1] .= '  '; - $table->data[0][1] .= html_print_image ("images/zoom.png", - true, array ("border" => 0, "title" => __('Agent detail'))); - $table->data[0][1] .= ''; + if ($id_agente) { + + $table->data[0][1] .= " " . __("ID") . "  $id_agente  "; + $table->data[0][1] .= '  '; + $table->data[0][1] .= html_print_image ("images/zoom.png", + true, array ("border" => 0, "title" => __('Agent detail'))); + $table->data[0][1] .= ''; + } } + + + // Remote configuration available if (!$new_agent) { if (isset($filename)) { @@ -197,17 +202,21 @@ if (!$new_agent) { if (!$new_agent) { $table->data[0][1] .= "  " . html_print_image('images/cross.png', true, array('title' => __("Delete agent"))) . ""; } +$table->data[1][0] = __('Alias'); +$table->data[1][1] = html_print_input_text ('alias', $alias, '', 50, 100, true); -$table->data[1][0] = __('IP Address'); -$table->data[1][1] = html_print_input_text ('direccion', $direccion_agente, '', 16, 100, true); + + +$table->data[2][0] = __('IP Address'); +$table->data[2][1] = html_print_input_text ('direccion', $direccion_agente, '', 16, 100, true); if ($id_agente) { - $table->data[1][1] .= '    '; - + $table->data[2][1] .= '    '; + $ip_all = agents_get_addresses ($id_agente); - - $table->data[1][1] .= html_print_select ($ip_all, "address_list", $direccion_agente, '', '', 0, true); - $table->data[1][1] .= " ". html_print_checkbox ("delete_ip", 1, false, true).__('Delete selected'); + + $table->data[2][1] .= html_print_select ($ip_all, "address_list", $direccion_agente, '', '', 0, true); + $table->data[2][1] .= " ". html_print_checkbox ("delete_ip", 1, false, true).__('Delete selected'); } ?> @@ -217,77 +226,83 @@ if ($id_agente) { } rowspan[1][2] = 3; -if ($id_agente) { - $table->data[1][2] = - ""; -} -else { - $table->data[1][2] = __("Only it is show when
the agent is saved."); +if(!$new_agent){ + $table->rowspan[2][2] = 3; + if ($id_agente) { + $table->data[2][2] = + ""; + } + else { + $table->data[2][2] = __("Only it is show when
the agent is saved."); + } } + $groups = users_get_groups ($config["id_user"], "AR",false); $agents = agents_get_group_agents (array_keys ($groups)); + $modules = db_get_all_rows_sql("SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo WHERE id_agente = " . $id_parent); - $modules_values = array(); $modules_values[0] = __('Any'); foreach ($modules as $m) { $modules_values[$m['id_module']] = $m['name']; } -$table->data[2][0] = __('Parent'); +$table->data[3][0] = __('Parent'); $params = array(); $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'id_parent'; -$params['value'] = agents_get_name ($id_parent); -$table->data[2][1] = ui_print_agent_autocomplete_input($params); +$params['print_hidden_input_idagent'] = true; +$params['hidden_input_idagent_name'] = 'id_agent_parent'; +$params['hidden_input_idagent_value'] = $id_parent; +$params['value'] = db_get_value ("alias","tagente","id_agente",$id_parent); +$table->data[3][1] = ui_print_agent_autocomplete_input($params); -$table->data[2][1] .= html_print_checkbox ("cascade_protection", 1, $cascade_protection, true).__('Cascade protection'). " " . ui_print_help_icon("cascade_protection", true); +$table->data[3][1] .= html_print_checkbox ("cascade_protection", 1, $cascade_protection, true).__('Cascade protection'). " " . ui_print_help_icon("cascade_protection", true); -$table->data[2][1] .= "  " . __('Module') . " " . html_print_select ($modules_values, "cascade_protection_module", $cascade_protection_module, "", "", 0, true); +$table->data[3][1] .= "  " . __('Module') . " " . html_print_select ($modules_values, "cascade_protection_module", $cascade_protection_module, "", "", 0, true); -$table->data[3][0] = __('Group'); -$table->data[3][1] = html_print_select_groups(false, "AR", false, 'grupo', $grupo, '', '', 0, true); -$table->data[3][1] .= ' '; -$table->data[3][1] .= ui_print_group_icon ($grupo, true); -$table->data[3][1] .= ''; +$table->data[4][0] = __('Group'); +$table->data[4][1] = html_print_select_groups(false, "AR", false, 'grupo', $grupo, '', '', 0, true); +$table->data[4][1] .= ' '; +$table->data[4][1] .= ui_print_group_icon ($grupo, true); +$table->data[4][1] .= ''; -$table->data[4][0] = __('Interval'); +$table->data[5][0] = __('Interval'); -$table->data[4][1] = html_print_extended_select_for_time ('intervalo', $intervalo, '', '', '0', 10, true); +$table->data[5][1] = html_print_extended_select_for_time ('intervalo', $intervalo, '', '', '0', 10, true); if ($intervalo < SECONDS_5MINUTES) { - $table->data[4][1] .= clippy_context_help("interval_agent_min"); + $table->data[5][1] .= clippy_context_help("interval_agent_min"); } -$table->data[5][0] = __('OS'); -$table->data[5][1] = html_print_select_from_sql ('SELECT id_os, name FROM tconfig_os', +$table->data[6][0] = __('OS'); +$table->data[6][1] = html_print_select_from_sql ('SELECT id_os, name FROM tconfig_os', 'id_os', $id_os, '', '', '0', true); -$table->data[5][1] .= ' '; -$table->data[5][1] .= ui_print_os_icon ($id_os, false, true); -$table->data[5][1] .= ''; +$table->data[6][1] .= ' '; +$table->data[6][1] .= ui_print_os_icon ($id_os, false, true); +$table->data[6][1] .= ''; // Network server $servers = servers_get_names(); if (!array_key_exists($server_name, $servers)) { $server_Name = 0; //Set the agent have not server. } -$table->data[6][0] = __('Server'); +$table->data[7][0] = __('Server'); if ($new_agent) { //Set first server by default. $servers_get_names = servers_get_names(); $array_keys_servers_get_names = array_keys($servers_get_names); $server_name = reset($array_keys_servers_get_names); } -$table->data[6][1] = html_print_select (servers_get_names (), +$table->data[7][1] = html_print_select (servers_get_names (), 'server_name', $server_name, '', __('None'), 0, true). ' ' . ui_print_help_icon ('agent_server', true); // Description -$table->data[7][0] = __('Description'); -$table->data[7][1] = html_print_input_text ('comentarios', $comentarios, +$table->data[8][0] = __('Description'); +$table->data[8][1] = html_print_input_text ('comentarios', $comentarios, '', 45, 200, true); html_print_table ($table); @@ -593,5 +608,7 @@ ui_require_jquery_file('bgiframe'); echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $id_agente); ?>", "#qr_code_agent_view", 128, 128); + $("#text-agente").prop('disabled', true); + }); diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c29219815d..17960c12e8 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -73,6 +73,7 @@ $campo_3 = ""; $maximo = 0; $minimo = 0; $nombre_agente = ""; +$alias = get_parameter('alias', ''); $direccion_agente = get_parameter('direccion', ''); $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); @@ -147,7 +148,8 @@ $module_macros = array (); // Create agent if ($create_agent) { - $nombre_agente = (string) get_parameter_post("agente",''); + $nombre_agente = md5($alias . $direccion_agente); + $alias = (string) get_parameter_post("alias",''); $direccion_agente = (string) get_parameter_post("direccion",''); $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); @@ -179,18 +181,19 @@ if ($create_agent) { } // Check if agent exists (BUG WC-50518-2) - if ($nombre_agente == "") { - $agent_creation_error = __('No agent name specified'); + if ($alias == "") { + $agent_creation_error = __('No agent alias specified'); $agent_created_ok = 0; } - elseif (agents_get_agent_id ($nombre_agente)) { + /*elseif (agents_get_agent_id ($nombre_agente)) { $agent_creation_error = __('There is already an agent in the database with this name'); $agent_created_ok = 0; - } + }*/ else { $id_agente = db_process_sql_insert ('tagente', array ('nombre' => $nombre_agente, + 'alias' => $alias, 'direccion' => $direccion_agente, 'id_grupo' => $grupo, 'intervalo' => $intervalo, @@ -241,7 +244,7 @@ if ($create_agent) { ' Quiet: ' . (int)$quiet; db_pandora_audit("Agent management", - "Created agent $nombre_agente", false, true, $info); + "Created agent $alias", false, true, $info); } else { $id_agente = 0; @@ -554,10 +557,9 @@ if ($id_agente) { default: break; } - - ui_print_page_header ( - agents_get_name ($id_agente) . ' ' . $tab_description, - "images/setup.png", false, $help_header , true, $onheader); + $agent = db_get_row ('tagente', 'id_agente', $id_agente); + ui_print_page_header ($agent["nombre"], + "images/setup.png", false, $help_header , true, $onheader, false, '', GENERIC_SIZE_TEXT, $agent["alias"] . ' ' . $tab_description); } else { // Create agent @@ -641,6 +643,7 @@ $update_agent = (bool) get_parameter ('update_agent'); if ($update_agent) { // if modified some agent paramenter $id_agente = (int) get_parameter_post ("id_agente"); $nombre_agente = str_replace('`','‘',(string) get_parameter_post ("agente", "")); + $alias = str_replace('`','‘',(string) get_parameter_post ("alias", "")); $direccion_agente = (string) get_parameter_post ("direccion", ''); $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); @@ -705,14 +708,14 @@ if ($update_agent) { // if modified some agent paramenter } //Verify if there is another agent with the same name but different ID - if ($nombre_agente == "") { - ui_print_error_message(__('No agent name specified')); + if ($alias == "") { + ui_print_error_message(__('No agent alias specified')); //If there is an agent with the same name, but a different ID } - elseif (agents_get_agent_id ($nombre_agente) > 0 && + /*elseif (agents_get_agent_id ($nombre_agente) > 0 && agents_get_agent_id ($nombre_agente) != $id_agente) { ui_print_error_message(__('There is already an agent in the database with this name')); - } + }*/ else { //If different IP is specified than previous, add the IP if ($direccion_agente != '' && @@ -732,7 +735,7 @@ if ($update_agent) { // if modified some agent paramenter 'id_parent' => $id_parent, 'id_os' => $id_os, 'modo' => $modo, - 'nombre' => $nombre_agente, + 'alias' => $alias, 'direccion' => $direccion_agente, 'id_grupo' => $grupo, 'intervalo' => $intervalo, @@ -778,8 +781,8 @@ if ($update_agent) { // if modified some agent paramenter enterprise_hook ('update_agent', array ($id_agente)); ui_print_success_message (__('Successfully updated')); db_pandora_audit("Agent management", - "Updated agent $nombre_agente", false, false, $info); - + "Updated agent $alias", false, false, $info); + } } } @@ -804,6 +807,12 @@ if ($id_agente) { $intervalo = $agent["intervalo"]; // Define interval in seconds $nombre_agente = $agent["nombre"]; + if(empty($alias)){ + $alias = $agent["alias"]; + if(empty($alias)){ + $alias = $nombre_agente; + } + } $direccion_agente = $agent["direccion"]; $grupo = $agent["id_grupo"]; $ultima_act = $agent["ultimo_contacto"]; @@ -1200,7 +1209,7 @@ if ($update_module) { $edit_module = true; db_pandora_audit("Agent management", - "Fail to try update module '$name' for agent " . $agent["nombre"]); + "Fail to try update module '$name' for agent " . $agent["alias"]); } else { if ($prediction_module == 3) { @@ -1218,7 +1227,7 @@ if ($update_module) { $agent = db_get_row ('tagente', 'id_agente', $id_agente); db_pandora_audit("Agent management", - "Updated module '$name' for agent ".$agent["nombre"], false, false, io_json_mb_encode($values)); + "Updated module '$name' for agent ".$agent["alias"], false, false, io_json_mb_encode($values)); } } @@ -1336,7 +1345,7 @@ if ($create_module) { $edit_module = true; $moduletype = $id_module; db_pandora_audit("Agent management", - "Fail to try added module '$name' for agent ".$agent["nombre"]); + "Fail to try added module '$name' for agent ".$agent["alias"]); } else { if ($prediction_module == 3) { @@ -1354,7 +1363,7 @@ if ($create_module) { $agent = db_get_row ('tagente', 'id_agente', $id_agente); db_pandora_audit("Agent management", - "Added module '$name' for agent ".$agent["nombre"], false, true, io_json_mb_encode($values)); + "Added module '$name' for agent ".$agent["alias"], false, true, io_json_mb_encode($values)); } } @@ -1471,7 +1480,7 @@ if ($delete_module) { // DELETE agent module ! $agent = db_get_row ('tagente', 'id_agente', $id_agente); db_pandora_audit("Agent management", - "Deleted module '".$module_data["nombre"]."' for agent ".$agent["nombre"]); + "Deleted module '".$module_data["nombre"]."' for agent ".$agent["alias"]); } } @@ -1502,11 +1511,11 @@ if (!empty($duplicate_module)) { // DUPLICATE agent module ! if ($result) { db_pandora_audit("Agent management", - "Duplicate module '".$id_duplicate_module."' for agent " . $agent["nombre"] . " with the new id for clon " . $result); + "Duplicate module '".$id_duplicate_module."' for agent " . $agent["alias"] . " with the new id for clon " . $result); } else { db_pandora_audit("Agent management", - "Fail to try duplicate module '".$id_duplicate_module."' for agent " . $agent["nombre"]); + "Fail to try duplicate module '".$id_duplicate_module."' for agent " . $agent["alias"]); } } diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 41330451c8..534b4efba0 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -215,14 +215,14 @@ switch ($sortField) { switch ($sort) { case 'up': $selectNameUp = $selected; - $order = array('field' => 'nombre ' . $order_collation, - 'field2' => 'nombre ' . $order_collation, + $order = array('field' => 'alias ' . $order_collation, + 'field2' => 'alias ' . $order_collation, 'order' => 'ASC'); break; case 'down': $selectNameDown = $selected; - $order = array('field' => 'nombre ' . $order_collation, - 'field2' => 'nombre ' . $order_collation, + $order = array('field' => 'alias ' . $order_collation, + 'field2' => 'alias ' . $order_collation, 'order' => 'DESC'); break; } @@ -232,13 +232,13 @@ switch ($sortField) { case 'up': $selectOsUp = $selected; $order = array('field' => 'id_os', - 'field2' => 'nombre ' . $order_collation, + 'field2' => 'alias ' . $order_collation, 'order' => 'ASC'); break; case 'down': $selectOsDown = $selected; $order = array('field' => 'id_os', - 'field2' => 'nombre ' . $order_collation, + 'field2' => 'alias ' . $order_collation, 'order' => 'DESC'); break; } @@ -248,13 +248,13 @@ switch ($sortField) { case 'up': $selectGroupUp = $selected; $order = array('field' => 'id_grupo', - 'field2' => 'nombre ' . $order_collation, + 'field2' => 'alias ' . $order_collation, 'order' => 'ASC'); break; case 'down': $selectGroupDown = $selected; $order = array('field' => 'id_grupo', - 'field2' => 'nombre ' . $order_collation, + 'field2' => 'alias ' . $order_collation, 'order' => 'DESC'); break; } @@ -266,8 +266,8 @@ switch ($sortField) { $selectOsDown = ''; $selectGroupUp = ''; $selectGroupDown = ''; - $order = array('field' => 'nombre ' . $order_collation, - 'field2' => 'nombre ' . $order_collation, + $order = array('field' => 'alias ' . $order_collation, + 'field2' => 'alias ' . $order_collation, 'order' => 'ASC'); break; } @@ -292,8 +292,9 @@ if ($search != "") { } $search_sql .= ")"; }else{ - $search_sql = " AND ( LOWER(nombre) " . $order_collation . " - LIKE LOWER('%$search%')) "; + $search_sql = " AND ( nombre " . $order_collation . " + LIKE '%$search%' OR alias " . $order_collation . " + LIKE '%$search%') "; } } @@ -386,7 +387,7 @@ else { FROM tagente WHERE 1=1 %s - ORDER BY %s %s %s LIMIT %d OFFSET %d', $search_sql, $order['field'], $order['field2'], + ORDER BY %s %s, %s %s LIMIT %d OFFSET %d', $search_sql, $order['field'],$order['order'], $order['field2'], $order['order'], $config["block_size"], $offset); break; case "oracle": @@ -397,7 +398,7 @@ else { FROM tagente WHERE 1=1 %s - ORDER BY %s %s %s', $search_sql, $order['field'], $order['field2'], $order['order']); + ORDER BY %s %s, %s %s', $search_sql, $order['field'],$order['order'], $order['field2'], $order['order']); $sql = oracle_recode_query ($sql, $set); break; } @@ -547,11 +548,14 @@ if ($agents !== false) { else { $main_tab = 'module'; } - - echo "" . - ui_print_truncate_text($agent["nombre"], 'agent_medium', true, true, true, '[…]', 'font-size: 7pt') . + ''.$agent["alias"].'' . ""; echo ""; if ($agent["disabled"]) { diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php index dc3244e51e..120cba7efe 100644 --- a/pandora_console/godmode/agentes/planned_downtime.editor.php +++ b/pandora_console/godmode/agentes/planned_downtime.editor.php @@ -672,7 +672,7 @@ if ($id_downtime > 0) { } - $sql = sprintf("SELECT tagente.id_agente, tagente.nombre + $sql = sprintf("SELECT tagente.id_agente, tagente.alias FROM tagente WHERE tagente.id_agente NOT IN ( SELECT tagente.id_agente @@ -687,7 +687,7 @@ if ($id_downtime > 0) { $agents = array(); $agent_ids = extract_column($agents, 'id_agente'); - $agent_names = extract_column($agents, 'nombre'); + $agent_names = extract_column($agents, 'alias'); // item[] = ; $agents = array_combine($agent_ids, $agent_names); if ($agents === false) @@ -765,7 +765,8 @@ if ($id_downtime > 0) { foreach ($downtimes_agents as $downtime_agent) { $data = array (); - $data[0] = $downtime_agent['nombre']; + $alias = db_get_value("alias","tagente","id_agente",$downtime_agent['id_agente']); + $data[0] = $alias; $data[1] = db_get_sql ("SELECT nombre FROM tgrupo diff --git a/pandora_console/godmode/agentes/planned_downtime.export_csv.php b/pandora_console/godmode/agentes/planned_downtime.export_csv.php index ea320fddc6..5b9a6a06e7 100644 --- a/pandora_console/godmode/agentes/planned_downtime.export_csv.php +++ b/pandora_console/godmode/agentes/planned_downtime.export_csv.php @@ -150,7 +150,7 @@ if (!empty($downtimes)) { $affected_items = array(); - $sql_agents = "SELECT tpda.id_agent AS agent_id, tpda.all_modules AS all_modules, ta.nombre AS agent_name + $sql_agents = "SELECT tpda.id_agent AS agent_id, tpda.all_modules AS all_modules, ta.nombre AS agent_name, ta.alias FROM tplanned_downtime_agents tpda, tagente ta WHERE tpda.id_downtime = $id AND tpda.id_agent = ta.id_agente"; @@ -159,7 +159,7 @@ if (!empty($downtimes)) { if (!empty($downtime_agents)) { foreach ($downtime_agents as $downtime_agent) { $downtime_items = array(); - $downtime_items[] = $downtime_agent['agent_name']; + $downtime_items[] = $downtime_agent[alias]; if (!$downtime_agent['all_modules']) { $agent_id = $downtime_agent['agent_id']; diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 986daa1550..62ab5b3ca9 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -189,12 +189,12 @@ if ($searchFlag) { case "postgresql": $where .= " AND id_agent_module IN (SELECT t2.id_agente_modulo FROM tagente t1 INNER JOIN tagente_modulo t2 ON t1.id_agente = t2.id_agente - WHERE t1.nombre LIKE '" . trim($agentName) . "')"; + WHERE t1.alias LIKE '" . trim($agentName) . "')"; break; case "oracle": $where .= " AND id_agent_module IN (SELECT t2.id_agente_modulo FROM tagente t1 INNER JOIN tagente_modulo t2 ON t1.id_agente = t2.id_agente - WHERE t1.nombre LIKE '" . trim($agentName) . "')"; + WHERE t1.alias LIKE '" . trim($agentName) . "')"; break; } } @@ -459,8 +459,8 @@ foreach ($simple_alerts as $alert) { if ($alert['disabled']) $data[0] .= ''; - $agent_name = agents_get_name ($id_agent); - $data[0] .= ui_print_truncate_text($agent_name, 'agent_small', false, true, true, '[…]', 'display:block;font-size: 7.2pt'); + $alias = db_get_value ("alias","tagente","id_agente",$id_agent); + $data[0] .= $alias; if ($alert['disabled']) $data[0] .= ''; diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index 5dadc22038..5c276332e7 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -82,7 +82,7 @@ if ($id) { } } if ($id_agent != 0) { - $text_agent = db_get_value('nombre', 'tagente', 'id_agente', $id_agent); + $text_agent = db_get_value('alias', 'tagente', 'id_agente', $id_agent); if ($text_agent == false) { $text_agent = ''; } diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php index d5f800305a..679832c8cf 100755 --- a/pandora_console/godmode/massive/massive_delete_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_alerts.php @@ -49,13 +49,13 @@ if (is_ajax ()) { $agents_alerts = array(); foreach( $groups as $group ) { $agents_alerts_one_group = alerts_get_agents_with_alert_template ($id_alert_template, $group, - false, array ('tagente.nombre', 'tagente.id_agente')); + false, array ('tagente.alias', 'tagente.id_agente')); if (is_array($agents_alerts_one_group)) { $agents_alerts = array_merge($agents_alerts, $agents_alerts_one_group); } } - $agents = index_array ($agents_alerts, 'id_agente', 'nombre'); + $agents = index_array ($agents_alerts, 'id_agente', 'alias'); asort($agents); @@ -220,8 +220,9 @@ $table->data[2][0] .= ''; $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_template, $id_group, - false, array ('tagente.nombre', 'tagente.id_agente')); -$table->data[2][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'nombre'), + false, array ('tagente.alias', 'tagente.id_agente')); +html_debug($agents_alerts); +$table->data[2][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'alias'), 'id_agents[]', '', '', '', '', true, true, true, '', $id_alert_template == 0); $table->data[2][2] = __('When select agents'); $table->data[2][2] .= '
'; diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php index b23be0abaf..04814ed1b6 100755 --- a/pandora_console/godmode/massive/massive_delete_modules.php +++ b/pandora_console/godmode/massive/massive_delete_modules.php @@ -39,10 +39,10 @@ if (is_ajax ()) { $agents_modules = modules_get_agents_with_module_name ($module_name, $id_group, array ('delete_pending' => 0, 'tagente_modulo.disabled' => 0), - array ('tagente.id_agente', 'tagente.nombre'), + array ('tagente.id_agente', 'tagente.alias'), $recursion); - echo json_encode (index_array ($agents_modules, 'id_agente', 'nombre')); + echo json_encode (index_array ($agents_modules, 'id_agente', 'alias')); return; } return; @@ -702,7 +702,7 @@ $(document).ready (function () { option = $("") .attr ("value", value["id_agente"]) - .html (value["nombre"]); + .html (value["alias"]); $("#id_agents").append (option); }); }, @@ -729,6 +729,12 @@ $(document).ready (function () { } }); + if(""){ + if("" == 'agents'){ + $("#groups_select").trigger("change"); + } + } + $("#status_module").change(function() { selector = $("#form_modules input[name=selection_mode]:checked").val(); if(selector == 'agents') { diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index bbf87c2bc7..26942b9c4a 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -59,7 +59,7 @@ if ($update_agents) { if (get_parameter ('id_os', '') != -1) $values['id_os'] = get_parameter ('id_os'); if (get_parameter ('id_parent', '') != '') - $values['id_parent'] = agents_get_agent_id(get_parameter('id_parent')); + $values['id_parent'] = get_parameter('id_agent_parent', 0); if (get_parameter ('server_name', '') != -1) $values['server_name'] = get_parameter ('server_name'); if (get_parameter ('description', '') != '') @@ -282,7 +282,10 @@ $params = array(); $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'id_parent'; -$params['value'] = agents_get_name ($id_parent); +$params['print_hidden_input_idagent'] = true; +$params['hidden_input_idagent_name'] = 'id_agent_parent'; +$params['hidden_input_idagent_value'] = $id_parent; +$params['value'] = db_get_value ("alias","tagente","id_agente",$id_parent); $table->data[0][1] = ui_print_agent_autocomplete_input($params); $table->data[0][1] .= "" . __('Cascade protection'). " " . diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index c680335429..bfc3aab6de 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -1010,7 +1010,7 @@ $(document).ready (function () { option = $("") .attr("value", value["id_agente"]) - .html(value["nombre"]); + .html(value["alias"]); $("#id_agents").append (option); }); }, @@ -1023,6 +1023,13 @@ $(document).ready (function () { $("#groups_select").trigger("change"); }); + + if(""){ + if("" == 'agents'){ + $("#groups_select").trigger("change"); + } + } + $("#status_module").change(function() { selector = $("#form_edit input[name=selection_mode]:checked").val(); @@ -1033,6 +1040,7 @@ $(document).ready (function () { $("#module_type").trigger("change"); } }); + }); function disabled_status () { diff --git a/pandora_console/godmode/massive/massive_enable_disable_alerts.php b/pandora_console/godmode/massive/massive_enable_disable_alerts.php index 78590ccd38..7d799c1f70 100644 --- a/pandora_console/godmode/massive/massive_enable_disable_alerts.php +++ b/pandora_console/godmode/massive/massive_enable_disable_alerts.php @@ -49,8 +49,8 @@ if (is_ajax ()) { $disabled = (int) get_parameter ('disabled'); $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_templates, false, - array('order' => 'tagente.nombre, talert_template_modules.disabled', 'talert_template_modules.disabled' => $disabled), - array ('CONCAT(tagente.nombre, " - ", tagente_modulo.nombre) as agent_agentmodule_name', + array('order' => 'tagente.alias, talert_template_modules.disabled', 'talert_template_modules.disabled' => $disabled), + array ('CONCAT(tagente.alias, " - ", tagente_modulo.nombre) as agent_agentmodule_name', 'talert_template_modules.id as template_module_id'), $id_agents); echo json_encode (index_array ($agents_alerts, 'template_module_id', 'agent_agentmodule_name')); @@ -156,8 +156,8 @@ $table->data[3][0] .= ''; $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_templates, $id_group, - false, array ('tagente.nombre', 'tagente.id_agente')); -$table->data[3][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'nombre'), + false, array ('tagente.alias', 'tagente.id_agente')); +$table->data[3][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'alias'), 'id_enabled_alerts[]', '', '', '', '', true, true, true, '', $id_alert_templates == 0); $table->data[4][0] = __('Action'); diff --git a/pandora_console/godmode/massive/massive_standby_alerts.php b/pandora_console/godmode/massive/massive_standby_alerts.php index ed6b4167c5..6af3940680 100644 --- a/pandora_console/godmode/massive/massive_standby_alerts.php +++ b/pandora_console/godmode/massive/massive_standby_alerts.php @@ -49,8 +49,8 @@ if (is_ajax ()) { $standby = (int) get_parameter ('standby'); $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_templates, false, - array('order' => 'tagente.nombre, talert_template_modules.standby', 'talert_template_modules.standby' => $standby), - array ('CONCAT(tagente.nombre, " - ", tagente_modulo.nombre) as agent_agentmodule_name', + array('order' => 'tagente.alias, talert_template_modules.standby', 'talert_template_modules.standby' => $standby), + array ('CONCAT(tagente.alias, " - ", tagente_modulo.nombre) as agent_agentmodule_name', 'talert_template_modules.id as template_module_id'), $id_agents); echo json_encode (index_array ($agents_alerts, 'template_module_id', 'agent_agentmodule_name')); @@ -156,8 +156,8 @@ $table->data[3][0] .= ''; $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_templates, $id_group, - false, array ('tagente.nombre', 'tagente.id_agente')); -$table->data[3][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'nombre'), + false, array ('tagente.alias', 'tagente.id_agente')); +$table->data[3][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'alias'), 'id_not_standby_alerts[]', '', '', '', '', true, true, true, '', $id_alert_templates == 0); $table->data[4][0] = __('Action'); @@ -172,7 +172,7 @@ $table->data[5][0] = __('Standby alerts').ui_print_help_tip(__('Format').":
$table->data[5][0] .= ''; -$table->data[5][1] = html_print_select (index_array ($agents_alerts, 'id_agente2', 'nombre'), +$table->data[5][1] = html_print_select (index_array ($agents_alerts, 'id_agente2', 'alias'), 'id_standby_alerts[]', '', '', '', '', true, true, true, '', $id_alert_templates == 0); $table->data[5][1] .= ''; diff --git a/pandora_console/godmode/reporting/graph_builder.graph_editor.php b/pandora_console/godmode/reporting/graph_builder.graph_editor.php index 8e5d8b5d48..cc20e1cfe7 100644 --- a/pandora_console/godmode/reporting/graph_builder.graph_editor.php +++ b/pandora_console/godmode/reporting/graph_builder.graph_editor.php @@ -41,7 +41,7 @@ if (isset ($_GET["get_agent"])) { if ($editGraph) { $graphRows = db_get_all_rows_sql("SELECT t1.*, - (SELECT t3.nombre + (SELECT t3.alias FROM tagente t3 WHERE t3.id_agente = (SELECT t2.id_agente diff --git a/pandora_console/godmode/reporting/reporting_builder.list_items.php b/pandora_console/godmode/reporting/reporting_builder.list_items.php index 84dc835f8f..c66ff26f0d 100755 --- a/pandora_console/godmode/reporting/reporting_builder.list_items.php +++ b/pandora_console/godmode/reporting/reporting_builder.list_items.php @@ -87,7 +87,8 @@ else { $agents = array(); foreach ($rows as $row) { - $agents[$row['id_agente']] = $row['nombre']; + $alias = db_get_value ("alias","tagente","id_agente",$row['id_agente']); + $agents[$row['id_agente']] = $alias; } switch ($config['dbtype']) { @@ -372,15 +373,17 @@ foreach ($items as $item) { $agent_name_db = array(); foreach ($agents as $a) { - $agent_name_db[] = agents_get_name($a); + + $alias = db_get_value ("alias","tagente","id_agente",$a); + $agent_name_db[] = $alias; } $agent_name_db = implode('
',$agent_name_db); $module_name_db = implode('
',$modules); } else { - $agent_name_db = agents_get_name(agents_get_agent_id_by_module_id($item['id_agent_module'])); - $agent_name_db = ui_print_truncate_text($agent_name_db, 'agent_small'); + $alias = db_get_value ("alias","tagente","id_agente",agents_get_agent_id_by_module_id($item['id_agent_module'])); + $agent_name_db = '' .$alias . ''; $module_name_db = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $item['id_agent_module'])); $module_name_db = ui_print_truncate_text(io_safe_output($module_name_db), 'module_small'); } @@ -390,7 +393,8 @@ foreach ($items as $item) { } } else { - $row[2] = ui_print_truncate_text(agents_get_name($item['id_agent']), 'agent_small'); + $alias = db_get_value ("alias","tagente","id_agente",$item['id_agent']); + $row[2] = '' .$alias . ''; if ($item['id_agent_module'] == '') { $row [3] = ''; diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index b1a6b040d9..eba416fb73 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -437,6 +437,7 @@ function readFields() { values['left'] = $("input[name=left]").val(); values['top'] = $("input[name=top]").val(); values['agent'] = $("input[name=agent]").val(); + values['id_agent'] = $("input[name=id_agent]").val(); values['module'] = $("select[name=module]").val(); values['process_simple_value'] = $("select[name=process_value]").val(); values['background'] = $("#background_image").val(); @@ -997,6 +998,9 @@ function loadFieldsFromDB(item) { $("input[name=agent]").val(val); //Reload no-sincrone the select of modules } + if (key == 'id_agent') { + $("input[name=id_agent]").val(val); + } if (key == 'modules_html') { $("select[name=module]").empty().html(val); $("select[name=module]").val(moduleId); diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.php b/pandora_console/godmode/reporting/visual_console_builder.editor.php index 64bb54fdc1..bff4bcb1e9 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.php +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.php @@ -87,10 +87,7 @@ echo "
$agent['id_agente'], 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), 'ip' => io_safe_output($agent['direccion']), 'filter' => 'agent'); } @@ -136,11 +137,12 @@ if ($search_agents && (!is_metaconsole() || $force_local)) { $filter_address[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))'; break; } - $agents = agents_get_agents($filter_address, array ('id_agente', 'nombre', 'direccion')); + $agents = agents_get_agents($filter_address, array ('id_agente', 'nombre', 'direccion', 'alias')); if ($agents !== false) { foreach ($agents as $agent) { $data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), 'ip' => io_safe_output($agent['direccion']), 'filter' => 'address'); } @@ -159,16 +161,40 @@ if ($search_agents && (!is_metaconsole() || $force_local)) { $filter_description[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))'; break; } - $agents = agents_get_agents($filter_description, array ('id_agente', 'nombre', 'direccion')); + $agents = agents_get_agents($filter_description, array ('id_agente', 'nombre', 'direccion', 'alias')); if ($agents !== false) { foreach ($agents as $agent) { $data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), 'ip' => io_safe_output($agent['direccion']), 'filter' => 'description'); } } - + + //Get agents for only the alias + $filter_description = $filter; + switch ($config['dbtype']) { + case "mysql": + $filter_description[] = '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion NOT LIKE "%'.$string.'%" AND comentarios NOT LIKE "%'.$string.'%" AND alias LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_description[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion NOT LIKE \'%'.$string.'%\' AND comentarios NOT LIKE \'%'.$string.'%\' AND alias LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_description[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(comentarios) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(alias) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } + $agents = agents_get_agents($filter_description, array ('id_agente', 'nombre', 'direccion', 'alias')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'alias'); + } + } echo json_encode($data); return; } diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 0af4054f3e..0d5dd4abe4 100755 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -478,6 +478,9 @@ switch ($action) { $values['id_agent'] = $id_agent; } } + else if (!empty($id_agent)) { + $values['id_agent'] = $id_agent; + } else if ($agent !== null) { $id_agent = agents_get_agent_id($agent); $values['id_agent'] = $id_agent; @@ -664,12 +667,12 @@ switch ($action) { if (!empty($connection['server_name'])) { $elementFields['agent_name'] = - io_safe_output(agents_get_name($elementFields['id_agent'])) + io_safe_output(agents_get_alias($elementFields['id_agent'])) . " (" . io_safe_output($connection['server_name']) . ")"; } else { $elementFields['agent_name'] = - io_safe_output(agents_get_name($elementFields['id_agent'])); + io_safe_output(agents_get_alias($elementFields['id_agent'])); } //Make the html of select box of modules about id_agent. @@ -784,10 +787,15 @@ switch ($action) { $values['id_agent'] = $id_agent; } else { - if ($agent != '') + if (!empty($id_agent)) { + $values['id_agent'] = $id_agent; + } + else if (!empty($agent)) { $values['id_agent'] = agents_get_agent_id($agent); - else + } + else { $values['id_agent'] = 0; + } } $values['id_agente_modulo'] = $id_module; $values['id_layout_linked'] = $map_linked; diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 86ec3fa099..7d44dc1df4 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -234,7 +234,7 @@ class Tree { // Agent name filter $agent_search_filter = ""; if (!empty($this->filter['searchAgent'])) { - $agent_search_filter = " AND LOWER(ta.nombre) LIKE LOWER('%".$this->filter['searchAgent']."%')"; + $agent_search_filter = " AND LOWER(ta.nombre) LIKE LOWER('%".$this->filter['searchAgent']."%') OR ta.alias LIKE '%".$this->filter['searchAgent']."%'"; } // Agent status filter @@ -409,15 +409,15 @@ class Tree { } else { if (! is_metaconsole() || $this->strictACL) { - $columns = 'ta.id_agente AS id, ta.nombre AS name, + $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, + $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $order_fields = 'ta.nombre ASC, ta.id_agente ASC'; + $order_fields = 'ta.alias ASC, ta.id_agente ASC'; $sql = "SELECT $columns FROM tagente ta @@ -435,11 +435,11 @@ class Tree { ORDER BY $order_fields"; } else { - $columns = 'ta.id_tagente AS id, ta.nombre AS name, + $columns = 'ta.id_tagente AS id, ta.nombre AS name, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet, id_tmetaconsole_setup AS server_id'; - $order_fields = 'ta.nombre ASC, ta.id_tagente ASC'; + $order_fields = 'ta.alias ASC, ta.id_tagente ASC'; $sql = "SELECT $columns FROM tmetaconsole_agent ta @@ -595,15 +595,15 @@ class Tree { } } else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, + $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, + $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $order_fields = 'ta.nombre ASC, ta.id_agente ASC'; + $order_fields = 'ta.alias ASC, ta.id_agente ASC'; $sql = "SELECT $columns FROM tagente ta @@ -718,15 +718,15 @@ class Tree { } } else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, + $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, + $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $order_fields = 'ta.nombre ASC, ta.id_agente ASC'; + $order_fields = 'ta.alias ASC, ta.id_agente ASC'; $sql = "SELECT $columns FROM tagente ta @@ -847,15 +847,15 @@ class Tree { } } else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, + $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, + $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $order_fields = 'ta.nombre ASC, ta.id_agente ASC'; + $order_fields = 'ta.alias ASC, ta.id_agente ASC'; $sql = "SELECT $columns FROM tagente ta @@ -978,15 +978,15 @@ class Tree { } } else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, + $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, + $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet'; - $order_fields = 'ta.nombre ASC, ta.id_agente ASC'; + $order_fields = 'ta.alias ASC, ta.id_agente ASC'; $symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~'; $name = $rootID; diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 98a5f9d414..ccb02da5f7 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -221,7 +221,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f } } - $selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.nombre AS agent_name, t4.name AS template_name'; + $selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.alias AS agent_name, t4.name AS template_name'; if ($count !== false) { $selectText = 'COUNT(talert_template_modules.id) AS count'; } @@ -890,6 +890,21 @@ function agents_get_group_agents ($id_group = 0, $search = false, unset ($search["name"]); } + if (isset ($search["alias"])) { + $name = io_safe_input ($search["alias"]); + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $filter[] = "alias COLLATE utf8_general_ci LIKE '$name'"; + break; + case "oracle": + $filter[] = "UPPER(alias) LIKE UPPER('$name')"; + break; + } + + unset ($search["alias"]); + } + if (isset($search['status'])) { switch ($search['status']) { case AGENT_STATUS_NORMAL: @@ -941,14 +956,14 @@ function agents_get_group_agents ($id_group = 0, $search = false, $filter['disabled'] = 0; } - $filter['order'] = 'nombre'; + $filter['order'] = 'alias'; if (is_metaconsole()) { $table_name = 'tmetaconsole_agent'; $fields = array( 'id_tagente AS id_agente', - 'nombre', + 'alias', 'id_tmetaconsole_setup AS id_server' ); } @@ -957,7 +972,7 @@ function agents_get_group_agents ($id_group = 0, $search = false, $fields = array( 'id_agente', - 'nombre' + 'alias' ); } @@ -968,7 +983,7 @@ function agents_get_group_agents ($id_group = 0, $search = false, $agents = array (); foreach ($result as $row) { - if (!isset($row["id_agente"]) || !isset($row["nombre"])) + if (!isset($row["id_agente"]) || !isset($row["alias"])) continue; if ($serialized && isset($row["id_server"])) { @@ -980,13 +995,13 @@ function agents_get_group_agents ($id_group = 0, $search = false, switch ($case) { case "lower": - $value = mb_strtolower ($row["nombre"], "UTF-8"); + $value = mb_strtolower ($row["alias"], "UTF-8"); break; case "upper": - $value = mb_strtoupper ($row["nombre"], "UTF-8"); + $value = mb_strtoupper ($row["alias"], "UTF-8"); break; default: - $value = $row["nombre"]; + $value = $row["alias"]; break; } @@ -1310,6 +1325,28 @@ function agents_get_name ($id_agent, $case = "none") { } } +/** + * Get alias of an agent. + * + * @param int $id_agent Agent id. + * @param string $case Case (upper, lower, none) + * + * @return string Alias of the given agent. + */ +function agents_get_alias ($id_agent, $case = 'none') { + $alias = (string) db_get_value ('alias', 'tagente', 'id_agente', (int) $id_agent); + + switch ($case) { + case 'upper': + return mb_strtoupper($alias, 'UTF-8'); + case 'lower': + return mb_strtolower($alias, 'UTF-8'); + case 'none': + default: + return ($alias); + } +} + /** * Get the number of pandora data packets in the database. * diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 6c100d9003..2b166cd331 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1822,7 +1822,7 @@ function get_group_alerts($id_group, $filter = '', $options = false, } } - $selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.nombre AS agent_name, t4.name AS template_name'; + $selectText = 'talert_template_modules.*, t2.nombre AS agent_module_name, t3.alias AS agent_name, t4.name AS template_name'; if ($count !== false) { $selectText = 'COUNT(talert_template_modules.id) AS count'; } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 9536794820..235a839689 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -979,7 +979,7 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret $myclass = get_priority_class ($event["criticity"]); $data[4] = "". - agents_get_name ($event["id_agente"]). ""; + agents_get_alias($event["id_agente"]). ""; // ui_print_agent_name ($event["id_agente"], true, 25, '', true); // for System or SNMP generated alerts @@ -2017,10 +2017,13 @@ function events_page_details ($event, $server = "") { $data = array(); $data[0] = '
'.__('Name').'
'; if (can_user_access_node ()) { - $data[1] = ui_print_agent_name ($event["id_agente"], true, 'agent_medium', '', false, $serverstring, $hashstring, $agent['nombre']); + //$data[1] = ui_print_agent_name ($event["id_agente"], true, 'agent_medium', '', false, $serverstring, $hashstring, $agent['nombre']); + $alias = db_get_row ("tagente","id_agente",$event["id_agente"]); + $data[1] = ''; + $data[1] .= '' . $alias['alias'] . ''; } else { - $data[1] = ui_print_truncate_text($agent['nombre'], 'agent_medium', true, true, true); + $data[1] = ui_print_truncate_text($agent['alias'], 'agent_medium', true, true, true); } $table_details->data[] = $data; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 541983d8d9..2fafb9a24b 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1221,19 +1221,21 @@ function graphic_combined_module ($module_list, $weight_list, $period, else { $agent_name = io_safe_output( modules_get_agentmodule_agent_name ($agent_module_id)); + $alias = db_get_value ("alias","tagente","nombre",$agent_name); $module_name = io_safe_output( modules_get_agentmodule_name ($agent_module_id)); if ($flash_charts) - $module_name_list[$i] = '' . $agent_name . " / " . $module_name. ''; + $module_name_list[$i] = '' . $alias . " / " . $module_name. ''; else - $module_name_list[$i] = $agent_name . " / " . $module_name; + $module_name_list[$i] = $alias . " / " . $module_name; } } else { //Get and process agent name $agent_name = io_safe_output( modules_get_agentmodule_agent_name ($agent_module_id)); + $alias = db_get_value ("alias","tagente","nombre",$agent_name); $agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false); $agent_id = agents_get_agent_id ($agent_name); @@ -1252,13 +1254,13 @@ function graphic_combined_module ($module_list, $weight_list, $period, else $module_name_list[$i] = '' . - $agent_name . ' / ' . $module_name . ''; + $alias . ' / ' . $module_name . ''; } else { if ($labels[$agent_module_id] != '') $module_name_list[$i] = $labels[$agent_module_id]; else - $module_name_list[$i] = $agent_name . ' / ' . $module_name; + $module_name_list[$i] = $alias . ' / ' . $module_name; } } @@ -1522,11 +1524,13 @@ function graphic_combined_module ($module_list, $weight_list, $period, $value = false; } - - if ( !empty($labels) && isset($labels[$module]) ) - $label = io_safe_input($labels[$module]); - else - $label = agents_get_name($temp[$module]['id_agente']) . ': ' . $temp[$module]['nombre']; + if ( !empty($labels) && isset($labels[$module]) ){ + $label = io_safe_input($labels[$module]); + }else{ + $alias = db_get_value ("alias","tagente","id_agente",$temp[$module]['id_agente']); + $label = $alias . ': ' . $temp[$module]['nombre']; + } + $temp[$module]['label'] = $label; $temp[$module]['value'] = $value; @@ -1589,10 +1593,13 @@ function graphic_combined_module ($module_list, $weight_list, $period, $agent_name = io_safe_output( modules_get_agentmodule_agent_name ($module)); - if (!empty($labels) && isset($labels[$module]) ) - $label = $labels[$module]; - else - $label = $agent_name . " - " .$module_data['nombre']; + if (!empty($labels) && isset($labels[$module]) ){ + $label = $labels[$module]; + }else { + $alias = db_get_value ("alias","tagente","id_agente",$module_data['id_agente']); + $label = $alias . " - " .$module_data['nombre']; + } + $temp[$label]['g'] = round($temp_data,4); @@ -1649,8 +1656,8 @@ function graphic_combined_module ($module_list, $weight_list, $period, if ( !empty($labels) && isset($labels[$module]) ){ $label = io_safe_output($labels[$module]); }else { - $agent_name = agents_get_name($data_module['id_agente']); - $label = io_safe_output($agent_name . ": " . $data_module['nombre']); + $alias = db_get_value ("alias","tagente","id_agente",$data_module['id_agente']); + $label = io_safe_output($alias . ": " . $data_module['nombre']); } $temp[$label] = array('value'=>$value, @@ -3126,7 +3133,9 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta = $name = mb_substr (io_safe_output($row['agent_name']), 0, 14)." (".$row["count"].")"; } else { - $name = mb_substr (agents_get_name ($row["id_agente"], "lower"), 0, 14)." (".$row["count"].")"; + $alias = db_get_value ("alias","tagente","id_agente",$row["id_agente"]); + //$name = mb_substr (agents_get_name ($row["id_agente"], "lower"), 0, 14)." (".$row["count"].")"; + $name = mb_substr ($alias, 0, 14)." (".$row["count"].")"; } $data[$name] = $row["count"]; } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 5513ae9401..12d2d5583e 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1023,6 +1023,18 @@ function modules_get_agentmodule_agent_name ($id_agentmodule) { return (string) agents_get_name (modules_get_agentmodule_agent ($id_agentmodule)); } +/** + * Get agent alias of an agent module. + * + * @param int $id_agente_modulo Agent module id. + * + * @return string The alias of the given agent module. + */ +function modules_get_agentmodule_agent_alias ($id_agentmodule) { + // Since this is a helper function we don't need to do casting + return (string) agents_get_alias (modules_get_agentmodule_agent ($id_agentmodule)); +} + /** * Get the module name of an agent module. * diff --git a/pandora_console/include/functions_pandora_networkmap.php b/pandora_console/include/functions_pandora_networkmap.php index db2fb980bb..fde4a78a3d 100644 --- a/pandora_console/include/functions_pandora_networkmap.php +++ b/pandora_console/include/functions_pandora_networkmap.php @@ -851,7 +851,7 @@ function networkmap_loadfile($id = 0, $file = '', case 'agent': $data['id_agent'] = $ids[$node_id]['id_agent']; - $text = agents_get_name($ids[$node_id]['id_agent']); + $text = agents_get_alias($ids[$node_id]['id_agent']); $text = io_safe_output($text); $text = ui_print_truncate_text($text, 'agent_medium', false, true, false, diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 5ca2ebd82a..c343620bda 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -152,6 +152,10 @@ function reporting_html_print_report($report, $mini = false, $report_info = 1) { } else $label = ''; + + $aux = explode("-",$item['subtitle']); + $item['subtitle'] = db_get_value ("alias","tagente","nombre",$item['agent_name']) .' -'. $aux[1]; + reporting_html_header($table, $mini, $item['title'], $item['subtitle'], @@ -1224,8 +1228,9 @@ function reporting_html_inventory_changes($table, $item) { $table1->data[2][0] = __('Added'); $table1->colspan[2][0] = 2; - - $table1->data = array_merge($table1->data, $module_item['added']); + if (count ($module_item['added'])) { + $table1->data = array_merge($table1->data, $module_item['added']); + } $table1->cellstyle[3 + count($module_item['added'])][0] = @@ -1233,8 +1238,9 @@ function reporting_html_inventory_changes($table, $item) { $table1->data[3 + count($module_item['added'])][0] = __('Deleted'); $table1->colspan[3 + count($module_item['added'])][0] = 2; - - $table1->data = array_merge($table1->data, $module_item['deleted']); + if (count ($module_item['deleted'])) { + $table1->data = array_merge($table1->data, $module_item['deleted']); + } $table->colspan[ diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 047be52917..86def7662e 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -522,8 +522,9 @@ function treeview_printTable($id_agente, $server_data = array(), $no_head = fals else { $cellName = ''; } - - $cellName .= ui_print_agent_name ($agent["id_agente"], true, 500, "text-transform: uppercase;", true, $console_url, $url_hash, false, $user_access_node); + + $cellName .= '' . + ''.$agent["alias"].''; if ($agent['disabled']) { $cellName .= ui_print_help_tip(__('Disabled'), true) . ""; @@ -780,4 +781,4 @@ function treeview_printTable($id_agente, $server_data = array(), $no_head = fals return; } -?> \ No newline at end of file +?> diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 30a6736eaf..60360ccdc7 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -787,6 +787,7 @@ function ui_format_alert_row ($alert, $agent = true, $url = '', $agent_style = f // Get agent id $id_agent = modules_get_agentmodule_agent ($alert['id_agent_module']); + $agente = db_get_row ('tagente', 'id_agente', $id_agent); $template = alerts_get_alert_template ($alert['id_alert_template']); $description = io_safe_output($template['name']); @@ -847,10 +848,10 @@ function ui_format_alert_row ($alert, $agent = true, $url = '', $agent_style = f } else { if ($agent_style !== false) { - $data[$index['agent_name']] .= ui_print_agent_name ($id_agent, true, 'agent_medium', $styleDisabled . " $agent_style", false, $console_url, $url_hash, $agent_name); + $data[$index['agent_name']] .=' '.$agente["alias"].''; } else { - $data[$index['agent_name']] .= ui_print_agent_name ($id_agent, true, 'agent_medium', $styleDisabled, false, $console_url, $url_hash); + $data[$index['agent_name']] .= ' '.$agente["alias"].''; } } @@ -2390,7 +2391,8 @@ function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = fal * @return string Header HTML */ -function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $godmode = false, $options = "",$modal = false, $message = "", $numChars = GENERIC_SIZE_TEXT) { + +function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $godmode = false, $options = "", $modal = false, $message = "", $numChars = GENERIC_SIZE_TEXT, $alias = "") { $title = io_safe_input_html($title); if (($icon == "") && ($godmode == true)) { $icon = "images/gm_setup.png"; @@ -2415,9 +2417,14 @@ function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $buffer .= '
  •  ' . '  '; - $buffer .= '' . - ui_print_truncate_text($title, $numChars); - + if(strpos($title, "Monitoring » Services »") != -1){ + $title = str_replace("Monitoring » Services » Service Map » ",'',$title); + } + + $buffer .= ''; + if (empty($alias)) $buffer .= ui_print_truncate_text($title, $numChars); + else $buffer .= ui_print_truncate_text($alias, $numChars); + if ($modal && !enterprise_installed()){ $buffer .= "
    @@ -3206,7 +3213,7 @@ function ui_print_agent_autocomplete_input($parameters) { select: function( event, ui ) { - var agent_name = ui.item.name; + var agent_name = ui.item.alias; var agent_id = ui.item.id; var server_name = ""; var server_id = ""; @@ -3264,10 +3271,10 @@ function ui_print_agent_autocomplete_input($parameters) { }) .data("ui-autocomplete")._renderItem = function( ul, item ) { if (item.ip == "") { - text = "" + item.name + ""; + text = "" + item.alias+ ""; } else { - text = "" + item.name + text = "" + item.alias + "
    IP:" + item.ip + "
    "; } @@ -3291,6 +3298,12 @@ function ui_print_agent_autocomplete_input($parameters) { .append(text) .appendTo(ul); break; + case \'alias\': + return $("
  • ") + .data("item.autocomplete", item) + .append(text) + .appendTo(ul); + break; } diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 65eb95e746..e10c8c00dc 100755 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -122,8 +122,6 @@ function visual_map_print_item($mode = "read", $layoutData, $left = $left * $proportion['proportion_width']; } - $agentname = agents_get_name(agents_get_module_id ($id_module)); - $label = str_replace(ui_print_truncate_text($agentname, 'agent_small', false, true, false, '…', false), $agentname, $label); $text = '' . $label .''; if($height == 0){ @@ -1670,7 +1668,7 @@ function visual_map_process_wizard_add ($id_agents, $image, $id_layout, $range, break; } - $label = agents_get_name($id_agent); + $label = agents_get_alias($id_agent); $value_label = '(_VALUE_)'; if ($type === SIMPLE_VALUE) { @@ -1747,12 +1745,12 @@ function visual_map_process_wizard_add_modules ($id_modules, $image, } } - $id_agent = modules_get_agentmodule_agent ($id_module); + $id_agent = modules_get_agentmodule_agent($id_module); switch ($label_type) { case 'agent_module': default: - $agent_label = agents_get_name ($id_agent); + $agent_label = agents_get_alias($id_agent); $module_label = modules_get_agentmodule_name($id_module); $label = '

    '.$agent_label . " - " . $module_label.'

    '; break; @@ -1761,7 +1759,7 @@ function visual_map_process_wizard_add_modules ($id_modules, $image, $label = '

    '.$module_label.'

    '; break; case 'agent': - $agent_label = agents_get_name ($id_agent); + $agent_label = agents_get_alias($id_agent); $label = '

    '.$agent_label.'

    '; break; case 'none': @@ -1953,9 +1951,7 @@ function visual_map_process_wizard_add_agents ($id_agents, $image, switch ($label_type) { case 'agent': - $agent_label = - agents_get_name($id_agent); - $label = $agent_label; + $label = agents_get_alias($id_agent); break; case 'none': $label = ''; diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php index d196b2bff3..26d6389868 100755 --- a/pandora_console/include/functions_visual_map_editor.php +++ b/pandora_console/include/functions_visual_map_editor.php @@ -284,6 +284,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) { $params['javascript_is_function_select'] = true; $params['use_hidden_input_idagent'] = true; $params['print_hidden_input_idagent'] = true; + $params['hidden_input_idagent_name'] = 'id_agent'; if (defined('METACONSOLE')) { $params['javascript_ajax_page'] = '../../ajax.php'; $params['disabled_javascript_on_blur_function'] = true; diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 05ca835239..271bd75f05 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -369,7 +369,7 @@ var TreeController = { $content.append($alertImage); } - $content.append(element.name); + $content.append(element.alias); break; case 'module': // Status image diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 08e3032006..fc253bf324 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -179,7 +179,7 @@ if ($free_search != '') { WHERE id_agente IN ( SELECT id_agente FROM tagente - WHERE nombre LIKE "%' . $free_search . '%"))' . + WHERE nombre LIKE "%' . $free_search . '%") OR alias LIKE "%' . $free_search . '%")' . ')'; break; @@ -214,7 +214,7 @@ if ($free_search != '') { WHERE id_agente IN ( SELECT id_agente FROM tagente - WHERE nombre LIKE \'%' . $free_search . '%\'))' . + WHERE nombre LIKE \'%' . $free_search . '%\' OR alias LIKE \'%' . $free_search . '%\'))' . ')'; break; diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index 1180fc69d9..4d7baf69de 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -258,13 +258,13 @@ switch ($sortField) { switch ($sort) { case 'up': $selectNameUp = $selected; - $order = array('field' => 'nombre' . $order_collation, - 'field2' => 'nombre' . $order_collation, 'order' => 'ASC'); + $order = array('field' => 'alias' . $order_collation, + 'field2' => 'alias' . $order_collation, 'order' => 'ASC'); break; case 'down': $selectNameDown = $selected; - $order = array('field' => 'nombre' . $order_collation, - 'field2' => 'nombre' . $order_collation, 'order' => 'DESC'); + $order = array('field' => 'alias' . $order_collation, + 'field2' => 'alias' . $order_collation, 'order' => 'DESC'); break; } break; @@ -273,12 +273,12 @@ switch ($sortField) { case 'up': $selectOsUp = $selected; $order = array('field' => 'id_os', - 'field2' => 'nombre' . $order_collation, 'order' => 'ASC'); + 'field2' => 'alias' . $order_collation, 'order' => 'ASC'); break; case 'down': $selectOsDown = $selected; $order = array('field' => 'id_os', - 'field2' => 'nombre' . $order_collation, 'order' => 'DESC'); + 'field2' => 'alias' . $order_collation, 'order' => 'DESC'); break; } break; @@ -287,12 +287,12 @@ switch ($sortField) { case 'up': $selectIntervalUp = $selected; $order = array('field' => 'intervalo', - 'field2' => 'nombre' . $order_collation, 'order' => 'ASC'); + 'field2' => 'alias' . $order_collation, 'order' => 'ASC'); break; case 'down': $selectIntervalDown = $selected; $order = array('field' => 'intervalo', - 'field2' => 'nombre' . $order_collation, 'order' => 'DESC'); + 'field2' => 'alias' . $order_collation, 'order' => 'DESC'); break; } break; @@ -301,12 +301,12 @@ switch ($sortField) { case 'up': $selectGroupUp = $selected; $order = array('field' => 'id_grupo', - 'field2' => 'nombre' . $order_collation, 'order' => 'ASC'); + 'field2' => 'alias' . $order_collation, 'order' => 'ASC'); break; case 'down': $selectGroupDown = $selected; $order = array('field' => 'id_grupo', - 'field2' => 'nombre' . $order_collation, 'order' => 'DESC'); + 'field2' => 'alias' . $order_collation, 'order' => 'DESC'); break; } break; @@ -315,12 +315,12 @@ switch ($sortField) { case 'up': $selectLastContactUp = $selected; $order = array('field' => 'ultimo_contacto', - 'field2' => 'nombre' . $order_collation, 'order' => 'DESC'); + 'field2' => 'alias' . $order_collation, 'order' => 'DESC'); break; case 'down': $selectLastContactDown = $selected; $order = array('field' => 'ultimo_contacto', - 'field2' => 'nombre' . $order_collation, 'order' => 'ASC'); + 'field2' => 'alias' . $order_collation, 'order' => 'ASC'); break; } break; @@ -329,12 +329,12 @@ switch ($sortField) { case 'up': $selectLastContactUp = $selected; $order = array('field' => 'comentarios', - 'field2' => 'nombre' . $order_collation, 'order' => 'DESC'); + 'field2' => 'alias' . $order_collation, 'order' => 'DESC'); break; case 'down': $selectLastContactDown = $selected; $order = array('field' => 'comentarios', - 'field2' => 'nombre' . $order_collation, 'order' => 'ASC'); + 'field2' => 'alias' . $order_collation, 'order' => 'ASC'); break; } break; @@ -349,8 +349,8 @@ switch ($sortField) { $selectGroupDown = ''; $selectLastContactUp = ''; $selectLastContactDown = ''; - $order = array('field' => 'nombre' . $order_collation, - 'field2' => 'nombre' . $order_collation, + $order = array('field' => 'alias' . $order_collation, + 'field2' => 'alias' . $order_collation, 'order' => 'ASC'); break; } @@ -377,7 +377,7 @@ if ($search != "") { $search_sql .= ")"; }else{ $search_sql = " AND ( nombre " . $order_collation . " - LIKE '%$search%') "; + LIKE '%$search%' OR alias ".$order_collation." LIKE '%$search%') "; } } @@ -453,6 +453,8 @@ else { array ('id_agente', 'id_grupo', + 'nombre', + 'alias', 'id_os', 'ultimo_contacto', 'intervalo', @@ -569,7 +571,7 @@ foreach ($agents as $agent) { if ($agent['quiet']) { $data[0] .= html_print_image("images/dot_green.disabled.png", true, array("border" => '0', "title" => __('Quiet'), "alt" => "")) . " "; } - $data[0] .= ui_print_agent_name($agent["id_agente"], true, 60, 'font-size:8pt !important;', true); + $data[0] .= ' '.$agent["alias"].''; $data[0] .= ''; $data[0] .= '