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

View File

@ -2201,14 +2201,20 @@ sub init_module ($) {
sub get_ehkey { sub get_ehkey {
my $fh; my $fh;
return '' unless defined($Conf{'ehorus_conf'});
# Open the eHorus configuration file. # Open the eHorus configuration file.
if (!open($fh, '<', $Conf{'ehorus_conf'})) { 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 ''; return '';
} }
# Look fot the eHorus key. # Look for the eHorus key.
while (my $line = <$fh>) { while (my $line = <$fh>) {
# Skip comments.
next if ($line =~ m/^\s*#/);
if ($line =~ m/\s*eh_key\s+(\S+)/) { if ($line =~ m/\s*eh_key\s+(\S+)/) {
my $eh_key = $1; my $eh_key = $1;
close($fh); close($fh);
@ -2401,11 +2407,14 @@ while (1) {
# Clear the XML # Clear the XML
$Xml = ""; $Xml = "";
# Get the eHorus key.
my $eh_key = get_ehkey();
# Custom fields # Custom fields
my @customfieldskeys = keys(%Customfields); my @customfieldskeys = keys(%Customfields);
if ($#customfieldskeys > -1) { if ($#customfieldskeys > -1 || $eh_key ne '') {
$Xml .= "<custom_fields>\n"; $Xml .= "<custom_fields>\n";
foreach my $customfieldkey (@customfieldskeys) { foreach my $customfieldkey (@customfieldskeys) {
if($customfieldkey =~ m/^(custom_field\d+_)name/) { if($customfieldkey =~ m/^(custom_field\d+_)name/) {
if(defined($Customfields{$1."value"})) { 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"; $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_header .= "'>\n";
$Xml = $xml_header . $Xml . "</agent_data>"; $Xml = $xml_header . $Xml . "</agent_data>";