Inbound Mail hash errors: "^M" in cleaner.log

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
gdksc
Posts: 20
Joined: Fri Feb 01, 2019 9:58 am

Re: Inbound Mail hash errors: "^M" in cleaner.log

Post by gdksc »

As an experiment, I appended another line to convert any "3D" in the email body to "=":

Code: Select all

            // 2. Verify that the email object hash exists and the host/service exists
            $email['body'] = preg_replace("/[\\r\\n]+/", "\n",$email['body']);
            $email['body'] = preg_replace("/3D/", "=",$email['body']);
And my hash was decoded successfully:

Code: Select all

-----
To reply, keep the following data in your response email.
##M2Q1NGFhYmU1MDcyNzdiNlNxY051VjhVUFhVL0xYZWhyOGlSaGJLOVE5S05JUGFWQ3dPZi91e=
nhiYk11MkZWSzBOYTZLWVpnaHRjZy9iOG94dndVQ3JBcmdXcXBjM1dhVUdpUG9nPT0==##
hash: M2Q1NGFhYmU1MDcyNzdiNlNxY051VjhVUFhVL0xYZWhyOGlSaGJLOVE5S05JUGFWQ3dPZi91enhiYk11MkZWSzBOYTZLWVpnaHRjZy9iOG94dndVQ3JBcmdXcXBjM1dhVUdpUG9nPT0
$obj = json_decode(decrypt_data(M2Q1NGFhYmU1MDcyNzdiNlNxY051VjhVUFhVL0xYZWhyOGlSaGJLOVE5S05JUGFWQ3dPZi91enhiYk11MkZWSzBOYTZLWVpnaHRjZy9iOG94dndVQ3JBcmdXcXBjM1dhVUdpUG9nPT0))
json_last_error: 0
object(stdClass)#8 (2) {
  ["host"]=>
  string(14) "fbv-nagios-d01"
  ["service"]=>
  string(18) "Disk Usage on /var"
}
msh_end: 231
msg_lines_count: 11
Array
(
    [0] => ack
Seems to confirm that the "=" being converted to "3D" is my issue here.

However, I'm still unsure where the "=" is being converted to "3D", initially...
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Inbound Mail hash errors: "^M" in cleaner.log

Post by lmiltchev »

Try the following:

1. Make a backup of your original xicore.inc.php file:

Code: Select all

cp -p /usr/local/nagiosxi/html/includes/components/xicor/xicore.inc.php /usr/local/nagiosxi/html/includes/components/xicor/xicore.inc.php.backup
2. Download the zip file below:
xicore.inc.php.zip
3. Unzip it and place the xicore.inc.php file in the /usr/local/nagiosxi/html/includes/components/xicore directory, replacing the "original" one.

4. Test the inbound email commands again.

Let us know if this helped.

Note: We tested the patch in house with Microsoft Outlook, and it worked fine for us. If you run into any more problems, we will escalate the issue to our developers. Thank you!
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
gdksc
Posts: 20
Joined: Fri Feb 01, 2019 9:58 am

Re: Inbound Mail hash errors: "^M" in cleaner.log

Post by gdksc »

Hi, @lmiltchev.

I installed the new xicore.inc.php file, but no luck.

Here is a diff of the original xicore.inc.php vs the new xicore.inc.php:

Code: Select all

# diff xicore.inc.php.orig xicore.inc.php
552a553,555
>
>             // Replace all Windows line endings with Linux ones
>             $email['body'] = preg_replace("/[\\r\\n]+/", "\n", $email['body']);
559c562
<                 $hash = trim(str_replace(array('> ', '>', '=', "\n", "\t", "\r"), '', substr($email['body'], $start + 2, $end - $start - 2)));
---
>                 $hash = trim(str_replace(array('> ', '>', "\n", "\t", "\r"), '', substr($email['body'], $start + 2, $end - $start - 2)));
592c595
<                 echo "msh_end: " . $msg_end . "\n";
---
>                 echo "msg_end: " . $msg_end . "\n";
Here is the hash at the bottom of my reply email:

Code: Select all

-----

To reply, keep the following data in your response email.

##NjY1NjU1YzllYTYyZWUwYnpFN1g4T0hEemtmNENVczltbzJySWsvRENLbkdWVm1IRXJwcW9yNWpMU2x3RkZWY3V0S2UrbG1JczZGKzBBSVBXNEE1K0hiK2RMcnFFdWxyS29pTFRRPT0=##
Here is the message in cleaner.log:

Code: Select all

----------------------------------
Running callbacks:
Error - Could not find a host object in the hash provided
Processed 1 incoming emails
----------------------------------
Let me know if any additional ideas for debugging..

Thanks.
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: Inbound Mail hash errors: "^M" in cleaner.log

Post by jomann »

Alright, the xicore.inc.php that lmiltchev gave you is the one with the fixes that I've applied to ensure our Outlook emails work with the dev/test boxes we have. Can you put back in your logging that will output the email body/text/hash and test the reply once more? I am unable to recreate any hashing issues now that we removed the newlines.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
gdksc
Posts: 20
Joined: Fri Feb 01, 2019 9:58 am

Re: Inbound Mail hash errors: "^M" in cleaner.log

Post by gdksc »

Hi, @jomann.

Good news to report..

Seems my issue is resolved by using "quoted_printable_decode" [1]:

Code: Select all

// Convert quoted-printable
$email['body'] = quoted_printable_decode($email['body']);
That works with the original xicore.inc.php, as well as the new xicore.inc.php.

Code: Select all

# diff xicore.inc.php.orig xicore.inc.php
552a553,558
>
>             // Convert quoted-printable
>             $email['body'] = quoted_printable_decode($email['body']);
>
>             // Replace all Windows line endings with Linux ones
>             $email['body'] = preg_replace("/[\\r\\n]+/", "\n", $email['body']);
559c565
<                 $hash = trim(str_replace(array('> ', '>', '=', "\n", "\t", "\r"), '', substr($email['body'], $start + 2, $end - $start - 2)));
---
>                 $hash = trim(str_replace(array('> ', '>', "\n", "\t", "\r"), '', substr($email['body'], $start + 2, $end - $start - 2)));
592c598
<                 echo "msh_end: " . $msg_end . "\n";
---
>                 echo "msg_end: " . $msg_end . "\n";
Result from the cleaner.log:

Code: Select all

----------------------------------
Running callbacks:
msh_end: 241
msg_lines_count: 14
Array
(
    [0] => ack
I'll defer for best long-term approach, but this seems to work.

Thanks again for your help.

[1] https://www.php.net/manual/en/function. ... decode.php
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: Inbound Mail hash errors: "^M" in cleaner.log

Post by jomann »

Thanks for checking into this, we will have to test this internally to ensure it works properly in our use cases but I don't see any harm in having it added if it works for you. If it works with our tests as well then it will be added in the next bug fix release so you should be fine upgrading to the next version when it comes out without having to constantly add it back in.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked