Add email for every host

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
pianunix
Posts: 51
Joined: Tue Jul 22, 2014 3:08 am

Add email for every host

Post by pianunix »

Hi,

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

Thanks.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Add email for every host

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
pianunix
Posts: 51
Joined: Tue Jul 22, 2014 3:08 am

Re: Add email for every host

Post by pianunix »

I see thanks for your information.
pianunix
Posts: 51
Joined: Tue Jul 22, 2014 3:08 am

Re: Add email for every host

Post by pianunix »

Still wont work.

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

Thanks.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Add email for every host

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
pianunix
Posts: 51
Joined: Tue Jul 22, 2014 3:08 am

Re: Add email for every host

Post 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]
}
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Add email for every host

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
pianunix
Posts: 51
Joined: Tue Jul 22, 2014 3:08 am

Re: Add email for every host

Post by pianunix »

I see, well thanks for everything.
:D
Locked