Nagios Notifications

Hello all -
I have a question regarding nagios notifications. At this point, I have everything working with nagios that I want to so far and want to start sending notifications via e-mail. I am new to nagios as well as Linux system admin so please don’t shun me if I ask a newbie sort of question. If so, just point me in the right direction.

Ok here goes. . . I am getting the notifications using the default mail command script for hosts and services. Those notifications are going to the “nagios-admin” user on the localhost. Here is the snippet of minimal.cfg file that I am using that defines the contact_groups, host-groups, e-mail address etc…

###############################################################################

TIME PERIODS

###############################################################################
###############################################################################

This defines a timeperiod where all times are valid for checks,

notifications, etc. The classic “24x7” support nightmare. :frowning:

define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}

###############################################################################
###############################################################################

COMMANDS

###############################################################################
###############################################################################

This is a sample service notification command that can be used to send email

notifications (about service alerts) to contacts.

define command{
command_name notify-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$OUTPUT$" | /bin/mail -s " $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

This is a sample host notification command that can be used to send email

notifications (about host alerts) to contacts.

define command{
command_name host-notify-by-email
command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $OUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /bin/mail -s “Host $HOSTSTATE$ alert for $HOSTNAME$!” $CONTACTEMAIL$
}

###############################################################################
###############################################################################

CONTACTS

###############################################################################
###############################################################################

In this simple config file, a single contact will receive all alerts.

This assumes that you have an account (or email alias) called

“nagios-admin” on the local host.

define contact{
contact_name nagios
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email nagios-admin@localhost
}

###############################################################################
###############################################################################

CONTACT GROUPS

###############################################################################
###############################################################################

We only have one contact in this simple configuration file, so there is

no need to create more than one contact group.

define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios-admin
}

###############################################################################
###############################################################################

HOST GROUPS

###############################################################################
###############################################################################

We only have one host in our simple config file, so there is no need to

create more than one hostgroup.

define hostgroup{
hostgroup_name test
alias Test Servers
members nagios-admin
}


Anyway, with that configution, I am getting mail to the nagios-admin on the localhost.

I want to be able to get mail to an external e-mail address so I’ve made some simple changes to the configuration file that I’ve posted using that e-mail address. I don’t get anything.

So, I’ve tried to e-mail my external address using the following command.

printf “%b” “Testing” | mail -s “Testing” [email protected]

I received the mail message.

I tried this as the root user as well as the nagios user and it worked both ways.

My question is, if this command works from the command line, and I can get the mail to my external address using that command, why am I not getting the notifications to this address when I switch the e-mail address in the minimal.cfg file?

It seems that there is a problem with the config file.

Please advise. All suggestions are greatly appreciated. : )

Ty

First off, reverse those changes you made. You didn’t have to change anything.
All you need to add is another contact. Make it just like the nagios-admin contact. 24x7 all that. But the new contact is going to be you and your real email addy. That’s it.
Oh, and of course, you will have to be a member of the contactgroup that is defined as getting notifications.

The other thing is, why do you have a host named “nagios-admin”

In case you missed it, read the docs again. The hostgroups.cfg file contains definitions of hosts that belong to a group, not contacts.
So, in other words:
define hostgroup{
hostgroup_name test
alias Test Servers
members somehost # not some contact liike nagios-admin
}

The contactgroup you made is fine, but you left out an important detail, and that is your services.cfg.
in services.cfg you must define who is going to be contacted. So add a contact_groups like nagios-admin

Thanks jakkedup, I am now getting external e-mail notifications. And like I said in my earlier post, I am new to Linux Administration and certainly new to Nagios. I am greatly appreciative of your assistance and hope that in the future you will continue to be patient with newbies like myself who have read the docs over and over and still get confused. I think that’s common in Linux Administration. Any Open Source software for that matter.

Again, thanks for your assistance. : )