示例#1
0
文件: validate.c 项目: KISSMonX/monit
/**
 * Validate a given process service s. Events are posted according to 
 * its configuration. In case of a fatal event FALSE is returned.
 */
int check_process(Service_T s) {

  pid_t  pid = -1;
  Port_T pp = NULL;
  Resource_T pr = NULL;

  ASSERT(s);

  /* Test for running process */
  if (!(pid = Util_isProcessRunning(s, FALSE))) {
    Event_post(s, Event_Nonexist, STATE_FAILED, s->action_NONEXIST, "process is not running");
    return FALSE;
  } else
    Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "process is running with pid %d", (int)pid);

  if (Run.doprocess) {
    if (update_process_data(s, ptree, ptreesize, pid)) {
      check_process_state(s);
      check_process_pid(s);
      check_process_ppid(s);
      for (pr = s->resourcelist; pr; pr = pr->next)
        check_process_resources(s, pr);
    } else
      LogError("'%s' failed to get service data\n", s->name);
  }

  /* Test each host:port and protocol in the service's portlist */
  if (s->portlist)
    for (pp = s->portlist; pp; pp = pp->next)
      check_connection(s, pp);

  return TRUE;
  
}
示例#2
0
文件: validate.c 项目: KISSMonX/monit
/**
 * Validate the general system indicators. In case of a fatal event
 * FALSE is returned.
 */
int check_system(Service_T s) {
  Resource_T r = NULL;

  ASSERT(s);

  for (r = s->resourcelist; r; r = r->next) {
    check_process_resources(s, r);
  }

  return TRUE;
}
示例#3
0
/**
 * Validate a given process service s. Events are posted according to 
 * its configuration. In case of a fatal event FALSE is returned.
 */
int check_process(Service_T s) {

  pid_t  pid= -1;
  Port_T pp= NULL;
  Resource_T pr= NULL;
  char report[STRLEN]={0};
  
  /* Test for running process */
  if(!(pid= is_process_running(s))) {
    /* Reset the proc info object to prevent false data in the first run */
    memset(s->procinfo, 0, sizeof *(s->procinfo));
    Event_post(s, EVENT_START, "Event: Process '%s' is not running.\n",
	       s->name);
    return FALSE;
  } else {
    DEBUG("'%s' is running with pid %d\n", s->name, (int)pid);
  }

  if(Run.doprocess) {
    if(update_process_data(s, ptree, ptreesize, pid)) {
      if(! check_process_state(s, report)) {
	Event_post(s, EVENT_RESOURCE, "Event: %s\n", report);
      } else {
	DEBUG("'%s' check_process_state() passed.\n", s->name);
      }
      
      for(pr= s->resourcelist; pr; pr= pr->next) {
	if(!check_process_resources(s, pr, report)) {
	  pr->cycle=0;
	  if(! pr->event_handled) {
	    pr->event_flag= TRUE;
	    pr->event_handled= TRUE;
	    if(! eval_actions(pr->action, s, report, "resource",
			      EVENT_RESOURCE)) {
	      reset_resource_counter(s);
	      return FALSE;
	    }
	  }
	} else {
	  pr->event_handled= FALSE;
	}
      }
    } else {
      log("'%s' failed to get service data\n", s->name);
    }
  }

  /* Test each host:port and protocol in the service's portlist */
  for(pp= s->portlist; pp; pp= pp->next) {
    if(!check_process_connection(s, pp, report)) {
      if(! pp->event_handled) {
	pp->event_flag= TRUE;
	pp->event_handled= TRUE;
	if(! eval_actions(pp->action, s, report, "connection",
			  EVENT_CONNECTION)) {
	  return FALSE;
	}
      }
    } else {
      pp->event_handled= FALSE;
    }
  }
  
  return TRUE;
  
}