Page 1 of 1

Add email for every host

Posted: Wed Aug 13, 2014 4:23 am
by pianunix
Hi,

Can we add a diferrent contact email on alert server for every host ?

Thanks.

Re: Add email for every host

Posted: Wed Aug 13, 2014 9:13 am
by eloyd
Yes. You need to create a different contact for each email and then assign that contact to the host notifications.

Advanced topic, but easier: If the hostname is part of the email address you're sending to, you could use the $HOSTNAME$ macro as part of the email address you're mailing to in your commands.cfg config file.

Re: Add email for every host

Posted: Wed Aug 13, 2014 10:33 pm
by pianunix
I see thanks for your information.

Re: Add email for every host

Posted: Thu Aug 14, 2014 3:56 am
by pianunix
Still wont work.

Can you give us example code for assign email to another host ?

Thanks.

Re: Add email for every host

Posted: Thu Aug 14, 2014 9:06 am
by eloyd
In hosts.cfg (or wherever you're defining your hosts):

Code: Select all

define host{
        use             some_template
        host_name       my.favorite.hostname
        address         10.1.1.1
        contact_groups          group_1
}
define host{
        use             some_template
        host_name       my.other.hostname
        address         10.1.1.2
        contact_groups          group_2
}
Note that I'm using contact_groups here, and specifying different groups. You could just as easily use "contacts" instead and list individual contacts.

Now, in "contacts.cfg" (or wherever you store your contact information):

Code: Select all

define contact{
        contact_name            contact1
        use                     some_template
        email                   [email protected]
}
define contact{
        contact_name            contact2
        use                     some_template
        email                   [email protected]
}

define contactgroup{
        contactgroup_name       group_1
        alias                   support team plus admins
        members                 contact1, contact2
}
define contactgroup{
        contactgroup_name       group_2
        alias                   just support team
        members                 contact1
}
I've complicated things a bit with the groups, but I thought you might like to see that you can group contacts into multiple groups and then make notifications use the groups instead of the contacts. That way, if someone moves around from one group to another, you just change their group assignment instead of all the locations that they are listed as a notification recipient.

Re: Add email for every host

Posted: Thu Aug 14, 2014 10:43 pm
by pianunix
Can we just give like this for example in host.cfg ?

Code: Select all

define host{
        use             some_template
        host_name       my.favorite.hostname
        address         10.1.1.1
        contacts          [email protected]
}

Re: Add email for every host

Posted: Fri Aug 15, 2014 2:08 am
by Box293
pianunix wrote:Can we just give like this for example in host.cfg ?
No, this is not how Nagios works. An email address needs to be defined in a contact and the host config references the contact OR the contact group the contact is a member of.

The email address is just one of the many settings a contact can have, others can be notification interval, what it receives notifications on, etc etc etc. The point being is that Nagios is designed this way to be very flexible.

Re: Add email for every host

Posted: Fri Aug 15, 2014 3:40 am
by pianunix
I see, well thanks for everything.
:D