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.
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 »

Earlier you mentioned it worked from the commandline with the -a flags combined, can you try the following

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 <some@mail.com>'; Content-Type: text/plain; charset=UTF-8" $CONTACTEMAIL$
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
ttsvetanov
Posts: 13
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

scottwilkerson wrote:Earlier you mentioned it worked from the commandline with the -a flags combined, can you try the following

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 <some@mail.com>'; Content-Type: text/plain; charset=UTF-8" $CONTACTEMAIL$
ttsvetanov wrote:...... With:

Code: Select all

-a "'From: someone <some@mail.com>'; Content-Type: text/plain; charset=UTF-8"
I receive
stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string
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 »

I'm not sure if I am going down the correct path here, but can you show the output of

Code: Select all

su nagios -c 'env|grep LANG'
su nagios -c 'locale'
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
ttsvetanov
Posts: 13
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

Code: Select all

root@nagios:/tmp# su nagios -c 'env|grep LANG'
LANG=en_US.UTF-8
root@nagios:/tmp# su nagios -c 'locale'
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
root@nagios:/tmp#
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 »

ttsvetanov wrote:

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 <some@mail.com>" -a "Content-Type: text/plain; charset=UTF-8"
I just tested this on a freshly setup Debian 9 system running Nagios Core 4.4.5 with the command above as the only host notification handler and when I took the host down with the following text as the message:

Code: Select all

Здрасти, това тук е тестов текст на кирилица, изпратен от NAGIOS CGI.
I received the following email as expected

Code: Select all

From some@mail.com Thu Feb 27 10:12:38 2020
Return-path: <some@mail.com>
Envelope-to: nagios@localhost
Delivery-date: Thu, 27 Feb 2020 10:12:38 -0600
Received: from nagios by debian9x64 with local (Exim 4.89)
        (envelope-from <some@mail.com>)
        id 1j7Lm9-0003CB-Ur
        for nagios@localhost; Thu, 27 Feb 2020 10:12:37 -0600
Subject: **SITE1 PROBLEM Host localhost is DOWN
From: someone <some@mail.com>
Content-Type: text/plain; charset=UTF-8
To: <nagios@localhost>
X-Mailer: mail (GNU Mailutils 3.1.1)
Message-Id: <E1j7Lm9-0003CB-Ur@debian9x64>
Date: Thu, 27 Feb 2020 10:12:37 -0600

PROBLEM
Host: localhost
State: DOWN
Address:127.0.0.1
Info: Здрасти, това тук е тестов текст на кирилица, изпратен от NAGIOS CGI.
Duration: 0d 0h 0m 0s
Alias: localhost

Date/Time: Thu Feb 27 10:12:37 CST 2020

Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
ttsvetanov
Posts: 13
Joined: Tue Jun 26, 2018 8:46 am

Re: Nagios 4.4.5 email alerts with encoding

Post by ttsvetanov »

Are you using sendmail for mail client?
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 »

The mailer was mail (GNU Mailutils 3.1.1)

I just opened the text file for the message in vi
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked