Score:0

Nagios check_procs not reporting processes not spawned by root

ph flag

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
}
tbielaszewski avatar
ng flag
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`
Jim Miller avatar
ph flag
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.
Score:0
ph flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.