Send the eHorus key as a custom field.

This commit is contained in:
Ramon Novoa 2016-12-07 15:12:08 +01:00
parent e8e1eeaed3
commit a5cc574061
1 changed files with 22 additions and 9 deletions

View File

@ -2201,14 +2201,20 @@ sub init_module ($) {
sub get_ehkey {
my $fh;
return '' unless defined($Conf{'ehorus_conf'});
# Open the eHorus configuration file.
if (!open($fh, '<', $Conf{'ehorus_conf'})) {
log_message ('log', "Error opening the eHorus configuration file: $!");
# Do not write to the log, since ehorus_conf points to the default eHorus configuration file by default.
return '';
}
# Look fot the eHorus key.
# Look for the eHorus key.
while (my $line = <$fh>) {
# Skip comments.
next if ($line =~ m/^\s*#/);
if ($line =~ m/\s*eh_key\s+(\S+)/) {
my $eh_key = $1;
close($fh);
@ -2401,11 +2407,14 @@ while (1) {
# Clear the XML
$Xml = "";
# Get the eHorus key.
my $eh_key = get_ehkey();
# Custom fields
my @customfieldskeys = keys(%Customfields);
if ($#customfieldskeys > -1) {
if ($#customfieldskeys > -1 || $eh_key ne '') {
$Xml .= "<custom_fields>\n";
foreach my $customfieldkey (@customfieldskeys) {
if($customfieldkey =~ m/^(custom_field\d+_)name/) {
if(defined($Customfields{$1."value"})) {
@ -2416,6 +2425,15 @@ while (1) {
}
}
}
# Add the eHorus key as a custom field.
if ($eh_key ne '') {
$Xml .= " <field>\n";
$Xml .= " <name>eHorusID</name>\n";
$Xml .= " <value><![CDATA[". $eh_key ."]]></value>\n";
$Xml .= " </field>\n";
}
$Xml .= "</custom_fields>\n";
}
@ -2504,11 +2522,6 @@ while (1) {
}
}
# eHorus key.
if (defined ($Conf{'ehorus_conf'})) {
$xml_header .= "' eh_key='" . get_ehkey();
}
$xml_header .= "'>\n";
$Xml = $xml_header . $Xml . "</agent_data>";