Centreon – Enabling email alerts

This will be the document that we must follow if we want to enable Nagios and Centreon alerts through the use of email and thus receive the alerts in our monitoring system, when a host or service changes status to Warning, Critical, and so on.

 

Enabling notifications from Centreon,

The first thing will be to define a user to whom we want the alerts to be sent, later we will touch on a base service template, so that everything we work on has notifications enabled and this specific user; and we don't have to set it up every time we create a new service.

And then finally, we will modify Postfix to use our organization's mail server to do mail relay!

 

 

The first thing will be to create a user that we want to receive the alerts, In this simple example, I will have one user receive the alerts from the entire platform. As we can imagine, We will be able to customize what type and to whom we want certain alerts to be delivered. We're going to “Configuration” > “Users” > “Contact Users”, there we must register a user where we will at least fill in the following fields:

  • Alias / Login: It will be the login you will use if we also want to give you access to Centreon.
  • Full Name: Full name.
  • Email: Email address where we want the alerts to reach you.
  • Enable Notifications: Yes. We must enable notifications.
  • Host Notification Options: We select the type of alerts we want to receive related to the hosts, we will usually dial Warning, Unknown and Recovery.
  • Host Notification Period: The Host Alert Notification Period, Default 24×7.
  • Host Notification Commands: We leave 'service-notify-by-email'.
  • Service Notification Options: We select the type of alerts we want to receive related to the services, we will usually dial Warning, Unknown, Critical and Recovery.
  • Service Notification Period: The Service Alert Notification Period, Default 24×7.
  • Service Notification Commands: We leave 'service-notify-by-email'.

 

GOOD, before creating any service, if, for example, we want to do what we said, that all services we create from now on are notified to you, we will be able to edit a service template that Centreon brings. From this template, Then we will create the services that monitor the items that interest us. These base templates may already have a basic configuration that is as said, Notification is enabled, to this user, etc… We can create a template by duplicating an existing one if we want, In this case I will edit the template 'generic-active-service-custom’ that we will find in “Configuration” > “Services” > “Templates”. In other documents you will see that all the services I will create, They start from this template!

 

If we are once within the service template, we'll see that it has a “Notification”, We'll go there to set up everything we need, In this example it would be as follows:

  • Notification Enabled: Yes.
  • Implied Contacts: We add the newly created user.
  • Notification Period: 24×7
  • Notification Type: We leave all the options that interest us marked, Usually Warning, Unknown, Critical and Recovery.

 

And nothing, if in the Postfix configuration file '/etc/postfix/main.cf’ Add a line indicating which server will act as a relay, it will be enough for the email to go out now. Of course, we must allow the mail server that we are going to send mail without authentication or well, How we set it up.

[SourceCode]relayhost = [FQDN_SERVIDOR_DE_CORREO][/SourceCode]

 

And then, With the following command we can try to send a test email from the shell itself:

[SourceCode]echo "This is a test of sending mail" | mail -s "Mail Test"" di*****************@do*****.eso[/SourceCode]

 

Sending mail using Gmail,

A good option, will not be to use our mail server to send emails, lest if our mail server goes down we will be left without alerts… what better than using an external messaging service like Gmail. Like underneath, Our Nagios uses Postfix, we will configure this service to use the Gmail server as a relay.

 

Simply edit the Postfix configuration file, added configuration lines against Gmail mail server:

[SourceCode]vim /etc/postfix/main.cf

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes[/SourceCode]

 

We now create the authentication file:

[SourceCode]vim /etc/postfix/sasl_passwd

[smtp.gmail.com]:587 US*****@gm***.cOm:PASSWORD[/SourceCode]

 

As the above information is sensitive, we will protect this file, we apply the corresponding permissions so that only we can see it:

[SourceCode]sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd[/SourceCode]

 

Also, We need a certificate, We can get it from any one we have in the certificate directory, Running:

[SourceCode]cat /etc/ssl/certs/ca-bundle.crt | sudo tee -a /etc/postfix/cacert.pem[/SourceCode]

 

 

And finally, we will have to allow Gmail to let us send emails, we must enter both links with our Gmail account to allow less secure applications:

https://www.google.com/settings/security/lesssecureapps

https://accounts.google.com/DisplayUnlockCaptcha

 

Once all of the above has been done, we can restart Postfix to load the new data and run a test of sending mail from the shell with the following command. If we have problems, Remember that in '/var/log/maillog’ you have the Postfix logs.

[SourceCode]sudo /etc/init.d/postfix reload

echo "This is a test of sending mail" | mail -s "Mail Test"" di*****************@do*****.eso[/SourceCode]

 

And with this, at least the alerts of the services by email would be configured, When a service changes status, it will send it to us! We will go into more detail about types of alerts, etc… in other documents!

 

Recommended Posts

Author

nheobug@bujarra.com
Autor del blog Bujarra.com Cualquier necesidad que tengas, Do not hesitate to contact me, I will try to help you whenever I can, Sharing is living ;) . Enjoy documents!!!

Nagios - Monitorizando Windows

30 of March of 2017