Fix data timestamps.
Apply timezone offsets to data timestamps. Ignore data timestamps if use_xml_timestamp is set to 0.
This commit is contained in:
parent
eba0ce9e80
commit
5373b17bac
|
@ -377,19 +377,7 @@ sub process_xml_data ($$$$$) {
|
||||||
|
|
||||||
# Modify the timestamp with the timezone_offset
|
# Modify the timestamp with the timezone_offset
|
||||||
logger($pa_config, "Applied a timezone offset of $timestamp to agent " . $data->{'agent_name'}, 10);
|
logger($pa_config, "Applied a timezone offset of $timestamp to agent " . $data->{'agent_name'}, 10);
|
||||||
|
$timestamp = apply_timezone_offset($timestamp, $timezone_offset);
|
||||||
# Calculate the start date to add the offset
|
|
||||||
my $utimestamp = 0;
|
|
||||||
eval {
|
|
||||||
if ($timestamp =~ /(\d+)[\/|\-](\d+)[\/|\-](\d+) +(\d+):(\d+):(\d+)/) {
|
|
||||||
$utimestamp = strftime("%s", $6, $5, $4, $3, $2 -1 , $1 - 1900);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
# Apply the offset if there were no errors
|
|
||||||
if (! $@ && $utimestamp != 0) {
|
|
||||||
$timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp + ($timezone_offset * 3600)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check some variables
|
# Check some variables
|
||||||
|
@ -630,6 +618,11 @@ sub process_xml_data ($$$$$) {
|
||||||
# Single data
|
# Single data
|
||||||
if (! defined ($module_data->{'datalist'})) {
|
if (! defined ($module_data->{'datalist'})) {
|
||||||
my $data_timestamp = get_tag_value ($module_data, 'timestamp', $timestamp);
|
my $data_timestamp = get_tag_value ($module_data, 'timestamp', $timestamp);
|
||||||
|
if ($pa_config->{'use_xml_timestamp'} eq '0' && defined($timestamp)) {
|
||||||
|
$data_timestamp = $timestamp;
|
||||||
|
}
|
||||||
|
$data_timestamp = apply_timezone_offset($data_timestamp, $timezone_offset);
|
||||||
|
|
||||||
process_module_data ($pa_config, $module_data, $server_id, $agent, $module_name, $module_type, $interval, $data_timestamp, $dbh, $new_agent);
|
process_module_data ($pa_config, $module_data, $server_id, $agent, $module_name, $module_type, $interval, $data_timestamp, $dbh, $new_agent);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
@ -647,10 +640,10 @@ sub process_xml_data ($$$$$) {
|
||||||
|
|
||||||
$module_data->{'data'} = $data->{'value'};
|
$module_data->{'data'} = $data->{'value'};
|
||||||
my $data_timestamp = get_tag_value ($data, 'timestamp', $timestamp);
|
my $data_timestamp = get_tag_value ($data, 'timestamp', $timestamp);
|
||||||
|
|
||||||
if ($pa_config->{'use_xml_timestamp'} eq '0' && defined($timestamp)) {
|
if ($pa_config->{'use_xml_timestamp'} eq '0' && defined($timestamp)) {
|
||||||
$data_timestamp = $timestamp;
|
$data_timestamp = $timestamp;
|
||||||
}
|
}
|
||||||
|
$data_timestamp = apply_timezone_offset($data_timestamp, $timezone_offset);
|
||||||
|
|
||||||
process_module_data ($pa_config, $module_data, $server_id, $agent, $module_name,
|
process_module_data ($pa_config, $module_data, $server_id, $agent, $module_name,
|
||||||
$module_type, $interval, $data_timestamp, $dbh, $new_agent);
|
$module_type, $interval, $data_timestamp, $dbh, $new_agent);
|
||||||
|
|
|
@ -182,6 +182,7 @@ our @EXPORT = qw(
|
||||||
check_cron_element
|
check_cron_element
|
||||||
cron_check
|
cron_check
|
||||||
p_pretty_json
|
p_pretty_json
|
||||||
|
apply_timezone_offset
|
||||||
);
|
);
|
||||||
|
|
||||||
# ID of the different servers
|
# ID of the different servers
|
||||||
|
@ -2990,6 +2991,33 @@ sub p_pretty_json {
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Apply a timezone offset to the given timestamp.
|
||||||
|
################################################################################
|
||||||
|
sub apply_timezone_offset {
|
||||||
|
my ($timestamp, $timezone_offset) = @_;
|
||||||
|
|
||||||
|
# Nothing to be done.
|
||||||
|
return $timestamp if (!defined($timezone_offset) || $timezone_offset == 0);
|
||||||
|
|
||||||
|
# Convert the timestamp to seconds.
|
||||||
|
my $utimestamp = 0;
|
||||||
|
eval {
|
||||||
|
if ($timestamp =~ /(\d+)[\/|\-](\d+)[\/|\-](\d+) +(\d+):(\d+):(\d+)/) {
|
||||||
|
$utimestamp = strftime("%s", $6, $5, $4, $3, $2 -1 , $1 - 1900);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
# Something went wrong.
|
||||||
|
return $timestamp if ($@);
|
||||||
|
|
||||||
|
# Apply the offset and convert back to timestamp.
|
||||||
|
$timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp + ($timezone_offset * 3600)));
|
||||||
|
|
||||||
|
return $timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
__END__
|
__END__
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue