Beginner
Beginner

Reputation: 2886

Custom plugin check icinga2

I am a beginner in icinga and nagios usage for server management. I setup icinga on a machine and set up all the basics. The next step I tried was to check if certain services were running at ports 8080, 8081 and 8082 or not. I wrote a quick python script for that. I placed that file under /usr/local/lib/myscript.py. The next step I did was to create a command under /etc/nagios-plugins/config/testone.cfg . My command looks like this

define command{
        command_name    check_restarts
        command_line    python /usr/local/lib/myscript.py -w 3 -c 5 -p 8080
        command_line    python /usr/local/lib/myscript.py -w 3 -c 5 -p 8081
        command_line    python /usr/local/lib/myscript.py -w 3 -c 5 -p 8082
        }

I then added a service to services.conf under /etc/icinga2/conf.d/services.conf. But this leads to an error when I restart icinga which shows up a message Backend icinga not running on the UI and errors point to services.conf when I try sudo service icings2 status.

Can anyone please guid me around these steps?

Upvotes: 0

Views: 6061

Answers (1)

letsc
letsc

Reputation: 2567

The easiest way to do this is as follows:

Once you have nagios installed go to /etc/nagios/nrpe.d/commands.conf (if you dont have a commands.conf create it ). In that file place this

command[check_process] = /usr/bin/python /path/to/your/script

Here check_process can be any name you wish to keep.

Once this is in place, check it using the check_nrpe plugin. Its places in /usr/lib/nagios/../check_nrpe (dont fully remember the location)

type this in your terminal: path/to/check_nrpe -H localhost -c check_process

Considering this is localhost i.e. your running the script on the same system i dont see any issues cropping up.

Next go the /etc/icinga/conf.d/mychecks.conf (again create this file, preferably create a new folder and place it in there). This should be the content of your file:

apply Service "My service" {
    import "generic-service"
    check_command = "check_process"

    assign where host.name == NodeName
}

you can check for any issues using sudo /etc/init.d/icinga2 checkconfig . ANy issues are usually very descriptive and helpfull. If the checkconfig is [ok] then restart icinga and you're set.

Upvotes: 1

Related Questions