2009-06-08 Ramon Novoa <rnovoa@artica.es>

* util/pandora_xml_stress.pl: Let the user specify the maximum number
          of threads.

        * util/pandora_xml_stress.README: Updated the documentation.





git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1739 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2009-06-08 18:36:12 +00:00
parent 9d3c86bdde
commit 16925ae59a
3 changed files with 75 additions and 44 deletions

View File

@ -1,3 +1,10 @@
2009-06-08 Ramon Novoa <rnovoa@artica.es>
* util/pandora_xml_stress.pl: Let the user specify the maximum number
of threads.
* util/pandora_xml_stress.README: Updated the documentation.
2009-06-08 Sancho Leren <slerena@artica.es> 2009-06-08 Sancho Leren <slerena@artica.es>
* Header updates. * Header updates.

View File

@ -18,6 +18,9 @@ Run the script like this:
Sample configuration file Sample configuration file
========================= =========================
# Maximum number of threads, by default 10.
max_threads 10
# File containing a list of agent names (one per line). # File containing a list of agent names (one per line).
agent_file agent_names.txt agent_file agent_names.txt
@ -52,6 +55,12 @@ time_to 2009-06-05 00:00:00
# race conditions when auto-creating the agent, by default 2. # race conditions when auto-creating the agent, by default 2.
startup_delay 2 startup_delay 2
# Address of the Tentacle server where XML files will be sent (optional).
# server_ip 192.168.50.1
# Port of the Tentacle server, by default 41121.
# server_port 41121
# Module definitions. Similar to pandora_agent.conf. # Module definitions. Similar to pandora_agent.conf.
module_begin module_begin

View File

@ -24,7 +24,7 @@ use threads::shared;
use Time::Local; use Time::Local;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use POSIX qw (strftime); use POSIX qw (strftime ceil);
# Global variables used for statistics # Global variables used for statistics
my $Agents :shared = 0; my $Agents :shared = 0;
@ -78,8 +78,8 @@ sub load_config ($\%\@) {
################################################################################ ################################################################################
# Generate XML files. # Generate XML files.
################################################################################ ################################################################################
sub generate_xml_files ($$$) { sub generate_xml_files ($$$$$) {
my ($agent_name, $conf, $modules) = @_; my ($agents, $start, $step, $conf, $modules) = @_;
# Read agent configuration # Read agent configuration
my $interval = get_conf_token ($conf, 'interval', '300'); my $interval = get_conf_token ($conf, 'interval', '300');
@ -103,51 +103,57 @@ sub generate_xml_files ($$$) {
# Generate data files # Generate data files
my $utimestamp = $utimestamp_from; my $utimestamp = $utimestamp_from;
while ($utimestamp < $utimestamp_to) { while ($utimestamp <= $utimestamp_to) {
for (my $i = $start; $i < $start + $step; $i++) {
# XML header # Get the name of the agent
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); last unless defined ($agents->[$i]);
my $xml_data = "<?xml version='$xml_version' encoding='$encoding'?>\n"; my $agent_name = $agents->[$i];
$xml_data .= "<agent_data os_name='$os_name' os_version='$os_version' interval='$interval' version='$os_version' timestamp='$timestamp' agent_name='$agent_name'>\n";
foreach my $module (@{$modules}) {
# Skip unnamed modules # XML header
my $module_name = get_conf_token ($module, 'module_name', ''); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
next if ($module_name eq ''); my $xml_data = "<?xml version='$xml_version' encoding='$encoding'?>\n";
$xml_data .= "<agent_data os_name='$os_name' os_version='$os_version' interval='$interval' version='$os_version' timestamp='$timestamp' agent_name='$agent_name'>\n";
foreach my $module (@{$modules}) {
# Read module configuration # Skip unnamed modules
my $module_type = get_conf_token ($module, 'module_type', 'generic_data'); my $module_name = get_conf_token ($module, 'module_name', '');
my $module_description = get_conf_token ($module, 'module_description', ''); next if ($module_name eq '');
my $module_min = get_conf_token ($module, 'module_min', '0');
my $module_max = get_conf_token ($module, 'module_max', '255');
my $module_variation = get_conf_token ($module, 'module_variation', '100');
my $module_data = get_conf_token ($module, 'module_data', '');
# Generate module data # Read module configuration
$xml_data .= "\t<module>\n"; my $module_type = get_conf_token ($module, 'module_type', 'generic_data');
$xml_data .= "\t\t<name>$module_name</name>\n"; my $module_description = get_conf_token ($module, 'module_description', '');
$xml_data .= "\t\t<description>$module_description</description>\n"; my $module_min = get_conf_token ($module, 'module_min', '0');
$xml_data .= "\t\t<type>$module_type</type>\n"; my $module_max = get_conf_token ($module, 'module_max', '255');
my $rnd_data = generate_random_data ($module_type, $module_data, $module_min, $module_max, $module_variation); my $module_variation = get_conf_token ($module, 'module_variation', '100');
$module->{'module_data'} = $rnd_data; my $module_data = get_conf_token ($module, 'module_data', '');
$xml_data .= "\t\t<data>$rnd_data</data>\n";
$xml_data .= "\t</module>\n";
}
$xml_data .= "</agent_data>\n"; # Generate module data
$xml_data .= "\t<module>\n";
$xml_data .= "\t\t<name>$module_name</name>\n";
$xml_data .= "\t\t<description>$module_description</description>\n";
$xml_data .= "\t\t<type>$module_type</type>\n";
my $rnd_data = generate_random_data ($module_type, $module_data, $module_min, $module_max, $module_variation);
$module->{'module_data'} = $rnd_data;
$xml_data .= "\t\t<data>$rnd_data</data>\n";
$xml_data .= "\t</module>\n";
}
# Fix the temporal path $xml_data .= "</agent_data>\n";
my $last_char = chop ($temporal);
$temporal .= $last_char if ($last_char ne '/');
# Save the XML data file # Fix the temporal path
my $xml_file = $temporal . '/' . $agent_name . $utimestamp . '.data'; my $last_char = chop ($temporal);
open (FILE, ">", $xml_file) || die ("[error] Could not write to '$xml_file': $!.\n\n"); $temporal .= $last_char if ($last_char ne '/');
print FILE $xml_data;
close (FILE);
copy_xml_file ($conf, $xml_file); # Save the XML data file
$XMLFiles++; my $xml_file = $temporal . '/' . $agent_name . '_' . $utimestamp . '.data';
open (FILE, ">", $xml_file) || die ("[error] Could not write to '$xml_file': $!.\n\n");
print FILE $xml_data;
close (FILE);
copy_xml_file ($conf, $xml_file);
$XMLFiles++;
}
# First run, let the server create the new agent before sending more data # First run, let the server create the new agent before sending more data
if ($utimestamp == $utimestamp_from) { if ($utimestamp == $utimestamp_from) {
@ -252,16 +258,25 @@ load_config ($ARGV[0], %conf, @modules);
die ("[error] No agent file specified in configuration file.\n\n") unless defined ($conf{'agent_file'}); die ("[error] No agent file specified in configuration file.\n\n") unless defined ($conf{'agent_file'});
open (FILE, "<", $conf{'agent_file'}) || die ("[error] Could not open agent configuration file '" . $conf{'agent_file'} . "': $!.\n\n"); open (FILE, "<", $conf{'agent_file'}) || die ("[error] Could not open agent configuration file '" . $conf{'agent_file'} . "': $!.\n\n");
my $t0 = gettimeofday (); # Read agent names
my @agents;
# Launch a thread for each agent
while (my $agent_name = <FILE>) { while (my $agent_name = <FILE>) {
chomp ($agent_name); chomp ($agent_name);
threads->create (\&generate_xml_files, $agent_name, \%conf, \@modules); push (@agents, $agent_name);
$Agents++; $Agents++;
} }
close (FILE); close (FILE);
# Get the maximum number of threads and the number of agents per thread
my $max_threads = get_conf_token (\%conf, 'max_threads', '10');
$max_threads = 10 unless ($max_threads > 0);
my $step = ceil ($Agents / $max_threads);
my $t0 = gettimeofday ();
for (my $i = 0; $i < $Agents; $i += $step) {
threads->create (\&generate_xml_files, \@agents, $i, $step, \%conf, \@modules);
}
# Log some information for the user # Log some information for the user
my $time_now = strftime ("%Y-%m-%d %H:%M:%S", localtime ()); my $time_now = strftime ("%Y-%m-%d %H:%M:%S", localtime ());
my $time_from = get_conf_token (\%conf, 'time_from', $time_now); my $time_from = get_conf_token (\%conf, 'time_from', $time_now);