Page 1 of 5
Email of multiline output
Posted: Wed Sep 29, 2021 8:43 am
by hbouma
Nagios XI 5.6.4 on RHEL 7 VMs
I have a check command that outputs multiple lines. However, the email is coming across with only the first line.
I attempted changing the notifications to use the %serviceoutput% and %longserviceoutput%, however, it now outputs the long service output with \n instead of an actual new line. I saw the post
https://support.nagios.com/forum/viewto ... =16&t=8443 and tried what was put in this post, but it didn't seem to work.
Email content:
……………………
Info:
"Files modified in the last 120 minutes. Files are:"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf
\nXXXXXXXXXXXXXXXXXXXXXX.pdf"
Date/Time: 2021-09-29 09:29:19
Notification Email message settings:
Info:
"%serviceoutput%"
"%longserviceoutput%"
Date/Time: %datetime%
GUI output
2021-09-29 09_32_57-Service Status Detail · Nagios XI and 11 more pages - Work - Microsoft Edge.png
Re: Email of multiline output
Posted: Thu Sep 30, 2021 9:35 am
by pbroste
Hello @hbouma
Thanks for reaching out, please PM your system profile for us to review so we can see what is going on.
To send us your system profile.
- Login to the Nagios XI GUI using a web browser.
- Click the "Admin" > "System Profile" Menu
- Click the "Download Profile" button
- Save the profile.zip file and send via Private Message
Thanks,
Perry
Re: Email of multiline output
Posted: Thu Sep 30, 2021 9:43 am
by hbouma
Profile sent.
Re: Email of multiline output
Posted: Fri Oct 01, 2021 3:06 pm
by pbroste
Hello @hbouma,
I see that you are implementing or testing 'onCallEvent.sh' script with $LONGSERVICEOUTPUT$ variable and want to know what results you are receiving when you manually run that with the '$LONGSERVICEOUTPUT$ variable'.
Code: Select all
'/usr/local/integrate/everbridge/onCallEvent.sh \"$SERVICESTATE$\" \"$SERVICESTATETYPE$\" \"$SERVICEATTEMPT$\" \"$SERVICEGROUPNAME$\" \"$SERVICEOUTPUT$\" \"$LONGSERVICEOUTPUT$\" \"$HOSTNAME$\" \"$SERVICEDESC$\" \"$SERVICEDISPLAYNAME$\"',2,'1','2018-09-26 19:40:45',NULL,1),(142,'Test','echo \"check failed\" + \"$SERVICEDESC$\" + \"$LASTSERVICESTATE$\" + \"$LASTSERVICESTATEID$\" + \"$SERVICESTATETYPE$\" + \"$CONTACTGROUPALIAS$\" >> /tmp/thisisatest.txt'
Please let me know the results.
Perry
Re: Email of multiline output
Posted: Mon Oct 04, 2021 7:31 am
by hbouma
The problem is from the built in Nagios XI email that are not actually inserting the new line in the email itself.
The onCallEvent.sh script sends data out to our EverBridge paging system. Although this script does take in the LONGSERVICEOUTPUT from the Nagios XI program, it only uses that data to do some internal logic and doesn't actually pass that data along through the page out. Instead, we depend on the Nagios XI program to pass along that data.
Re: Email of multiline output
Posted: Tue Oct 05, 2021 10:38 am
by hbouma
Hi, I haven't heard anything back on this. Just looking for an update.
Re: Email of multiline output
Posted: Tue Oct 05, 2021 1:21 pm
by pbroste
Hello @hbouma
I have "labbed" this up on my test VM and am finding that I am receiving no additional info from the $LONGSERVICEOUTPUT$.
I will follow up shortly on further test results.
Thanks,
Perry
Re: Email of multiline output
Posted: Mon Oct 11, 2021 1:08 pm
by hbouma
Hi,
I just wanted to follow up on this and see if you found anything in the lab.
Re: Email of multiline output
Posted: Tue Oct 12, 2021 3:10 pm
by pbroste
Hello @hbouma
Thanks for pinging me on this, took the time today and tested the option to add the $LONGSERVICEOUTPUT$. In my example; we added the following to 'notify-service-by-email':
/usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$ $LONGDATETIME$\n\n2ndAdditional Info:\n\n$LONGSERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
To test:
Code: Select all
/usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$ $LONGDATETIME$\n\n2ndAdditional Info:\n\n$LONGSERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" root@localhost
We see that the variable is ready for data stream matching $LONGSERVICEOUTPUT$'s:
Code: Select all
Subject: ** $ Service Alert: $/$ is $ **
To: <root@localhost>
X-Mailer: mail (GNU Mailutils 3.7)
Message-Id: <20211012200049.DD31EC0E86@nagiosserver>
Date: Tue, 12 Oct 2021 20:00:49 +0000 (UTC)
From: root <root@nagiosserver>
***** Nagios Monitor XI Alert *****
Notification Type: $
Service: $
Host: $
Address: $
State: $
Date/Time: $
Additional Info:
$ $
2ndAdditional Info:
$
The $LONGSERVICEOUTPUT$ requires a plugin that will output additional or second line(s) of information.
On my test I sent out the following two lines on email alert:
Code: Select all
Subject: ** PROBLEM Service Alert: 192.168.111.115/Disk Usage on /snap/core18/2074 is CRITICAL **
To: <root@localhost>
X-Mailer: mail (GNU Mailutils 3.7)
Message-Id: <20211012193546.96A28C0E2B@nagiosserver>
Date: Tue, 12 Oct 2021 19:35:46 +0000 (UTC)
From: nagios@nagiosserver
***** Nagios Monitor XI Alert *****
Notification Type: PROBLEM
Service: Disk Usage on /snap/core18/2074
Host: 192.168.xxx.115
Address: 192.168.xxx.115
State: CRITICAL
Date/Time: Tue Oct 12 19:35:46 UTC 2021
Additional Info:
CRITICAL: Used disk space was 100.00 % (Used: 0.05 GiB, Free: 0.00 GiB, Total: 0.05 GiB) Tue Oct 12 19:35:46 UTC 2021
2ndAdditional Info: On /dev/sda2
Thanks,
Perry
Re: Email of multiline output
Posted: Wed Oct 13, 2021 6:33 am
by hbouma
I am a bit confused as to why we are editing the command? We have already updated the notification template to include the LONGSERVICEOUTPUT, which shows with new lines in the GUI just fine.
***** Nagios XI Alert *****
%alertsummary%
Notification Type: %type%
Service: %service%
Host: %host%
Address: %hostaddress%
State: %servicestate%
Info:
"%serviceoutput%"
"%longserviceoutput%"
Date/Time: %datetime%
Rapid Respond: %responseurl%
Nagios URL: %xiserverurl%
The plugin we are running does insert new lines into the output. Here is the snippet pulling in the information based on
https://support.nagios.com/forum/viewto ... 93#p333955:
Code: Select all
# Checks for new files in $FOLDER that were created in the last $MINUTES
#Get parameters
param([string] $FOLDER, [int] $TIME)
#Set default exit code
$EXIT_CODE = 0
try
{
#Get list of files in $FOLDER that are older than $TIME minutes old, convert FILES to a string, set exit code 2 and set output
$FILES = (Get-ChildItem -Path $FOLDER -Exclude 'SOME FOLDERS*' -File -Recurse | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-$TIME/1440)} | % { $_.FullName } )
#If FILES is empty or null
if (-not [string]::IsNullOrEmpty($FILES)){
$FILES_OUTPUT = $FILES | Out-String
$EXIT_CODE = 2
$output = "Files modified in the last $TIME minutes. Files are:`n$FILES_OUTPUT"
}
#If FILES is empty or null, set exit code and output.
elseif ([string]::IsNullOrEmpty($FILES)){
$EXIT_CODE = 0
$output = "No files modified in the last $TIME minutes."
}
#Else, something went wrong.
else {
$EXIT_CODE = 3
$output = "Something went wrong with the check. Please email XXXXXXXXXXXXXXXX for support with the following Diagnostic information: Folder = $FOLDER and Time = $TIME"
}
if ($EXIT_CODE -eq 2){
Write-Output $output
exit 2
}
elseif ($EXIT_CODE -eq 0) {
Write-Output $output
exit 0
}
else {
Write-Output "Something went wrong with the check. Please email XXXXXXXXXXXXXXXXXXX for support with the following Diagnostic information: Folder = $FOLDER and Time = $TIME"
exit 3
}
}
catch
{
Write-Output "Something went wrong with the check. Please email XXXXXXXXXXXXXX with the following Diagnostic information Folder = $FOLDER and Time = $TIME for support. Code: $_"
$_="";
exit 3;
}