Use OMD with ssmtp
If you use Open Monitoring Distribution (OMD) and don't want to setup a full-fledged Postfix or Sendmail service (e.g. because it is a test system) you might want to have a look at the alternative tool ssmtp
for relaying mails to an external mail server. The tool is only recommend if you don't need any local mail transfers.
Of course this works with Postfix and Sendmail as well but implementing this task is - depending on the configuration the mail server - more time-comsuming (e.g. because canonical maps, SASL, SSL/TLS have to be configures). I prefer ssmtp
for fast setups because I can do all the configuration tasks in one single file and this takes not even 5 minutes.
First of all you'll have to install ssmtp
:
1# yum install -y ssmtp
2# cp /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.initial
3# vi /etc/ssmtp/ssmtp.conf
4...
5root=mymail@myhoster.tld
6mailhub=smtp.myhoster.tld
7rewriteDomain=hoster.tld
8UseTLS=Yes
9UseSTARTTLS=Yes
10AuthUser=mymail@myhoster.tld
11AuthPass=...
12FromLineOverride=yes
13...
Afterwards you should test the functionality of ssmtp
at least once - it's recommended to have a look in the protocol file /var/log/maillog
:
1# uptime|sendmail mail@hoster.tld
2# tail -f /var/log/maillog
If sending mails is working fine you'll have to customize a script inside the appropriate OMD site - have a look at the variable $mail
in line 16:
1# vi /opt/omd/sites/SITE/lib/nagios/plugins/notify-by-email.pl
216gg
3...
4my $mail = $ENV{'OMD_ROOT'}.'/bin/mail -t';
You'll need to adjust the line like this:
1my $mail = $ENV{'OMD_ROOT'}.'/bin/mail';
A symbolic link inside the site has to be adjusted so that the mail
command points to the ssmtp
utility:
1# rm /opt/omd/sites/SITE/bin/mail
2# ln -s $(which ssmtp) /opt/omd/sites/SITE/bin/mail
It might be possible that your mail provides claims that you use sender addresses that are assigned to your server - if so, edit the file /etc/ssmtp/revaliases
:
1SITE:sender@hoster.tld
Sending mails from inside the site should work now:
1# su - SITE
2$ uptime|sendmail mail@hoster.tld
All notifications are now sent using ssmtp
- it is recommended to disable the previously used mail service and set a symbolic link if you also need to send mails from outside the OMD site:
1# chkconfig postfix off
2# service postfix stop
3# rm /etc/alternatives/mta
4# ln -s $(which ssmtp) /etc/alternatives/mta
Of course this works only if you don't need local mail transfer. 😉