diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 0bab3b1581..552788c7d2 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2012-09-28 Dario Rodriguez + + * util/pandora_xml_stress.conf, + util/pandora_xml_stress.pl, + util/pandora_xml_stress_module_source.txt: Added new + features to pandora_xml_stress program. + 2012-09-26 Hirofumi Kosaka * util/pandora_db.pl: bug fix: 'audit_purge' was used to purge diff --git a/pandora_server/util/pandora_xml_stress.conf b/pandora_server/util/pandora_xml_stress.conf index e114356c5b..46580a758b 100644 --- a/pandora_server/util/pandora_xml_stress.conf +++ b/pandora_server/util/pandora_xml_stress.conf @@ -145,3 +145,10 @@ module_type generic_data_string module_description Messages from the system in logfile format module_exec type=RANDOM;variation=60;min=40;max=40 module_end + +module_begin +module_name Module source +module_type generic_data +module_description Module data generated from source +module_exec type=SOURCE;src=/usr/share/pandora_server/util/pandora_xml_stress_module_source.txt +module_end diff --git a/pandora_server/util/pandora_xml_stress.pl b/pandora_server/util/pandora_xml_stress.pl index 99528f219c..a843ff3a19 100755 --- a/pandora_server/util/pandora_xml_stress.pl +++ b/pandora_server/util/pandora_xml_stress.pl @@ -81,6 +81,7 @@ sub load_config ($\%\@) { close (FILE); } + ################################################################################ # Generate XML files. ################################################################################ @@ -113,6 +114,8 @@ sub generate_xml_files ($$$$$$) { die ("[error] Invalid time_to: $time_to\n\n") unless ($time_to =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/); my $utimestamp_to = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900); + my %modules_src_pointers = init_src_pointers($modules); + # Generate data files my $utimestamp = $utimestamp_from; while ($utimestamp <= $utimestamp_to) { @@ -164,6 +167,7 @@ sub generate_xml_files ($$$$$$) { my $module_avg = get_generation_parameter($module, 'avg', '127'); my $module_time_wave_length = get_generation_parameter($module, 'time_wave_length', '0'); my $module_time_offset = get_generation_parameter($module, 'time_offset', '0'); + my $module_src = get_generation_parameter($module, 'src', 'source.txt'); # Generate module data $xml_data .= "\t\n"; @@ -208,6 +212,9 @@ sub generate_xml_files ($$$$$$) { $rnd_data = generate_curve_data ($utimestamp, $module_min, $module_max, $module_time_wave_length, $module_time_offset); } + }elsif ($generation_type eq 'SOURCE') { + $rnd_data = generate_data_from_source($module_name, $module_src, \%modules_src_pointers); + } # Save previous data @@ -215,7 +222,7 @@ sub generate_xml_files ($$$$$$) { $xml_data .= "\t\t$rnd_data\n"; $xml_data .= "\t\n"; } - + $xml_data .= "\n"; # Fix the temporal path @@ -233,6 +240,9 @@ sub generate_xml_files ($$$$$$) { $XMLFiles++; } + #Update src pointers for a new xml + update_src_pointers(\%modules_src_pointers); + # First run, let the server create the new agent before sending more data if ($utimestamp == $utimestamp_from) { threads->yield (); @@ -316,6 +326,79 @@ sub generate_scatter_data ($$$$$$) { } } +################################################################################ +# Generates data from a txt source +################################################################################ +sub generate_data_from_source ($$$) { + my ($module_name, $module_src, $pointers) = @_; + + my $data = 0; + + my $pointer; + + if (-e $module_src) { + + #Get data and split to an array + open (FD , "<", $module_src); + my @data_array = ; + close(FD); + + $module_name =~ s/\ /\_/; + + $pointer = $pointers->{$module_name}; + + $pointer = $pointer % ($#data_array+1); + + $data = $data_array[$pointer]; + + } else { + #There was an error, set last to 0 and return data + return $data; + } + + return $data; +} + +################################################################################ +# Initialize SRC pointer for src modules +################################################################################ +sub init_src_pointers ($) { + my ($modules) = shift; + + my %pointers; + + foreach my $mod (@{$modules}) { + # Skip unnamed modules + my $module_name = get_conf_token ($mod, 'module_name', ''); + next if ($module_name eq ''); + + my $type = get_generation_parameter($mod, 'type', 'RANDOM'); + + if ($type eq 'SOURCE') { + + $module_name =~ s/\ /\_/; + + $pointers{$module_name} = 0; + } + } + + return %pointers; +} + +################################################################################ +# Updates SRC pointer for src modules +################################################################################ +sub update_src_pointers ($) { + + my ($pointers) = shift; + + foreach my $p (keys %{$pointers}) { + + #Add 1 to the pointer + $pointers->{$p}++; + } +} + ################################################################################ # Returns the value of a configuration token. ################################################################################ diff --git a/pandora_server/util/pandora_xml_stress_module_source.txt b/pandora_server/util/pandora_xml_stress_module_source.txt new file mode 100644 index 0000000000..606cfe936f --- /dev/null +++ b/pandora_server/util/pandora_xml_stress_module_source.txt @@ -0,0 +1,38 @@ +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +0 +1 +12 +13 +12 +14 +12 +14