From f1dcdc037ec912029e56849b670b5c413d3b0a4b Mon Sep 17 00:00:00 2001 From: ramonn Date: Tue, 28 Feb 2012 15:48:26 +0000 Subject: [PATCH] 2012-02-28 Ramon Novoa * Linux/pandora_agent.conf, pandora_agent: Added support for xml_buffer. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5664 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/unix/ChangeLog | 5 ++ pandora_agents/unix/Linux/pandora_agent.conf | 6 +++ pandora_agents/unix/pandora_agent | 55 +++++++++++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index f91399a090..c56c2123fe 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,8 @@ +2012-02-28 Ramon Novoa + + * Linux/pandora_agent.conf, + pandora_agent: Added support for xml_buffer. + 2012-02-23 Ramon Novoa * pandora_agent: Set the intensive interval before reading modules. diff --git a/pandora_agents/unix/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index d0d5d19f66..625a8ac965 100755 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -127,6 +127,12 @@ transfer_mode tentacle # User the agent will run as #pandora_user root +# Enable or disable XML buffer. +#xml_buffer 0 + +# Minimum available bytes in the temporal directory to enable the XML buffer +#temporal_min_size 1024 + # Secondary server configuration # ============================== diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index f68e52bf8f..8aa007b288 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -98,6 +98,16 @@ use constant PART_CMDS => { aix => 'df -kP | awk \'NR > 1 {print $2, $4, $6}\'', freebsd => 'df -k | awk \'NR > 1 {print $2, $4, $6}\'' }; + +# Commands to call df with POSIX output format +use constant DF_CMDS => { + # total, available, mount point + linux => 'df -P', + solaris => 'df -k', + hpux => 'df -P', + aix => 'df -kP', + freebsd => 'df -k' +}; # OS and OS version my $OS = $^O; @@ -146,6 +156,7 @@ my %Conf = ( 'secondary_server_ssl' => 'no', 'secondary_server_opts' => '', 'autotime' => 0, + 'temporal_min_size' => 1, 'timezone_offset' => 0, 'pandora_exec' => 'pandora_agent_exec', 'agent_threads' => 1, @@ -157,6 +168,7 @@ my %Conf = ( 'proxy_timeout' => 1, 'intensive_interval' => 0, 'timestamp' => 0, + 'xml_buffer' => 0, ); # Modules @@ -673,6 +685,22 @@ sub send_file { return $rc; } +################################################################################ +# Send buffered XML files. +################################################################################ +sub send_buffered_xml_files () { + + # Read XML files from the temporal directory + opendir(TEMPORAL, $Conf{'temporal'}) or return; + while (my $xml_file = readdir(TEMPORAL)) { + + # Skip non data files + next unless ($xml_file =~ m/\.data$/); + + send_file ($xml_file, 1); + } +} + ################################################################################ # Swap primary and secondary servers. ################################################################################ @@ -1627,6 +1655,23 @@ sub kill_signal_handler (){ exit (0); } +################################################################################ +# Get the free disk space in the temporal directory (in bytes). +################################################################################ +sub temporal_freedisk () { + + # Call df + return 0 unless defined (DF_CMDS->{$OS}); + my $cmd = DF_CMDS->{$OS} . ' ' . $Conf{'temporal'} . ' | awk \'NR > 1 {print $4}\''; + my $temporal_freedisk = `$cmd`; + + # Check for errors + return 0 unless ($? eq 0); + + # Convert to bytes + return 1024 * int ($temporal_freedisk); +} + ################################################################################ # Main. ################################################################################ @@ -1893,9 +1938,15 @@ while (1) { } # Send the XML data file - send_file ($temp_file, 1); - unlink ($temp_file); + my $rc = send_file ($temp_file, 1); + if ($rc == 0 || $Conf{'xml_buffer'} == 0 || temporal_freedisk () < $Conf{'temporal_min_size'}) { + unlink ($temp_file); + } + # Send buffered XML data files + if ($Conf{'xml_buffer'} == 1) { + send_buffered_xml_files (); + } } # Enable signal capture to break the Sleep interval on UDP signal