Email Notification - Is there a way to display the error?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
JohnnieDaimler
Posts: 7
Joined: Wed Aug 02, 2017 8:38 am

Email Notification - Is there a way to display the error?

Post by JohnnieDaimler »

I want my email notification to display the error it finds. Is there a way?
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Email Notification - Is there a way to display the error

Post by mcapra »

You would have to edit the command definition associated with your notification handler. This documentation describes all the macros you will have available for Host Notifications and Service Notifications:
https://assets.nagios.com/downloads/nag ... olist.html

You might find the documentation for these macros particularly relevant as they give the output of the plugin associated with the host/service:

Code: Select all

$SERVICEOUTPUT$
$LONGSERVICEOUTPUT$
$HOSTOUTPUT$
$LONGHOSTOUTPUT$
In my mind, you could just append the $SERVICEOUTPUT$ or $HOSTOUTPUT$ to your message body.
Former Nagios employee
https://www.mcapra.com/
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Email Notification - Is there a way to display the error

Post by tmcdonald »

Thanks for the assist, @mcapra! OP, let us know if you need further assistance.
Former Nagios employee
JohnnieDaimler
Posts: 7
Joined: Wed Aug 02, 2017 8:38 am

Re: Email Notification - Is there a way to display the error

Post by JohnnieDaimler »

I already attached the SERVICEOUTPUT macro. I'm getting the following on my email body.

WARNING - (1 warnings) - 08-01 20:36:37.553

I want a more detailed message of the error. Is there a way to edit the SERVICEOUTPUT response to display what the warning is? Note, that I'm scanning a .log file searching for an err pattern.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Email Notification - Is there a way to display the error

Post by mcapra »

JohnnieDaimler wrote: I want a more detailed message of the error. Is there a way to edit the SERVICEOUTPUT response to display what the warning is?.
Try $LONGSERVICEOUTPUT$. Those macros only return whatever the plugin your check uses returned to stdout. If your plugin isn't returning specific enough data, there's no modification that can be made to the macro to work around that.

If that doesn't give you what you're looking for, can you share the output of your check command executed from the CLI of your Nagios Core machine?
Former Nagios employee
https://www.mcapra.com/
JohnnieDaimler
Posts: 7
Joined: Wed Aug 02, 2017 8:38 am

Re: Email Notification - Is there a way to display the error

Post by JohnnieDaimler »

I attached the command as a screenshot. I'm getting a nothing back on the LONGSERVICEOUT marco
Attachments
Capture.PNG
JohnnieDaimler
Posts: 7
Joined: Wed Aug 02, 2017 8:38 am

Re: Email Notification - Is there a way to display the error

Post by JohnnieDaimler »

I'm guessing there isn't a way to attach the log file to the email is there?
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Email Notification - Is there a way to display the error

Post by mcapra »

I'm actually looking for the command that produces this output:

Code: Select all

WARNING - (1 warnings) - 08-01 20:36:37.553
Not the command you are using for your notifications. Again, the various OUTPUT macros rely completely and entirely on what the plugin gives you, so it's valuable to know what, if anything, a given plugin produces.

For example, here's the output for an execution of the check_http plugin:

Code: Select all

[root@nagios ~]# /usr/local/nagios/libexec/check_http -H www.google.com
HTTP OK: HTTP/1.1 200 OK - 11974 bytes in 0.086 second response time |time=0.085856s;;;0.000000 size=11974B;;;0
If I were to include this plugin in a service definition as part of it's check_command, I would expect notifications for this service to have $SERVICEOUTPUT$ return something like the following:

Code: Select all

HTTP OK: HTTP/1.1 200 OK - 11974 bytes in 0.086 second response time 
Former Nagios employee
https://www.mcapra.com/
JohnnieDaimler
Posts: 7
Joined: Wed Aug 02, 2017 8:38 am

Re: Email Notification - Is there a way to display the error

Post by JohnnieDaimler »

Ok, where would I find out what plugin the service uses?
JohnnieDaimler
Posts: 7
Joined: Wed Aug 02, 2017 8:38 am

Re: Email Notification - Is there a way to display the error

Post by JohnnieDaimler »

I believe that this service is using the check_nrpe plugin....note that I didn't create all the commands and services
Locked