Esempio n. 1
0
/**
 *  This function contains the main check machinery for  monit. The
 *  validate function check services in the service list to see if
 *  they will pass all defined tests.
 */
void validate() {

  Service_T s;
  sigset_t ns, os;

  if(! update_loadavg())
    log("Update of loadavg has failed!\n");

  if(Run.doprocess)
    initprocesstree();

  for(s= servicelist; s; s= s->next) {
    if(s->visited)
      continue;
    LOCK(s->mutex)
      set_signal_block(&ns, &os);
      if(s->do_monitor && !check_skip(s) && !check_timeout(s))
        s->check(s);
      unset_signal_block(&os);
    END_LOCK;
  }

  if(Run.doprocess)
    delprocesstree();

  reset_depend();

}
Esempio n. 2
0
/**
 *  This function contains the main check machinery for  monit. The
 *  validate function check services in the service list to see if
 *  they will pass all defined tests.
 */
int validate() {
  int errors = 0;
  Service_T s;

  Run.handler_flag = HANDLER_SUCCEEDED;
  Event_queue_process();

  initprocesstree(&ptree, &ptreesize, &oldptree, &oldptreesize);
  gettimeofday(&systeminfo.collected, NULL);

  /* In the case that at least one action is pending, perform quick
   * loop to handle the actions ASAP */
  if (Run.doaction) {
    Run.doaction = 0;
    for (s = servicelist; s; s = s->next)
      do_scheduled_action(s);
  }

  /* Check the services */
  for (s = servicelist; s && !Run.stopped; s = s->next) {
    if (! do_scheduled_action(s) && s->monitor && ! check_skip(s)) {
      check_timeout(s); // Can disable monitoring => need to check s->monitor again
      if (s->monitor) {
        if (! s->check(s))
          errors++;
        /* The monitoring may be disabled by some matching rule in s->check
         * so we have to check again before setting to MONITOR_YES */
        if (s->monitor != MONITOR_NOT)
          s->monitor = MONITOR_YES;
      }
    }
    gettimeofday(&s->collected, NULL);
  }

  reset_depend();

  return errors;
}