/** * 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(); }
void process_testmatch(char *pattern) { #ifdef HAVE_REGEX_H regex_t *regex_comp; int reg_return; #endif #ifdef HAVE_REGEX_H NEW(regex_comp); if ((reg_return = regcomp(regex_comp, pattern, REG_NOSUB|REG_EXTENDED))) { char errbuf[STRLEN]; regerror(reg_return, regex_comp, errbuf, STRLEN); regfree(regex_comp); FREE(regex_comp); printf("Regex %s parsing error: %s\n", pattern, errbuf); exit(1); } #endif initprocesstree(&ptree, &ptreesize, &oldptree, &oldptreesize); if (Run.doprocess) { int i, count = 0; printf("List of processes matching pattern \"%s\":\n", pattern); printf("------------------------------------------\n"); for (i = 0; i < ptreesize; i++) { int match = FALSE; if (ptree[i].cmdline && ! strstr(ptree[i].cmdline, "procmatch")) { #ifdef HAVE_REGEX_H match = regexec(regex_comp, ptree[i].cmdline, 0, NULL, 0) ? FALSE : TRUE; #else match = strstr(ptree[i].cmdline, pattern) ? TRUE : FALSE; #endif if (match) { printf("\t%s\n", ptree[i].cmdline); count++; } } } printf("------------------------------------------\n"); printf("Total matches: %d\n", count); if (count > 1) printf("WARNING: multiple processes matched the pattern. The check is FIRST-MATCH based, please refine the pattern\n"); } }
/** * 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; }