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.
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