Check process with if exist does not contain some data

Issue #790 resolved
Lutz Mader created an issue

Hello, I missed some data in the environment variables in the "if exist" check (I use monit 5.25.2).

check process sleep matching "sleep"
  if exist then exec "/usr/local/etc/monit/scripts/env.sh"
    else if succeeded then exec "/usr/local/etc/monit/scripts/env.sh"

The "monit status" show the right data.

Process 'sleep'
  status                       Does exist
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  pid                          44445
  parent pid                   1
  uid                          504
  effective uid                504
  gid                          20
  uptime                       0m
  threads                      1
  children                     0
  cpu                          0.0%
  cpu total                    0.0%
  memory                       0.0% [520 kB]
  memory total                 0.0% [520 kB]
  data collected               Sat, 27 Oct 2018 21:22:59

I got the following variables for "does exist". Unfortunately some of the values does not contain some usefull data, but the description contain the pid value.

MONIT_HOST=MacBookPro.local
MONIT_PROCESS_PID=-1
MONIT_EVENT=Does exist
MONIT_PROCESS_MEMORY=0
MONIT_PROCESS_CPU_PERCENT=-1.0
MONIT_SERVICE=sleep
MONIT_PROCESS_CHILDREN=-1
MONIT_DESCRIPTION=process is running with pid 44445
MONIT_DATE=Sat, 27 Oct 2018 21:22:59

The "exists not" seems to fit, but contain to much values compared to "does not exist".

MONIT_HOST=MacBookPro.local
MONIT_PROCESS_PID=-1
MONIT_EVENT=Exists not
MONIT_PROCESS_MEMORY=0
MONIT_PROCESS_CPU_PERCENT=-1.0
MONIT_SERVICE=sleep
MONIT_PROCESS_CHILDREN=-1
MONIT_DESCRIPTION=process is not running
MONIT_DATE=Sat, 27 Oct 2018 21:24:59

Someone should have a look to "check process" handling, I think.

With regards, Lutz

Comments (2)

  1. Lutz Mader reporter

    Thanks for the fix. I add the changes to monit 5.25.2 to do some testing.

    If the process is running, I get proper env varibales now.

    #!
    
    MONIT_DATE=Wed, 30 Jan 2019 22:08:30
    MONIT_DESCRIPTION=process is running with pid 10369
    MONIT_EVENT=Does exist
    MONIT_HOST=MacBookPro.local
    MONIT_PROCESS_CHILDREN=0
    MONIT_PROCESS_CPU_PERCENT=0.0
    MONIT_PROCESS_MEMORY=520
    MONIT_PROCESS_PID=10369
    MONIT_SERVICE=sleep
    

    And if the process is not available I got.

    #!
    
    MONIT_DATE=Wed, 30 Jan 2019 22:10:30
    MONIT_DESCRIPTION=process is not running
    MONIT_EVENT=Exists not
    MONIT_HOST=MacBookPro.local
    MONIT_PROCESS_MEMORY=0
    MONIT_SERVICE=sleep
    

    The env variable "MONIT_PROCESS_MEMORY" is not usefully for a not running process, but the env values content is proper now.

    "monit status" show the right data, if the process is running.

    #!
    
    Process 'sleep'
      status                       Does exist
      monitoring status            Monitored
      monitoring mode              active
      on reboot                    start
      pid                          10369
      parent pid                   9951
      uid                          504
      effective uid                504
      gid                          20
      uptime                       0m
      threads                      1
      children                     0
      cpu                          0.0%
      cpu total                    0.0%
      memory                       0.0% [520 kB]
      memory total                 0.0% [520 kB]
      data collected               Wed, 30 Jan 2019 22:08:30
    

    Or not running.

    #!
    
    Process 'sleep'
      status                       OK
      monitoring status            Monitored
      monitoring mode              active
      on reboot                    start
      pid                          -
      parent pid                   -
      uid                          -
      effective uid                -
      gid                          -
      uptime                       -
      threads                      -
      children                     -
      cpu                          -
      cpu total                    -
      memory                       -
      memory total                 -
      data collected               Wed, 30 Jan 2019 22:14:30
    

    Nice to see, thanks for all help, Lutz

  2. Log in to comment