Unable to send emails

Hi,
I installed and configured nagios successfully but, I am not getting any emails regarding the hosts and services. I have given my email address in contacts.cfg file i am not getting any type of mails. Apart from changing email address in contacts.cfg i did not do any thing with respect to mails and contacts. Should i add any thing else to any file.

Please help me in this issue.

thanks,
512

whats the format of your contacts.cfg? it should be look like this…

define contact{
contact_name example
alias ex
service_notification_period 24x7
host_notification_period 24x7
service_notification_options c,r
host_notification_options d,r,u
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email [email protected]
}

hi,
Thanks for your reply. I modified my contacts.cfg file as explained above but i did not get any mail alert if the hosts are down or any service is down.

Nagios isn’t a mail server in itself. By that, I mean it has been created such that you will use it to notify you of alerts using your prefered method, be that email, pager, sms and so on. Due to the phenomenal amount of different options available, the user (i.e. you) are left to configure your own external notification application and then tailor the notify commands to interact with that application. For instance, it is pretty standard that one might use sendmail as the mail server, but maybe not, so whichever mailserver you choose to use, you would then configure your notify commands to suit. Happily, the default notify commands work for sendmail, so if you can get that working you should be up and running.

HTH

/S

hi,
thanks for your concern. Where should i give my mail server ip. Which configuration file should i modify.

Thanks,
512

I don’t know. What mailserver are you trying to configure?

hi,
I just want to know where should i add the statement about configuring the mail server.

I think you got my point.
thanks,
Prakash.

OK either I’m not getting what you are asking or you are not getting what I am replying with, so I’ll break it down.

As previously posted by ‘internstudent’, your contact object definitions (often defined in v3 in contacts.cfg) specify your notification commands. If you have installed nagios by following the quickstart guides, there are default email notification definitions included, like

service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email
notify-service-by-email and notify-host-by-email are command objects (defined in v3 in commands.cfg) and may look something like this:
[blockquote]define command{
command_name notify-host-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$" | /bin/mail -s " $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}[/blockquote]
This example uses /bin/mail to send email out to your $CONTACTEMAIL$ as specified in the contact object definition via sendmail. You then need to configure sendmail (for example, or your whatever your own chosen mail server) with whatever it needs to send emails - in this case that involves editing sendmail.mc with the appropriate LOCAL_DOMAIN, SMART_HOST, MASQUERADE features etc etc (theres plenty of information for this available on the web) and then running a make command to apply the changes.

[blockquote]I just want to know where should i add the statement about configuring the mail server.[/blockquote]
So, to answer literally in terms of ‘Nagios’, the answer is nowhere - configuring your mailserver is done outside of nagios and is nothing to do with nagios. How and where you configure your mailserver depends on what your mailserver application is. If it is sendmail, then it is as I have indicated above, if it is another application, then you will need to refer to the application’s readme file. The only thing you configure in nagios is the “notify” command objects, which point to your mail server application, and again I’ve indicated how this is done above.

Hopefully this has made things a little clearer, more information can be found in the notifications section of the documentation, nagios.sourceforge.net/docs/3_0/ … tions.html

/S

hi,
Thanks for your reply.
My question is should we add this service to our host and give the check command path to commands.cfg
If your answer is yes then what are the arguments we should pass and what are the threshold values we should use.

Thanks,
512

No. If you’ve followed the quickstart guide and your services and hosts are using the generic templates then I believe that the templates reference the “admin” contact already (which is probably where you added your email address, looking at your original post), and when the host goes down or a service alert is generated through a threshold breach, an attempt will be made to notify the admin contact via email. If you check nagios.log you should see entries like

[1216969563] SERVICE NOTIFICATION: nagiosadmin;<some hostname>;PING;WARNING;notify-service-by-email;PING WARNING - Packet loss = 0%, RTA = 224.96 mswhich will confirm that the attempt to fire the notify objects is being made. If you’re seeing this and the “notify” objects in command.cfg are correct then you need to look deeper into your mailserver application’s configuration, check it’s log, etc.

Hai,
I see those type of messages in my log file but i did not define any commands for notify in my commands.cfg and all.
I am not using generic service s here. I just defined some services for my client and using them.

So i think i should modify my commands.cfg by adding some definitions for notify.

Please help in defining those.

Thanks,
512

If you are seeing those messages in the log it does imply that they are already there pre-defined somewhere. Post an example of one of your services and we can see what is happening,

Hi,
I have added a service for a host in my hosts.cfg and defined the command used there in command.cfg

but, in my nagios web interface i am getting return code of 127 out of bounds.
I think i did the mistake in defining the service in my hosts.cfg
i am posting here my email notification part of hosts.cfg

define service{
use local-service ; Name of service template to use
host_name clientbox,BSDbox
service_description host_email
check_command notify-host-by-email! Notification !
}

define service{
use local-service ; Name of service template to use
host_name clientbox,BSDbox
service_description service_email
check_command notify-service-by-email! Notification !
}

here my check_command is the same which we get by default in commands.cfg
I think there is mistake in passing the arguments. Please suggest the right option there.

Thanks,
512

Well at the moment you have configured a service check object with a notification command. Looking at that, I’m not sure you have a total grasp of what Nagios does and what the objects are that you need to configure. Briefly, you have to have at the very least your host objects, service objects, command objects, contact objects, timeperiod objects and templates, and they all fit together to monitor a server.

The host and service object defines what to server and service to check (and when), and these reference other objects directly (or indirectly through the use parameter which references a template object). For instance, the check_command in the service object will reference a pre-defined command object definition (eg PING), and (again either directly or through the ‘use’ parameter) reference a contact or contactgroup object for notifications to be sent to. Your contact object then defines what method of notification is to be used (through reference to another command object, like notify-by-sms or notify-by-email) for that contact, and a timeperiod object for which these notifications are allowed.

I think it would be best to thouroughly review the “getting started” section of the documentation at nagios.sourceforge.net/docs/3_0/toc.html and understand how all these objects fit together, and then try and work out what you want to monitor and how, then have a go and come back when you get stuck.

Hi,
Thanks for your suggestion, but I have monitored many services till now by modifying my configuration files. Forget about my previous posts. I have modified all.

These are the places i modified.
1.Gave my email address in contacts.cfg
2.gave my address in nagios.cfg in place of admin_email

Apart from this i did not do anything. All the mater i posted in my previous posts is modified and deleted.

I just want to know what are the other things should i do to get notification alerts to my mail address.

Thanks,
512

Nothing… This is how it works… In your service object you previously posted you have

use local-service

local-service is a template. it will probably have in it

use generic-service

which references the generic service template ‘generic-service’… In that you will have

contact_groups                  admins

which is a contact-group object which will have in it

members                 nagiosadmin

which references the contact object where you have put your email address
[blockquote]email [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******[/blockquote]
When your service goes down the nagios notification process goes through that chain to find your email address and try and send a mail. This process would seem to be working as you mention you can see “SERVICE NOTIFICATION: nagiosadmin;;X;Y;notify-service-by-email” type messages. That’s it. Nagios is working. You do not need to do anything else. The email has ‘left’ nagios in the manner defined in the “notify-service-by-email” notify command object. You need to fix your external mail configuration to make it work. Perhaps examine the mail logs. Perhaps try sending a test mail from the command line. Perhaps try telnetting to your relay server on port 25 to make sure it is open.

Hi,
I am sorry to say that no email came even when the host is down. Let me say the place i feel the error is in my case.

In my hosts.cfg i defined hosts, hostgroups and different services i monitor.

i defined host like this

define host{
use linux-server
host_name host1
alias host1
address ipaddress
service_notification_period 24x7
max_check_attempts 5
notification_interval 30
notification_period 24x7
notification_options d,u,r
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email [email protected]
}

here linux-server is the host group.
when i use the actual data pasted above i am getting error for all these lines

service_notification_period 24x7

notification_period 24x7

service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email [email protected]

when ever i give comments to that lines mentioned above no errors occurs while compiling and there are no emails even.

Please check this once.

thanks,
512

this generally resides in a contact object definition, not a host object.  Host objects use notification_period, but being as it's not liking 

[code]notification_period 24x7[/code]
either, then I suspect you have not defined the 24x7 timeperiod object, but without seeing the actual error I don't know.  The timeperiod is normally defined like
[code]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
        }[/code]
[code]service_notification_commands notify-by-email
host_notification_commands host-notify-by-email[/code]
These also belong in contact objects, not a host object.  As does 'email', I'm surprised it didn't complain about that too.

this generally resides in a contact object definition, not a host object. Host objects use notification_period, but being as it’s not liking

either, then I suspect you have not defined the 24x7 timeperiod object, but without seeing the actual error I don’t know. The timeperiod is normally defined like

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 }

service_notification_commands notify-by-email host_notification_commands host-notify-by-email
These also belong in contact objects, not a host object. As does ‘email’, I’m surprised it didn’t complain about that too.

hi,
Thanks for your continues reply.
In between the time i posted the previous post and your post i modified the file same as you told. But in specifying the email notificatoins i gave

service_notification_commands notify-service-by-email
host_ notification_commands notify-host-by-email

I gave notify-service-by-email and notify-host-by-email because my commands.cfg contains the commands like this only.

But when i gave like that the error is

Error: Invalid host object directive ‘service_notification_commands’.
Error: Could not add object property in file ‘/usr/local/nagios/etc/objects/localhost.cfg’ on line 35.

Here localhost.cfg is the file where i defined the hosts and services.
line 35 is the line specifying the first notification.
If i give comment to this line and compile again then the error is in 36th line, ie the line containing second notification.

Thanks,
512

my timeperiods.cfg file has the code you have written there. its location is also included in nagios cfg file