0

I am trying to set up Nagios to monitor the nginx service on my load balancer but have been unsuccessful in getting it to show the service being up. The command and service definition are below. It seems that any process that is not spawned by root will not show as running. The nginx process is being run by www-data. I even tried something as simple as having it check for the "top" process I was running under a different user. What I have presented below works fine as long as I pick a process being run by root. If the process is spawned by any other user it shows as critical and does not work. Any thoughts?

    define command {
        command_name    check_nginx
        command_line    $USER1$/check_procs -c 1: -C nginx
}


define service {
   use                  local-service
   host_name            my_host
   service_description  Load Balance Service
   check_command        check_nginx
}
2
  • thoughts: 1. something weird is going on with OS as check_procs just reads info from /proc, so maybe some container or security mechanism limits what you can see. 2. play around with ` -u, --user=USER` option and maybe ` -g, --cgroup-hierarchy` Sep 15, 2021 at 10:49
  • I actually did try the user option but had no luck. I ended up going a different route and wrote a python plugin/script to accomplish it. Details will be below.
    – Jim Miller
    Sep 15, 2021 at 14:39

1 Answer 1

0

After trying all of the different options included with the check_proc plugin and not getting anywhere I decided to go a different route. I created the following python script and included it in the plugins directory. The python script name is check_service.py. If you name it something else you will have to modify the services and commands below accordingly.

   import os

status = os.system('systemctl is-active --quiet nginx')
if status == 768:
  print('Critical, Service is not running')
  exit(2)
elif status == 0:
 print('OK, Service is Running')
 exit(0)

I then added the following command to the commands.cfg file. The $ARG1$ is there for a future version of the script I am working on. It is not required.

define command{
    command_name    check_service
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_service $ARG1$
    }

Defined the service like this

define service {
    use                             local-service
    host_name                       debian
    service_description             Load Balance Service
    check_command                   check_service
    }

Then on the client I added this command to the nrpe.cfg file

command[check_service]=python3 /usr/lib/nagios/plugins/check_service.py

Hope this helps someone somewhere down the road.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .