Page 1 of 2

Postfix

Posted: Thu Feb 28, 2013 2:50 am
by MPIvan
Hi again :)

Can someone guide me through the simple installations of a postfix as a null client so nagios can send me a notification if something is changing ... i have install Ubuntu server 12.04 LTS and nagios work great on it ... On the Ubuntu Server there is nothing more just a nagios and updates ...

Re: Postfix

Posted: Thu Feb 28, 2013 7:02 am
by gshergill
Hi MPIvan,

Below are the steps I used to install Postfix on Ubuntu 12.04:

Postfix Server Installation

First you need to install postfix;

Code: Select all

apt-get install postfix
When prompted, choose internet site, then enter the @ part where you wish the mail to be sent from, e.g nagios.notify.
This will mean that emails received from nagios will be @nagios.notify..

Mailx Server Installation

Now install nagios's part of the mail server;

Code: Select all

apt-get install heirloom-mailx
Configuring Nagios Mail Command

You need to edit the commands.cfg folder to take into account the new paths;

Code: Select all

vi /usr/local/nagios/etc/objects/commands.cfg
Replace;

Code: Select all

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
With;

Code: Select all

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
Note that the change is '/bin/mail' to '/usr/bin/mailx'.

Now restart Nagios;

Code: Select all

/etc/init.d/nagios restart
You should now receive email notifications of services/host states (after defining the email in the contact definition).

Good luck!

Kind Regards,

Gary Shergill

Re: Postfix

Posted: Thu Feb 28, 2013 11:04 am
by slansing
Thanks for the great guide Garry! I'm sure that will be very helpful. If you run into any issues let us know MPIvan.

Re: Postfix

Posted: Fri Mar 01, 2013 8:11 am
by MPIvan
Hi tnx to all for the reply's !!!

I have one question for now ...
When prompted, choose internet site, then enter the @ part where you wish the mail to be sent from, e.g nagios.notify.
This will mean that emails received from nagios will be @nagios.notify..
.

What if i want to be send as [email protected] then as you say instead of @nagios.notify should be @mydomain.com i suppose ?

Re: Postfix

Posted: Fri Mar 01, 2013 11:15 am
by gshergill
Hi MPIvan,

Yup I don't see any reason why that wouldn't work. I only chose nagios.notify because it helps me organise my emails more effectively.

Kind Regards,

Gary Shergil

Re: Postfix

Posted: Fri Mar 01, 2013 2:08 pm
by slansing
Please let us know if you run into further issues regarding this topic!

Re: Postfix

Posted: Mon Mar 04, 2013 10:18 am
by MPIvan
Hi,

we have some problem with the network and network policy ... new firewall added and i cant download nothing :) so im hoping tomorrow im gonna start ... first i have to fix this policy on the new firewall cant dl postifx :S ... tnx for helping me and i will post how it went the firs thing ill do after the postfix installed .... tnx again for support ...

Re: Postfix

Posted: Mon Mar 04, 2013 12:02 pm
by abrist
Great, let us know how everything went.

Re: Postfix

Posted: Tue Mar 05, 2013 10:26 am
by MPIvan
Hi guy's , here i am ... i have do like you told me gshergill. And everything went well. Im using Ubuntu Server 12.04LTS by the way ... i have in nagios template define router host template where i define "contactgroup_name emailme" and in contact.cfg i have define the contact like

define contact {
contact_name ivan
use generic-contact
alias ivanMP
email [email protected]
}

and

define contactgroup{
contactgroup_name emailme
alias mail me
members ivan
}

and i have nothing ... also i was trying to send mail like in this article and i have some problems like when i get to ehlo localhost
mail from: [email protected]
rcpt to: [email protected]
i have this error 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in local recipient table

so how do i test is it ok with postfix or sending mail or with my nagios configuration or do i missing something ... ?

or should i configure like this (null client)

Re: Postfix

Posted: Tue Mar 05, 2013 1:06 pm
by abrist
MPIvan wrote: i have this error 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in local recipient table
Below is a description from stackoverflow of the error:
The error is pretty self-descriptive: the target email username (left of the @ sign) can't be mapped to a local user on the system (default postfix settings), nor to a virtual domain (as none are configured out of the box). The decision to try and perform this mapping is controlled by the list of domains in 'mydestination' (plus any virtual domains). If this machine is in fact a domain's primary MX, then users that don't exist have broken mail. If this box only needs to send outgoing messages, simply removing the target domain from mydestination (by removing $mydomain from the list) should suffice -- it will still accept messages directly for [email protected], but messages for [email protected] will go through the MX lookup process for delivery elsewhere. You can shortcut the process by setting up a transport map (for individual domains), or for configuring a smarthost (for all mail)
Essentially, you need to create local users for each email address, or create a virtual domain and add the users there, or remove the target domain so the server just acts like an outbound relay.