Added feature sample_agent

This commit is contained in:
Jose Gonzalez 2019-10-22 11:54:27 +02:00
parent 22af1a3654
commit 7c39f3680e
7 changed files with 143 additions and 2 deletions

View File

@ -348,6 +348,15 @@ self_monitoring 1
# Self monitoring interval (in seconds). # Self monitoring interval (in seconds).
self_monitoring_interval 300 self_monitoring_interval 300
# Pandora Sample Agent. If enabled, every 10 minutes, this embedded agent
# will make sample data. Disabled by default.
sample_agent 0
# Pandora Sample Agent interval (in seconds).
sample_agent_interval 600
# Update parent from the agent xml # Update parent from the agent xml
#update_parent 1 #update_parent 1

View File

@ -340,6 +340,15 @@ restart_delay 60
self_monitoring 1 self_monitoring 1
# Pandora Sample Agent. If enabled, every 10 minutes, this embedded agent
# will make sample data. Disabled by default.
sample_agent 0
# Pandora Sample Agent interval (in seconds).
sample_agent_interval 600
# Update parent from the agent xml # Update parent from the agent xml
#update_parent 1 #update_parent 1

View File

@ -382,6 +382,14 @@ sub pandora_server_tasks ($) {
pandora_self_monitoring ($pa_config, $dbh); pandora_self_monitoring ($pa_config, $dbh);
} }
# Pandora sample agent
if (defined($pa_config->{"sample_agent"})
&& $pa_config->{"sample_agent"} == 1
&& !is_metaconsole($pa_config)
&& $counter % $pa_config->{"sample_agent_interval"} == 0) {
pandora_sample_agent ($pa_config);
}
# Avoid counter overflow # Avoid counter overflow
if ($counter >= ~0){ if ($counter >= ~0){
$counter = 0; $counter = 0;

View File

@ -376,6 +376,15 @@ self_monitoring 1
# Self monitoring interval (in seconds). # Self monitoring interval (in seconds).
self_monitoring_interval 300 self_monitoring_interval 300
# Pandora Sample Agent. If enabled, every 10 minutes, this embedded agent
# will make sample data. Disabled by default.
sample_agent 0
# Pandora Sample Agent interval (in seconds).
sample_agent_interval 600
# Update parent from the agent xml # Update parent from the agent xml
#update_parent 1 #update_parent 1

View File

@ -330,6 +330,15 @@ restart_delay 60
# Self monitoring interval (in seconds). # Self monitoring interval (in seconds).
#self_monitoring_interval 300 #self_monitoring_interval 300
# Pandora Sample Agent. If enabled, every 10 minutes, this embedded agent
# will make sample data. Disabled by default.
sample_agent 0
# Pandora Sample Agent interval (in seconds).
sample_agent_interval 600
# Update parent from the agent xml # Update parent from the agent xml
#update_parent 1 #update_parent 1

View File

@ -79,7 +79,7 @@ sub help_screen {
sub pandora_init { sub pandora_init {
my $pa_config = $_[0]; my $pa_config = $_[0];
my $init_string = $_[1]; my $init_string = $_[1];
print "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2018 " . pandora_get_initial_copyright_notice() . "\n"; print "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-20".substr($pandora_build,0,2)." " . pandora_get_initial_copyright_notice() . "\n";
print "This program is OpenSource, licensed under the terms of GPL License version 2.\n"; print "This program is OpenSource, licensed under the terms of GPL License version 2.\n";
print "You can download latest versions and documentation at official web page.\n\n"; print "You can download latest versions and documentation at official web page.\n\n";
@ -397,6 +397,12 @@ sub pandora_load_config {
# Self monitoring interval # Self monitoring interval
$pa_config->{'self_monitoring_interval'} = 300; # 5.1SP1 $pa_config->{'self_monitoring_interval'} = 300; # 5.1SP1
# Sample Agent
$pa_config->{'sample_agent'} = 0;
# Sample agent interval
$pa_config->{'sample_agent_interval'} = 600;
# Process XML data files as a stack # Process XML data files as a stack
$pa_config->{"dataserver_lifo"} = 0; # 5.0 $pa_config->{"dataserver_lifo"} = 0; # 5.0
@ -946,6 +952,12 @@ sub pandora_load_config {
elsif ($parametro =~ m/^self_monitoring_interval\s+([0-9]*)/i) { elsif ($parametro =~ m/^self_monitoring_interval\s+([0-9]*)/i) {
$pa_config->{'self_monitoring_interval'} = clean_blank($1); $pa_config->{'self_monitoring_interval'} = clean_blank($1);
} }
elsif ($parametro =~ m/^sample_agent\s+([0-1])/i) {
$pa_config->{'sample_agent'} = clean_blank($1);
}
elsif ($parametro =~ m/^sample_agent_interval\s+([0-9]*)/i) {
$pa_config->{'sample_agent_interval'} = clean_blank($1);
}
elsif ($parametro =~ m/^update_parent\s+([0-1])/i) { elsif ($parametro =~ m/^update_parent\s+([0-1])/i) {
$pa_config->{'update_parent'} = clean_blank($1); $pa_config->{'update_parent'} = clean_blank($1);
} }

View File

@ -100,6 +100,8 @@ Exported Functions:
=item * C<pandora_self_monitoring> =item * C<pandora_self_monitoring>
=item * C<pandora_sample_agent>
=back =back
=head1 METHODS =head1 METHODS
@ -122,6 +124,7 @@ use threads::shared;
use JSON qw(decode_json encode_json); use JSON qw(decode_json encode_json);
use MIME::Base64; use MIME::Base64;
use Text::ParseWords; use Text::ParseWords;
use Math::Trig; # Math functions
# Debugging # Debugging
#use Data::Dumper; #use Data::Dumper;
@ -247,6 +250,7 @@ our @EXPORT = qw(
pandora_group_statistics pandora_group_statistics
pandora_server_statistics pandora_server_statistics
pandora_self_monitoring pandora_self_monitoring
pandora_sample_agent
pandora_process_policy_queue pandora_process_policy_queue
subst_alert_macros subst_alert_macros
subst_column_macros subst_column_macros
@ -5114,7 +5118,7 @@ sub pandora_self_monitoring ($$) {
my $timezone_offset = 0; # PENDING (TODO) ! my $timezone_offset = 0; # PENDING (TODO) !
my $utimestamp = time (); my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime()); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime());
logger($pa_config, "Self monitoring activated.", 1);
my $xml_output = ""; my $xml_output = "";
$xml_output = "<agent_data os_name='$OS' os_version='$OS_VERSION' version='" . $pa_config->{'version'} . "' description='" . $pa_config->{'rb_product_name'} . " Server version " . $pa_config->{'version'} . "' agent_name='".$pa_config->{'servername'} . "' agent_alias='".$pa_config->{'servername'} . "' interval='".$pa_config->{"self_monitoring_interval"}."' timestamp='".$timestamp."' >"; $xml_output = "<agent_data os_name='$OS' os_version='$OS_VERSION' version='" . $pa_config->{'version'} . "' description='" . $pa_config->{'rb_product_name'} . " Server version " . $pa_config->{'version'} . "' agent_name='".$pa_config->{'servername'} . "' agent_alias='".$pa_config->{'servername'} . "' interval='".$pa_config->{"self_monitoring_interval"}."' timestamp='".$timestamp."' >";
@ -5235,6 +5239,87 @@ sub pandora_self_monitoring ($$) {
print XMLFILE $xml_output; print XMLFILE $xml_output;
close (XMLFILE); close (XMLFILE);
} }
##########################################################################
=head2 C<< xml_module_template (I<$module_name>, I<$module_type>, I<$module_data>) >>
Module template for sample agent
=cut
##########################################################################
sub xml_module_template ($$$) {
my ($module_name, $module_type, $module_data) = @_;
my $output = "<module>\n";
$module_name = "<![CDATA[".$module_name."]]>" if $module_name =~ /[\s+.]+/;
$module_data = "<![CDATA[".$module_data."]]>" if $module_data =~ /[\s+.]+/;
$output .= "\t<name>".$module_name."</name>\n";
$output .= "\t<type>".$module_type."</type>\n";
$output .= "\t<data>".$module_data."</data>\n";
$output .= "</module>\n";
return $output;
}
##########################################################################
=head2 C<< pandora_sample_agent (I<$pa_config>) >>
Pandora agent for make sample data
=cut
##########################################################################
sub pandora_sample_agent ($) {
my ($pa_config) = @_;
logger($pa_config, "Sample agent activated.", 1);
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime());
# First line
my $xml_output = "<agent_data os_name='$OS' os_version='$OS_VERSION' version='" . $pa_config->{'version'} . "' description='" . $pa_config->{'rb_product_name'} . " Server version " . $pa_config->{'version'} . "' agent_name='".$pa_config->{'servername'} . "' agent_alias='".$pa_config->{'servername'} . "' interval='".$pa_config->{"self_monitoring_interval"}."' timestamp='".$timestamp."' >";
# Boolean_True -> generic_proc siempre a 1
$xml_output .= xml_module_template ("Siempre a uno", "generic_proc","1");
# Boolean_MostlyTrue -> generic_proc un 80% de veces a 1
my $sample_boolean_mostly_true = 1;
$sample_boolean_mostly_true = 0 if rand(9) > 7;
$xml_output .= xml_module_template ("Boolean mostly true", "generic_proc",$sample_boolean_mostly_true);
# Boolean_MostlyFalse -> generic_proc un 80% de veces a 1
my $sample_boolean_mostly_false = 0;
$sample_boolean_mostly_false = 1 if rand(9) > 7;
$xml_output .= xml_module_template ("Siempre a uno", "generic_proc", $sample_boolean_mostly_false);
# Boolean_False -> generic_proc siempre a 0
$xml_output .= xml_module_template ("Siempre_false", "generic_proc","0");
# Data_Series_Scatter -> Valores random de 0 a 100
$xml_output .= xml_module_template ("Random_integer_values", "generic_data",int(rand(100)));
# Data_Series_Curve -> Valores en curvas senoidales o similares de 0 a 100
# (utilizar funcion matemática que use timestamp actual, para no tener que
# guardar valores anteriores)
my $b = 1;
my $sample_serie_curve = 1 + cos(deg2rad($b));
$b = $b + rand(20)/10;
$b = 0 if ($b > 180);
$sample_serie_curve = $sample_serie_curve * $b * 10;
$sample_serie_curve =~ s/\,/\./g;
$xml_output .= xml_module_template ("Random text", "generic_string", $sample_serie_curve);
# Text -> generic_string > Con una cadena de texto aleatorio de
# 10 caracteres, idealmente con espacios y caracteres ascii
# basicos (letras).
# String with 10 random characters
my $sample_random_text = "";
my @characters = ('a'..'z','A'..'Z');
for (1...10){
$sample_random_text .= $characters[int(rand(@characters))];
}
$xml_output .= xml_module_template ("Random text", "generic_string", $sample_random_text);
# End of xml
$xml_output .= "</agent_data>";
# File definition
my $filename = $pa_config->{"incomingdir"}."/".$pa_config->{'servername'}.".sample.".$utimestamp.".data";
# Opening, Writing and closing of XML
open (my $xmlfile, ">", $filename) or die "[FATAL] Could not open sample XML file for deploying monitorization at '$filename'";
print $xmlfile $xml_output;
close ($xmlfile);
}
########################################################################## ##########################################################################
=head2 C<< set_master (I<$pa_config>, I<$dbh>) >> =head2 C<< set_master (I<$pa_config>, I<$dbh>) >>