Nagios 4.4.5 email alerts with encoding

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.
ttsvetanov
Posts: 15
Joined: Tue Jun 26, 2018 8:46 am

Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

Hello community!

I am using nagios 4.4.5 and i am receiving errors when i add argument with character encoding to my command.

This is the command:

Code: Select all

/usr/bin/printf "%b" "$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress:$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDuration: $HOSTDURATION$\nAlias: $HOSTALIAS$\n\nDate/Time: $LONGDATETIME$ \n" | /usr/bin/mail -s "**SITE1 $NOTIFICATIONTYPE$ Host $HOSTNAME$ is $HOSTSTATE$" $CONTACTEMAIL$ -a "From: someone <[email protected]>"
And it's working fine in this way. But when i add -a "Content-Type: text/plain; charset=UTF-8"" :

Code: Select all

/usr/bin/printf "%b" "$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress:$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDuration: $HOSTDURATION$\nAlias: $HOSTALIAS$\n\nDate/Time: $LONGDATETIME$ \n" | /usr/bin/mail -s "**SITE1 $NOTIFICATIONTYPE$ Host $HOSTNAME$ is $HOSTSTATE$" $CONTACTEMAIL$ -a "From: someone <[email protected]>" -a "Content-Type: text/plain; charset=UTF-8"
It's not sending any mail. Nagios log gives me:
wproc: stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string
Any ideas?

Thank you!
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios 4.4.5 email alerts with encoding

Post by Box293 »

What is the actual mail binary?

Code: Select all

ls -la /usr/bin/mail
Perhaps instead of:
-a "From: someone <[email protected]>" -a "Content-Type: text/plain; charset=UTF-8"

Try:
-a "'From: someone <[email protected]>'; Content-Type: text/plain; charset=UTF-8"

The first troubleshooting test I would do would be from the command line as the nagios user with all the variables expanded out. Basically lets remove Nagios from the equation and test purely the commands.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
ttsvetanov
Posts: 15
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

I am using sendmail.
The command is working fine executed from the command line. With:

Code: Select all

-a "'From: someone <[email protected]>'; Content-Type: text/plain; charset=UTF-8"
I receive
stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios 4.4.5 email alerts with encoding

Post by Box293 »

Can you show us the full command and output from the commands we requested.
ttsvetanov wrote:I receive
stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string
Is this the output when running independently ?

The more detailed information you provide, the quicker your problem can be resolved.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
ttsvetanov
Posts: 15
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

Code: Select all

/usr/bin/printf "%b" "текст на кирилица" | /usr/bin/mail -s "proben tekst" -a "'From: [email protected] <[email protected]>'; Content-Type: text/plain; charset=UTF-8" [email protected]
Successfull received mail, but it's not taking the arguments after -a. The mail is from [email protected] with content "текст на кирилица".

Code: Select all

/usr/bin/printf "%b" "текст на кирилица" | /usr/bin/mail -s "proben tekst" -a "From: [email protected] <[email protected]>" -a "Content-Type: text/plain; charset=UTF-8" [email protected]
Successfull received mail with successfull taken argument "From" and "Content-Type".
The mail is from [email protected] and the content is "текст на кирилица".
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios 4.4.5 email alerts with encoding

Post by scottwilkerson »

You need to move the -a arguments before the send to email

Code: Select all

/usr/bin/printf "%b" "$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress:$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDuration: $HOSTDURATION$\nAlias: $HOSTALIAS$\n\nDate/Time: $LONGDATETIME$ \n" | /usr/bin/mail -s "**SITE1 $NOTIFICATIONTYPE$ Host $HOSTNAME$ is $HOSTSTATE$" -a "From: someone <[email protected]>" $CONTACTEMAIL$
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ttsvetanov
Posts: 15
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

Well i tried with the following command line:

Code: Select all

/usr/bin/printf "%b" "$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress:$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDuration: $HOSTDURATION$\nAlias: $HOSTALIAS$\n\nDate/Time: $LONGDATETIME$ \n" | /usr/bin/mail -s "**SITE1 $NOTIFICATIONTYPE$ Host $HOSTNAME$ is $HOSTSTATE$" -a "From: [email protected] <[email protected]>" -a "Content-Type: text/plain; charset=UTF-8" $CONTACTEMAIL$
Again no mail with the following in nagios.log:
wproc: stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string
Again, when i remove
-a "Content-Type: text/plain; charset=UTF-8"
from the line, i am receiving mails.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios 4.4.5 email alerts with encoding

Post by scottwilkerson »

Hmm, can I have you try changing it to single quotes

Code: Select all

-a 'Content-Type: text/plain; charset=UTF-8'
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ttsvetanov
Posts: 15
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

with

Code: Select all

-a 'Content-Type: text/plain; charset=UTF-8'
:
[1582317513] EXTERNAL COMMAND: SEND_CUSTOM_HOST_NOTIFICATION;$NameOfTheHost$;0;Nagios Admin;qwww
[1582317528] wproc: Core Worker 16659: job 266 (pid=21826) timed out. Killing it
[1582317528] wproc: CHECK job 266 from worker Core Worker 16659 timed out after 30.01s
[1582317528] wproc: early_timeout=1; exited_ok=0; wait_status=0; error_code=62;
[1582317528] wproc: Core Worker 16659: job 266 (pid=21826): Dormant child reaped
ttsvetanov
Posts: 15
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

Even tried with:

Code: Select all

command_line    /usr/bin/printf "%b" "Здрасти, това тук е тестов текст на кирилица, изпратен от NAGIOS CGI." | /usr/bin/mail -a "Content-Type: text/plain; charset=UTF-8" -s "Заглавие на тестовия мейл"
And again i received unterminated quoted string...
Locked