
Setting up corrective actions in Centreon
Another of the great advantages of having our monitored platform is that we can take advantage of and generate our own scripts to carry out corrective actions in our environment. Something that runs on the remote machine when we have a problem, for example if we run out of disk space, Well, a script that releases temporary, or the example that we will make in this document; when Nagios or Centreon detects that we have DNS Service from the DNS Server down, Well, let him start 🙂 it Ideal for any need we have, repetitive problems that we can automate their solution…
For this, we will use the Event Handlers or event triggers that we can easily configure in each Centreon Host or Service, every time the monitored service changes state, will execute the Command we define. As I tell you, in this document I'll use an already defined service in Centreon that monitors the Windows service's DNS server’ whether it is active or not; If you want information on how to monitor services here. Well, apart from checking it, what we will do is configure that when the Service sings as CRITICAL then it executes a .BAT file on the DNS server so that it lifts said service, Yes?
For Remote Script Execution, if you are following this series of documents about Nagios, I'm using NRPE, therefore, the NSClient++ agent will be installed and configured on the DNS server, If you need to go over it, you got it here.
What we would have to have, for example, is a batch file that in this case will restart the DNS service, the 'reinicia_servicios_dns.cmd’ I leave it as usual in the Scripts folder and its contents in this example will be:
[SourceCode]net stop "DNS server""
net start "DNS Server"[/SourceCode]
And as always, in the NSClient++ configuration file 'nsclient.ini', we will register both the Alias and what it should execute when that Alias is called from a remote machine, as it will be from our Nagios or Centreon, something like that we should add:
[SourceCode][/settings/external scripts/scripts]
reinicia_dns = cmd /c scripts\reinicia_dns.cmd
[/settings/external scripts/alias]
reinicia_dns = reinicia_dns[/SourceCode]
As usual, save the file and restart the NSClient++ Service to take effect.
And nothing, now we only have to go to the Service to which we want to add the corrective action, in this case I remind you that it was the service that monitored whether the DNS Service is active or not; therefore, When your status changes, We will proceed to run a script that will restart this service in order to tackle and try to correct a possible important failure in my organization. From Centreon, we seek our Service from “Configuration” > “Services”, and we edit it, from the “Data Processing”, enable 'Event Handler Enabled', in this case we will select the Command 'check_nrpe’ that will run as an 'Event Handler', and if we have to pass arguments we will do it separately from a ! (exclamation), In my case we know that if we pass the argument '!reinicia_dns’ which was the alias of the INI, 'Cause we'll get what we want, that runs that script remotely! We record with “Save” and as always we export the data and restart the Nagios or Centreon engine to reload the configuration, Well, I hope it was interesting to you!