Page 1 of 2

Nagios 4.4.5 email alerts with encoding

Posted: Fri Feb 14, 2020 9:11 am
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!

Re: Nagios 4.4.5 email alerts with encoding

Posted: Mon Feb 17, 2020 7:14 pm
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.

Re: Nagios 4.4.5 email alerts with encoding

Posted: Tue Feb 18, 2020 3:30 am
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

Re: Nagios 4.4.5 email alerts with encoding

Posted: Tue Feb 18, 2020 4:32 pm
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.

Re: Nagios 4.4.5 email alerts with encoding

Posted: Fri Feb 21, 2020 4:32 am
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 "текст на кирилица".

Re: Nagios 4.4.5 email alerts with encoding

Posted: Fri Feb 21, 2020 7:47 am
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$

Re: Nagios 4.4.5 email alerts with encoding

Posted: Fri Feb 21, 2020 9:30 am
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.

Re: Nagios 4.4.5 email alerts with encoding

Posted: Fri Feb 21, 2020 10:54 am
by scottwilkerson
Hmm, can I have you try changing it to single quotes

Code: Select all

-a 'Content-Type: text/plain; charset=UTF-8'

Re: Nagios 4.4.5 email alerts with encoding

Posted: Fri Feb 21, 2020 3:40 pm
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

Re: Nagios 4.4.5 email alerts with encoding

Posted: Mon Feb 24, 2020 4:34 am
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...