Nagios email alert configuration - email

I am configuring Nagios to send email alerts through postfix configured to an SMTP Relay Server, I have configured my commands.cfg and contacts.cfg to contain the required settings. However, whenever the email goes out, it is not picking up the configurations I have in my contacts.cfg and always takes a default email id:
Mar 26 02:20:05 dash postfix/pickup[24908]: 395DBBE0DC3: uid=1002 from=<oem>
Mar 26 02:20:05 dash postfix/cleanup[25635]: 395DBBE0DC3: message-id=<20180325205005.395DBBE0DC3#dash.in>
Mar 26 02:20:05 dash postfix/qmgr[17430]: 395DBBE0DC3: from=<oem#dash.in>, size=595, nrcpt=1 (queue active)
Mar 26 02:20:10 dash postfix/smtp[25637]: 395DBBE0DC3: to=<oem#dash.in>, orig_to=<oem>, relay=relay.smtp.dash.in:587, delay=5.6, delays=0.01/0.01/3.8/1.7, dsn=2.0.0, status=sent (250 Ok 010101625eecf59b-243d9f21-ae1c-4272-9213-55e11d7d5e25-000000)
Mar 26 02:20:11 dash postfix/qmgr[17430]: 395DBBE0DC3: removed
I have not configured the oem user anywhere in postfix or nagios, however there is an oem user on my system. I'm missing something basic I feel, if anyone has any idea do let me know.
Cheers!

Use grep to find out where it is configured:
$ sudo grep -s -R "oem#dash.in" /etc/*
$ sudo grep -s -R "oem#dash.in" /usr/local/nagios/*
$ cat /usr/local/nagios/etc/nagios.cfg | grep #
admin_email=myaccount#gmail.com
admin_pager=myaccount#gmail.com
$ cat /usr/local/nagios/etc/objects/contacts.cfg | grep #
email nagios#localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
email myaccount#gmail.com;
Test your configuration by:
$ echo "Test Email message body" | mail -r account_accepted_by_relay#mydomainname.onmicrosoft.com -s "Email test subject" myaccount#gmail.com
I've installed mailutils before using that test command:
$ sudo apt install mailutils
I'm using sendgrid, so my main.cf configuration includes:
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = localhost.localdomain
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, localhost
relayhost = [smtp.sendgrid.net]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
You could look here for more detailed explanation.

Related

sendemail unable to connect to stunnel on IP 127.0.0.1 (Port 259)

I recently setup a new Windows 10 computer. On it I transfered scripts I am using elseware. The script involves sendemail.exe sending out an email using stunnel to gmail.
The script is as follows:
c:\Program Files (x86)\sendEmail>sendEmail.exe -l c:\temp\sendemail.log -t email#gmail.com -u "Email Subject" -m "Email Message" -s 127.0.0.1:6259 -f senderemail#gmail.com -xu senderemail -xp 123456789012345 -o tls=auto
The above commands fails with the following error: '''Aug 07 15:45:15 dell-pms sendEmail.exe[5196]: ERROR => Connection attempt to 127.0.0.1:6259 failed: IO::Socket::INET: connect: Unknown error'''
Replacing 127.0.0.1 with localhost fails.
Repeating the command but replacing the IP address (127.0.0.1) with the computer's IP address 192.168.16.76 works.
The hosts file is the default (everything remarked).
Any suggestion how to diagnose.

SSMTP fails after migrating to Buster

SSMTP was working for years now on my RPi - latest on stretch.
Now I migrated to buster - and after this step it now fails.
$ cat /etc/ssmtp/ssmtp.conf
root=user#mydomain.com
mailhub=smtp.gmail.com:587
hostname=localhost
UseSTARTTLS=YES
AuthUser=user#gmail.com
AuthPass=very_secret
FromLineOverride=YES
$ echo "MailBody"|mail --debug-level=3 -s "My Subject" mailaddress#domain.com
mail: sendmail binary: /usr/sbin/sendmail
mail: source=system, name=user, passwd=x, uid=1001, gid=1000, gecos=user,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
mail: source=system, name=user, passwd=x, uid=1001, gid=1000, gecos=user,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
mail: mu_mailer_send_message(): using From: user#localhost
mail: Sending headers...
mail: Sending body...
mail: /usr/sbin/sendmail exited with: 1
mail: progmailer error: Process exited with a non-zero status
mail: cannot send message: Process exited with a non-zero status
mail: source=system, name=user, passwd=x, uid=1001, gid=1000, gecos=user,,,, dir=/home/user, shell=/bin/bash, mailbox=/var/mail/user, quota=0, change_uid=1
$ echo $?
36
I have a lot of shell-scripts sending mails with commands like:
echo "MailBody"|mail -s "My Subject" emailaddress#domain.com
=> so if SSMTP is no longer supported, I would neeed a solution following that syntax ...
thanks for any help!
I fixed this by switching away from ssmtp (which some sources say being unmaintained) to msmtp (https://wiki.debian.org/msmtp).
This could or could not apply to you, try to check the error code by sending an email directly via /usr/sbin/ssmtp -v ...., I had exit 36 (echo $? to get the code).
If you are in a similar situation and want to give msmtp a try, these the steps I followed:
Install:
$ sudo apt remove ssmtp
$ sudo apt install msmtp msmtp-mta
Configure (I'm not configuring GMail, I use Dreamhost email service, so your details might be different):
$ cat /etc/msmtprc
# Set default values for all following accounts.
defaults
auth on
tls on
tls_starttls off
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /tmp/msmtp.log
# Raspberry Pi
account rasp
host smtp.dreamhost.com
port 465
from raspberry#<REDACTED>
user raspberry#<REDACTED>
password <PLAINTEXTPASSWORD>
# default account
account default : rasp
For comparison, this was my /etc/ssmtp.conf file:
root=postmaster
mailhub=smtp.dreamhost.com:465
AuthUser=raspberry#<REDACTED>
AuthPass=<REDACTED>
UseTLS=YES
UseSTARTTLS=YES
TLS_CA-File=/etc/ssl/certs/ca-certificates.crt
hostname=<REDACTED>.org
FromLineOverride=NO
Set msmtp as default MTA. I've added the last line to my mail.rc file:
$ cat /etc/mail.rc
set ask askcc append dot save crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To
set mta=/usr/bin/msmtp
[NOTE]: There is also an issue with msmtp in that it's not populating automatically the "From:" header in the message so emails get rejected, to fix it, when calling mail make sure to do it manually:
echo TEST | mail -a "From: raspberry#<REDACTED>" --debug-level 10 -s '[rasp] server' <REDACTED>#gmail.com
This makes email sending work again from my Raspberry Pi on Debian buster/sid.

Raspberry PI - Send mail from command line using GMAIL smtp server

How can I send email from Raspberry Pi using my gmail account?
I would like to send mail from command line and use this method in my scripts.
Envirenment:
Hardware: Raspberry PI 3
OS: Jessie
SMTP: smtp.gmail.com
I use this method on my Raspberry Pi 3 devices:
Google account setting
Login to your gmail account
Go to: Settings -> Accounts and Import -> Other Google Account settings
Go to: Personal info & privacy -> Account overview
Go to: Sign-in & security -> Connect apps & sites
Set option Allow less secure apps to ON
Install SSMTP
sudo apt-get install ssmtp
Save original conf file
sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bak
Create new conf file (with vi, or some other text editor)
sudo vi /etc/ssmtp/ssmtp.conf
file content
root=your_account#gmail.com
mailhub=smtp.gmail.com:587
FromLineOverride=YES
AuthUser=your_account#gmail.com
AuthPass=your_password
UseSTARTTLS=YES
UseTLS=YES
# Debug=Yes
Secure conf file
sudo groupadd ssmtp
sudo chown :ssmtp /etc/ssmtp/ssmtp.conf
If you have error on this step like ''cannot access'' ... you must find ssmtp file and use that path: sudo find / -name "ssmtp"
sudo chown :ssmtp /usr/sbin/ssmtp
sudo chmod 640 /etc/ssmtp/ssmtp.conf
sudo chmod g+s /usr/sbin/ssmtp
Sending mail from (only one) command line
echo "This is a test" | ssmtp recipient.address#some_domain.com
or
printf "To: recipient.address#some_domain.com\nFrom: RaspberryPi3\nSubject: Testing send mail from Raspberry\n\nThis is test. Best Regards!\n" | ssmtp -t
Sending mail from file test.txt
Make file with similar content:
To: recipient.address#some_domain.com
From: your_account#gmail.com
Subject: Testing send mail from Raspberry
This is test mail (body)
Best Regards!
Now you can send mail from file
ssmtp recipient.address#some_domain.com < test.txt
That's all :)

gsutil rsync -C "continue" option not working

gsutil rsync -C "continue" option is not working from backup_script:
$GSUTIL rsync -c -C -e -r -x $EXCLUDES $SOURCE/Documents/ $DESTINATION/Documents/
From systemd log:
$ journalctl --since 12:00
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (CommandException: Error opening file "file:///home/wolfv/Documents/PC_maintenance/backup_systems/gsutil/ssmtp.conf": .)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
Jul 25 12:00:14 localhost.localdomain CROND[9694]: (wolfv) CMDOUT (Caught ^C - exiting)
because owner is root rather than user:
$ ls -l ssmtp.conf
-rw-r-----. 1 root root 1483 Jul 24 21:30 ssmtp.conf
rsyc worked fine after deleting the root-owned file.
This happened on a Fedora22 machine, when cron called backup_script which called gsutil rsync.
Thanks for reporting that problem. We'll get a fix for this bug in gsutil release 4.14.
Mike

CFG Error email receiving every 5 minutes from Zabbix on Unix server

I have configured sSMTP on myzabbixserver Unix system which successfully delivers Zabbix alerts via Gmail. Strangely I am receiving an email in my Gmail inbox (which I am using as From address for sSMTP config) EVERY 5 minutes with following details:
from: root <my.zabbix#gmail.com>
to: root
bcc: my.zabbix#gmail.com
subject: Cron <root#myzabbixserver> if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi
body: ERROR: CFG Error in "workdir", line 8: Working directory /var/www/mrtg does not exist
sSTMP.conf
root=my.zabbix#gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
AuthUser=my.zabbix#gmail.com
AuthPass=my.password
hostname=myzabbixserver
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
AuthMethod=LOGIN
gmail.sh script which Zabbix uses to send email alerts:
#!/bin/bash
to=$1
subject=$2
body=$3
echo $body | /usr/bin/mailx $to -s "$subject"
What does that email mean and how can I stop it ?
This is not a Zabbix problem, but mrtg problem. Your mrtg cron job /etc/cron.d/mrtg is failing and you are receiving this cron error output.
Solutions:
configure mrtg correctly (http://www.debianhelp.co.uk/mrtg.htm)
uninstall mrtg/disable mrtg cron job
...