Postfix configuration for Opsview Core

13 Feb

I’ve been using Opsview Core to keep an eye on various network resources for a while now.  I never really bothered to setup the notification system because, honestly, my phone acts as the notification system.  Recently, however, the boss has asked to get email notifications about certain things after hours.  Okay, so I needed to get Postfix set up.

My limited experience setting up an MTA has required a bunch of google mojo every time.  There are a number of really good resources, but no one source ever included everything I needed.  So, I’ll try to put it all in one place here… partly for my own reference, but perhaps it may help someone down the road.

For starters, I have Opsview (Core 3.20120925.0) running on a Ubuntu 10.04 VM install.

My postfix MTA doesn’t need to receive mail whatsoever, only send out the notification emails.  Indeed the Opsview server is not reachable from outside the LAN.

I had some time ago, installed sendmail on the server.  I’ve actually yet to successfully configure sendmail, so first things first, I needed to install postfix and the sasl packages for smtp authentication.

# sudo apt-get install postfix
# sudo apt-get install libsasl2-modules

This, incidentally, this will also uninstall sendmail if it’s installed.  Nice.  Now onto the configuration.
# sudo nano /etc/postfix/main.cf

Here, I started with the instructions on the postfix site.  Now, I’m not concerned with who the mail seems to be coming from, nor is my server on a routable domain, so the local references were fine for me.  Also, I just created a gmail account to be the account that authenticated with the gmail smtp server.
myhostname = Opsview-Core.localdomain
myorigin = $&;mydomain
relayhost = [smtp.gmail.com]:587
inet_interfaces = loopback-only
mydestination = $&;myhostname, localhost.$&;mydomain, localhost

Next, I needed to set up the smtp authentication with gmail.  I’ll be the first to admit that I don’t know if all of the lines below are required in order to accomplish my limited objectives.  On line 3 below here, the sasl-passwords file can be named whatever you want,  I just followed a tutorial, and that seemed like as good a name as any.
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl-passwords
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_security_level = may

Next I needed to create the hash that is referenced above.  Using your favorite text editor, create the file and add the line:
# sudo nano /etc/postfix/sasl-passwords
THEN ADD TO THE FILE:
[smtp.gmail.com]:587  username@gmail.com:password

Then, compile:
# sudo postmap /etc/postfix/sasl-passwords

That’s about it!  Restart postfix and then test.
# sudo /etc/init.d/postfix restart

For testing, I used the following command.  (the test needs to be run as user nagios)
# sudo su – nagios
nagios# /usr/local/nagios/utils/test_notifications hostproblem /usr/local/nagios/libexec/notifications/notify_by_email -t -e com.opsview.notificationmethods.email.tt
nagios# exit <— this leaves the nagios user

The -t flag has the test message print to screen.  Removing the -t flag will actually send the test email.  After running the test, I went and checked the mail logs to see if it was successfully sent.
# tail /var/log/mail.log

Once I got this set up and working, I started seeing a bunch of bouncbacks in my gmail inbox.  They were all cronjob messages about a failed sendmail action being sent to root@localdomain.  Apparently, the postfix install doesn’t completely eliminate all of the sendmail files.  The following line seems to have taken care of my sendmail cronjob issue.
# sudo apt-get –purge remove sendmail-base sendmail-cf sendmail-doc

It’s still early, but I think I’ve got everything set up on the postfix side.  Now it’s on to the various Opsview notification settings so that the boss doesn’t get an email alert every time a ping is 2ms over the threshold :)

Tags: , , , ,

One Response to “Postfix configuration for Opsview Core”

  1. Heidilux February 14, 2013 at 2:36 pm #

    Incidentally, if you do want to change the name of the user that the notification emails are sent from (by default, the nagios user actually makes the call to postfix to send the mail) run the command chfn nagios

Leave a Reply