From 51a3692415326d8c5987980d13a0ae3eaf8a3762 Mon Sep 17 00:00:00 2001 From: ramonn Date: Mon, 20 May 2013 11:20:39 +0000 Subject: [PATCH] 2013-05-20 Ramon Novoa * util/pandora_xml_stress.pl, util/pandora_xml_stress.conf: Added support for data attenuation on certain days. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8163 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 ++++++ pandora_server/util/pandora_xml_stress.conf | 8 ++++++- pandora_server/util/pandora_xml_stress.pl | 24 ++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 4d54bfd9eb..0c7ce20055 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2013-05-20 Ramon Novoa + + * util/pandora_xml_stress.pl, + util/pandora_xml_stress.conf: Added support for data attenuation on + certain days. + 2013-05-16 Ramon Novoa * bin/pandora_server: Added information about the loading of the diff --git a/pandora_server/util/pandora_xml_stress.conf b/pandora_server/util/pandora_xml_stress.conf index af3da5a4e5..87a8b81714 100644 --- a/pandora_server/util/pandora_xml_stress.conf +++ b/pandora_server/util/pandora_xml_stress.conf @@ -1,4 +1,4 @@ -o Sample configuration file for pandora_xmlstress +# Sample configuration file for pandora_xmlstress # (c) 2012, http://pandorafms.org # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -87,6 +87,8 @@ module_exec type=RANDOM;variation=20;min=50;max=500 module_unit conns module_min_critical 450 module_min_warning 400 +module_attenuation 0.33 +module_attenuation_wdays 0 6 module_end module_begin @@ -104,6 +106,8 @@ module_description Network throughtput for incoming data module_exec type=RANDOM;variation=50;min=0;max=1000000 module_unit kbit/sec module_min_critical 900000 +module_attenuation 0.5 +module_attenuation_wdays 0 6 module_end module_begin @@ -113,6 +117,8 @@ module_description Network throughtput for Outgoing data module_exec type=RANDOM;variation=50;min=0;max=1000000 module_unit kbit/sec module_min_critical 900000 +module_attenuation 0.1 +module_attenuation_wdays 0 6 module_end module_begin diff --git a/pandora_server/util/pandora_xml_stress.pl b/pandora_server/util/pandora_xml_stress.pl index 6cd3bfd3a6..91e6374a6b 100755 --- a/pandora_server/util/pandora_xml_stress.pl +++ b/pandora_server/util/pandora_xml_stress.pl @@ -137,7 +137,9 @@ sub generate_xml_files ($$$$$$) { my $ag_altitude = $altitude_base + (rand ($position_radius) - $position_radius/2)/100; # XML header - my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); + my @localtime = localtime ($utimestamp); + my $wday = $localtime[6]; + my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", @localtime); my $xml_data = "\n"; my $sign = int rand(2); $ag_timezone_offset += ($sign*(-1)+(1-$sign)) * int rand($ag_timezone_offset_range); @@ -152,6 +154,8 @@ sub generate_xml_files ($$$$$$) { my $module_type = get_conf_token ($module, 'module_type', 'generic_data'); my $module_description = get_conf_token ($module, 'module_description', ''); my $module_unit = get_conf_token ($module, 'module_unit', ''); + my $attenuation = get_conf_token ($module, 'module_attenuation', '0'); + my @attenuation_wdays = get_conf_token_array ($module, 'module_attenuation_wdays', ' '); #my $module_min = get_conf_token ($module, 'module_min', '0'); #my $module_max = get_conf_token ($module, 'module_max', '255'); @@ -237,6 +241,11 @@ sub generate_xml_files ($$$$$$) { } + # Data attenuation + if ($attenuation != 0 && ($#attenuation_wdays < 0 || $wday ~~ @attenuation_wdays)) { + $rnd_data *= $attenuation; + } + # Save previous data $module->{'module_data'} = $rnd_data; $xml_data .= "\t\t\n"; @@ -448,6 +457,19 @@ sub get_conf_token ($$$) { return $hash_ref->{$token}; } +################################################################################ +# Returns the value of a configuration token. +################################################################################ +sub get_conf_token_array ($$$) { + my ($hash_ref, $token, $separator) = @_; + + my @tokens = (); + return @tokens unless ref ($hash_ref) and defined ($hash_ref->{$token}); + + @tokens = split($separator, $hash_ref->{$token}); + return @tokens; +} + ################################################################################ # Returns the parameter of a generator configuration of module. ################################################################################