Add monitoring types

This commit is contained in:
felix.suarez 2024-01-09 16:01:00 -06:00
parent 6930631c66
commit 678972bc58

View File

@ -3889,7 +3889,8 @@ sub module_logger ($) {
my $status = grep_logs( my $status = grep_logs(
$module->{'name'}, $module->{'name'},
$module->{'params'}, $module->{'params'},
$module->{'filter'} $module->{'filter'},
$module->{'type'}
); );
return $status; return $status;
@ -3926,20 +3927,25 @@ my $encode_sub = defined(&MIME::Base64::encode_base64) ? \&MIME::Base64::encode_
}; };
sub grep_logs { sub grep_logs {
my ($str_name, $str_file, $str_regex) = @_; my ($module_name, $log_file, $reg_exp, $module_type) = @_;
if(!$str_name){ if(!$module_name){
log_message("module_logger", "Missing module name"); log_message("module_logger", "Missing module name");
return; return;
} }
if(!$str_file){ if(!$log_file){
log_message("module_logger", "Missing file name"); log_message("module_logger", "Missing file name");
return; return;
} }
if(!$str_regex){ if(!$module_type){
$str_regex = '.*'; log_message("module_logger", "Missing module type");
return;
}
if(!$reg_exp){
$reg_exp = '.*';
} }
my $idx_dir = '/tmp/'; my $idx_dir = '/tmp/';
@ -3947,9 +3953,6 @@ sub grep_logs {
my $idx_pos = 0; my $idx_pos = 0;
my $idx_size = 0; my $idx_size = 0;
my $idx_ino = ''; my $idx_ino = '';
my $module_name = $str_name;
my $log_file = $str_file;
my $reg_exp = $str_regex;
# Check that log file exists # Check that log file exists
if (! -e $log_file) { if (! -e $log_file) {
@ -3975,7 +3978,7 @@ sub grep_logs {
return if load_idx(\$idx_pos, \$idx_ino, \$idx_file, \$idx_size) == 1; return if load_idx(\$idx_pos, \$idx_ino, \$idx_file, \$idx_size) == 1;
my @data = parse_log(\$idx_pos, \$idx_ino, \$idx_file, \$log_file, \$module_name, \$reg_exp, \$idx_size); my @data = parse_log(\$idx_pos, \$idx_ino, \$idx_file, \$log_file, \$module_name, \$reg_exp, \$idx_size);
my $output = create_log($module_name, @data); my $output = create_log($module_name, $module_type, @data);
return $output; return $output;
} }
@ -4090,19 +4093,26 @@ sub grep_logs {
} }
sub create_log { sub create_log {
my ($module_name, @data) = @_; my ($module_name, $module_type, @data) = @_;
# No data # No data
if ($#data < 0) { if ($#data < 0 && $module_type ne "generic_proc") {
return; return;
} }
# Log module # Log module
my $output = "<log_module>\n"; my $output = "<log_module>\n";
$output .= "<source><![CDATA[" . $module_name . "]]></source>\n"; $output .= " <source><![CDATA[" . $module_name . "]]></source>\n";
$output .= "<encoding>base64</encoding>\n"; $output .= " <type><![CDATA[" . $module_type . "]]></type>\n";
$output .= "<data><![CDATA[";
$output .= &$encode_sub(join('', @data), ''); my $data_content = process_log_monitoring($module_type, @data);
if($module_type eq "log"){
$output .= " <encoding>base64</encoding>\n";
}
$output .= " <data><![CDATA[";
$output .= $data_content;
$output .= "]]></data>\n"; $output .= "]]></data>\n";
$output .= "</log_module>\n"; $output .= "</log_module>\n";
@ -4111,6 +4121,23 @@ sub grep_logs {
} }
sub process_log_monitoring {
my ($module_type, @data) = @_;
my $output = "";
if ($module_type eq "log"){
$output = &$encode_sub(join('', @data), '');
} elsif ($module_type eq "generic_data") {
$output = scalar @data;
} elsif ($module_type eq "generic_proc"){
$output = scalar @data > 0 ? 1 : 0;
} elsif ($module_type eq "generic_data_string" || $module_type eq "async_string"){
$output = join('', @data);
}
return $output;
}
################################################################################ ################################################################################
# TERM Handler # TERM Handler
################################################################################ ################################################################################