Page 3 of 3

Re: Email Response Command - missing hash data

Posted: Sun Aug 04, 2019 4:27 pm
by MediaworksNZ
I can now confirm that this does not work either by adding characters in front of the action commands in the examples section.
Really hope this is something easily added by a simple code patch?

Thanks for your help, it is much appreciated.

Code: Select all

***** Nagios XI Alert *****

%alertsummary%

Notification Type: %type%
Host: %host%
State: %hoststate%
Address: %hostaddress%
Info: %hostoutput%
Date/Time: %datetime%

Respond: %responseurl%
Nagios URL: %xiserverurl%

******************************
*****  Email Response example1:  *****
******************************
*****  ack or acknowledge (choose one)  *****
*****  I'm looking into this right now (Optional Comments for acknowledgement)  *****

******************************
*****  Email Response example2:  *****
******************************
*****  down or downtime (choose one)  *****
*****  9:40 – 10:40 / now - 11:30 (two examples: specify time range)  *****
*****  Someone knocked the plug out!  *****

******************************
*****  Email Response example3:  *****
******************************
*****  delay (Delay the next time Nagios XI sends notifications for the object)  *****
*****  5 hour (Must be specified)  *****

In Case of Error:
*******************************************************************************************************************************************************
If the system cannot read a response email you will receive an email back with an error message. Otherwise, it will pass the command onto the subsystem.
*******************************************************************************************************************************************************

Re: Email Response Command - missing hash data

Posted: Mon Aug 05, 2019 3:31 pm
by ssax
Here's what should be in the message:

Code: Select all

    $text .= _("To reply, keep the following data in your response email.")."\n\n";
    $text .= "##".$encoded."##";
Those two ## in the start and end of the message should are where it's detecting the hash data like so:

Code: Select all

            // 2. Verify that the email object hash exists and the host/service exists
            $start = strpos($email['body'], '##');
            $end = strpos($email['body'], '##', $start + 2);
            if ($start !== false && $end !== false) {
                // DO STUFF
            } else {
                echo "Error - Could not find a valid hash in the email sent\n";
                $error = true;
            }
So when it's failing it's saying it can't find the start ## OR end ## from the replied message, I'm currently trying to replicate that.

Re: Email Response Command - missing hash data

Posted: Wed Aug 14, 2019 6:25 am
by jacek
Hi,

I'm also running into problems with this feature.
I allow myself to dump on the bottom of this message the reply I sent to nagios.

I get Response Error, and in the logs it only says that it couldn't find a host object in the hash provided.
So I modified the "/usr/local/nagiosxi/html/includes/components/xicore/xicore.inc.php" file to echo the $hash value to the logs, so I can see what it gets via tailing the cleaner.log file.

Now the funny part, it gets the following, note the additional "=" and new line:

Code: Select all

Running callbacks:
Error - Could not find a host object in the hash provided
NDYyZWJmMDMwMGMyZjczOGlvd2JzcTBYbHdTY1k0ZnRiNUI0eHZpaFB6NFVsbzVTNHJHM3cwW=
itsMXM9
Processed 1 incoming emails
Now it goes even weirder, I somehow managed to sent one mail where the hash has been correctly interpreted (only 5 lines, ack, comment and hash separated with a blank line), but I don't know why. (the command got dumped, but I presume that this was because of the extra empty lines, anyway, wouldn't bother - the hash is the issue right now)
I tried copying the hash into a fresh mail and it will get interpreted wrong again.
Kinda out of ideas here....

If I need to make a separate thread out of this then let me know :)

My mail sent to nagios:

Code: Select all

ack

test


From: Nagios <Nagios@company.com> 
Sent: Wednesday, August 14, 2019 12:25 PM
To: me <me@company.com>
Subject: PROBLEM Host Alert - HOST is DOWN

---- Respond above this line ----

***** Nagios XI Alert *****

Nagios has detected a problem with this host.

Notification Type: PROBLEM
Host: HOST
State: DOWN
Address: 1.2.3.4
Info: CRITICAL - 1.2.3.4: Host unreachable @ 1.2.3.5. rta nan, lost 100%
Date/Time: 2019-08-14 10:24:46

Respond: https://NAGIOS.COMPANY.com/nagiosxi/rr.php?oid=1558&token=e5153f57f8ab61a2fc1819da20086c1a1592d583
Nagios URL: https://NAGIOS.COMPANY.com/nagiosxi/

-----

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

##NDYyZWJmMDMwMGMyZjczOGlvd2JzcTBYbHdTY1k0ZnRiNUI0eHZpaFB6NFVsbzVTNHJHM3cwWitsMXM9##

Re: Email Response Command - missing hash data

Posted: Thu Aug 15, 2019 9:25 am
by jomann
Hello,

It looks like it's not stripping all the parts of the hash that it should in order for it to properly process the string. What I think will fix the hashing issue is by adjusting line 559 in the xicore.inc.php file from:

Code: Select all

$hash = trim(str_replace('> ', '', substr($email['body'], $start + 2, $end - $start - 2)));
to this new one:

Code: Select all

$hash = trim(str_replace(array('> ', '>', '=', "\n", "\t", "\r"), '', substr($email['body'], $start + 2, $end - $start - 2)));
This should account for things that should not be in the hash that get added by the email clients. I've tested this locally to make sure that the hash is readable but would like to see if it resolves your problem. If it does fix this issue, it'll be in 5.6.6 also.

Re: Email Response Command - missing hash data

Posted: Mon Aug 19, 2019 2:51 am
by jacek
Looks like this worked for me!
Thanks a lot! :)

BTW - I have ACK mails disabled for all my users, but answering with ACK is generating an ACK email to all contacts of that host.
Is this something that I can change somewhere? The mail says that this has been ack by Nagios Administrator.
jomann wrote:

Code: Select all

$hash = trim(str_replace(array('> ', '>', '=', "\n", "\t", "\r"), '', substr($email['body'], $start + 2, $end - $start - 2)));
This should account for things that should not be in the hash that get added by the email clients. I've tested this locally to make sure that the hash is readable but would like to see if it resolves your problem. If it does fix this issue, it'll be in 5.6.6 also.

Re: Email Response Command - missing hash data

Posted: Tue Aug 20, 2019 1:57 pm
by scottwilkerson
Are you just seeing it in the Notifications report or are they actually receiving the email?

I ask because the user-defined settings in the "Notification Preferences" act as a filter, and Nagios Core still sent the notification to the XI notification handler, but the user-defined setting suppress that. This is why it would still show in the report.

Re: Email Response Command - missing hash data

Posted: Thu Aug 22, 2019 7:42 am
by jacek
I think actually this was an issue caused by myself (notification preferences).
I am already on the 5.6.6 version - will test things again and if issues found - will let know :)

Re: Email Response Command - missing hash data

Posted: Thu Aug 22, 2019 7:47 am
by scottwilkerson
jacek wrote:I think actually this was an issue caused by myself (notification preferences).
I am already on the 5.6.6 version - will test things again and if issues found - will let know :)
sounds good!