/[monit]/monit/validate.c
ViewVC logotype

Diff of /monit/validate.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.91 by martinp, Thu Sep 25 15:22:10 2003 UTC revision 1.92 by hauk, Thu Sep 25 19:27:38 2003 UTC
# Line 326  static int check_directory(Service_T s) Line 326  static int check_directory(Service_T s)
326    
327    struct stat stat_buf;    struct stat stat_buf;
328    char report[STRLEN]= {0};    char report[STRLEN]= {0};
329      static int directory_test_stat_handled= FALSE;
330      static int directory_test_type_handled= FALSE;
331    
332    if(stat(s->path, &stat_buf) != 0) {    if(stat(s->path, &stat_buf) != 0) {
333      Event_post(s, EVENT_START,      if(!directory_test_stat_handled) {
334                 "Event: directory '%s' doesn't exist\n", s->name);        Event_post(s, EVENT_START,
335                     "Event: directory '%s' doesn't exist\n", s->name);
336          directory_test_stat_handled= TRUE;
337        }
338      return FALSE;      return FALSE;
339      } else {
340        directory_test_stat_handled= FALSE;
341    }    }
342    
343    if(!S_ISDIR(stat_buf.st_mode)) {    if(!S_ISDIR(stat_buf.st_mode)) {
344      Event_post(s, EVENT_UNMONITOR,      if(!directory_test_type_handled) {
345                 "Event: '%s' is not directory\n", s->name);        Event_post(s, EVENT_UNMONITOR,
346                     "Event: '%s' is not directory\n", s->name);
347          directory_test_type_handled= TRUE;
348        }
349      return FALSE;      return FALSE;
350      } else {
351        directory_test_type_handled= FALSE;
352    }    }
353      
354    if(check_perm(s, stat_buf.st_mode, report)) {    if(check_perm(s, stat_buf.st_mode, report)) {
355      s->perm->event_flag= TRUE;      s->perm->event_flag= TRUE;
356      if(! eval_actions(s->perm->action, s, report, "permission",      if(! eval_actions(s->perm->action, s, report, "permission",
# Line 372  static int check_file(Service_T s) { Line 384  static int check_file(Service_T s) {
384    Size_T sl;    Size_T sl;
385    struct stat stat_buf;    struct stat stat_buf;
386    char report[STRLEN]= {0};    char report[STRLEN]= {0};
387      static int file_test_stat_handled= FALSE;
388      static int file_test_type_handled= FALSE;
389    
390    if(stat(s->path, &stat_buf) != 0) {    if(stat(s->path, &stat_buf) != 0) {
391      Event_post(s, EVENT_START, "Event: file '%s' doesn't exist\n", s->name);      if(! file_test_stat_handled) {
392          Event_post(s, EVENT_START, "Event: file '%s' doesn't exist\n", s->name);
393          file_test_stat_handled= TRUE;
394        }
395      return FALSE;      return FALSE;
396      } else {
397        file_test_stat_handled= FALSE;
398    }    }
399        
400    if(!S_ISREG(stat_buf.st_mode)) {    if(!S_ISREG(stat_buf.st_mode)) {
401      Event_post(s, EVENT_UNMONITOR,      if(! file_test_type_handled) {
402                 "Event: '%s' is not regular file\n", s->name);        Event_post(s, EVENT_UNMONITOR,
403                     "Event: '%s' is not regular file\n", s->name);
404          file_test_type_handled= TRUE;
405        }
406      return FALSE;      return FALSE;
407      } else {
408        file_test_type_handled= FALSE;
409    }    }
410        
411    if(check_checksum(s, report)) {    if(check_checksum(s, report)) {
# Line 412  static int check_file(Service_T s) { Line 436  static int check_file(Service_T s) {
436    
437    for(sl= s->sizelist; sl; sl= sl->next) {    for(sl= s->sizelist; sl; sl= sl->next) {
438      if(!check_size_item(s, sl, (unsigned long)stat_buf.st_size, report)) {      if(!check_size_item(s, sl, (unsigned long)stat_buf.st_size, report)) {
439        /* Turn on the object's event_flag to indicate that the size event        if(! sl->event_handled) {
440         * occured on this particular object */          /* Turn on the object's event_flag to indicate that the size event
441        sl->event_flag= TRUE;           * occured on this particular object */
442        if(! eval_actions(sl->action, s, report, "size", EVENT_SIZE)) {          sl->event_flag= TRUE;
443          return FALSE;          sl->event_handled= TRUE; /* Turn on the object's
444                                      * event_handled flag so this
445                                      * test is not handled in
446                                      * subsequent poll cycles until
447                                      * the error condition was reset.
448                                      */
449            if(! eval_actions(sl->action, s, report, "size", EVENT_SIZE)) {
450              return FALSE;
451            }
452        }        }
453        } else {
454          sl->event_handled= FALSE;
455      }      }
456    }    }
457    
# Line 435  static int check_device(Service_T s) { Line 469  static int check_device(Service_T s) {
469    Device_T td;    Device_T td;
470    struct stat stat_buf;    struct stat stat_buf;
471    char report[STRLEN]= {0};    char report[STRLEN]= {0};
472      static int device_test_stat_handled= FALSE;
473      static int device_test_read_handled= FALSE;
474    
475    if(stat(s->path, &stat_buf) != 0) {    if(stat(s->path, &stat_buf) != 0) {
476      Event_post(s, EVENT_START, "Event: device '%s' doesn't exist\n", s->name);      if(!device_test_stat_handled) {
477          Event_post(s, EVENT_START, "Event: device '%s' doesn't exist\n", s->name);
478          device_test_stat_handled= TRUE;
479        }
480      return FALSE;      return FALSE;
481      } else {
482        device_test_stat_handled= FALSE;
483    }    }
484        
485    if(check_perm(s, stat_buf.st_mode, report)) {    if(check_perm(s, stat_buf.st_mode, report)) {
# Line 461  static int check_device(Service_T s) { Line 502  static int check_device(Service_T s) {
502    }    }
503    
504    if(!DeviceInfo_Usage(s->devinfo, s->path)) {    if(!DeviceInfo_Usage(s->devinfo, s->path)) {
505      Event_post(s, EVENT_START,      if(! device_test_read_handled) {
506                 "Event: unable to read device '%s' state\n",        Event_post(s, EVENT_START,
507                 s->path);                   "Event: unable to read device '%s' state\n",
508                     s->path);
509          device_test_read_handled= TRUE;
510        }
511      return FALSE;      return FALSE;
512    } else {    } else {
513        device_test_read_handled= FALSE;
514      DEBUG("'%s' succeeded getting device statistic for %s\n", s->name, s->path);      DEBUG("'%s' succeeded getting device statistic for %s\n", s->name, s->path);
515    }    }
516    
# Line 473  static int check_device(Service_T s) { Line 518  static int check_device(Service_T s) {
518    if(s->devicelist) {    if(s->devicelist) {
519      for(td= s->devicelist; td; td= td->next) {      for(td= s->devicelist; td; td= td->next) {
520        if(!check_device_resources(s, td, report)) {        if(!check_device_resources(s, td, report)) {
521          if (! eval_actions(td->action, s, report, "device",          if(! td->event_handled) {
522                             EVENT_RESOURCE)) {            td->event_flag= TRUE; /* Turn on the object's event_flag
523            return FALSE;                                   * to indicate that the resource
524          }                                   * event occured on this particular
525                                     * object */
526              td->event_handled= TRUE; /* Turn on the object's
527                                        * event_handled flag so this
528                                        * test is not handled in
529                                        * subsequent poll cycles until
530                                        * the error condition was reset.
531                                        */
532    
533              if(! eval_actions(td->action, s, report, "device", EVENT_RESOURCE)) {
534                return FALSE;
535              }
536            }
537          } else {
538            td->event_handled= FALSE;
539        }        }
540      }      }
541        
542    }    }
543        
544    return TRUE;    return TRUE;
# Line 493  static int check_device(Service_T s) { Line 553  static int check_device(Service_T s) {
553   */   */
554  static int check_remote_host(Service_T s) {  static int check_remote_host(Service_T s) {
555    
   Icmp_T icmp;  
556    Port_T pp;    Port_T pp;
557      Icmp_T icmp;
558    char report[STRLEN]={0};    char report[STRLEN]={0};
559    
560    /* Test each host:port and protocol in the service's portlist */    /* Test each host:port and protocol in the service's portlist */
561    for(pp= s->portlist; pp; pp= pp->next) {    for(pp= s->portlist; pp; pp= pp->next) {
562      if(!check_process_connection(s, pp, report)) {      if(!check_process_connection(s, pp, report)) {
563        pp->is_available= FALSE;        pp->is_available= FALSE;
564        pp->event_flag= TRUE; /* Turn on the object's event_flag to        if(! pp->event_handled) {
565                               * indicate that the port event          pp->event_flag= TRUE;
566                               * occured on this particular          pp->event_handled= TRUE;
567                               * object */          if(! eval_actions(pp->action, s, report, "connection",
568        if(! eval_actions(pp->action, s, report, "connection",                            EVENT_CONNECTION)) {
569                          EVENT_CONNECTION)) {            return FALSE;
570          return FALSE;          }
571        }        }
572      } else {      } else {
573        pp->is_available= TRUE;        pp->is_available= TRUE;
574          pp->event_handled= FALSE;
575      }      }
576    }    }
577    
# Line 518  static int check_remote_host(Service_T s Line 579  static int check_remote_host(Service_T s
579    for(icmp= s->icmplist; icmp; icmp= icmp->next) {    for(icmp= s->icmplist; icmp; icmp= icmp->next) {
580      if(!check_icmp_connection(s, icmp, report)) {      if(!check_icmp_connection(s, icmp, report)) {
581        icmp->is_available= FALSE;        icmp->is_available= FALSE;
582        icmp->event_flag= TRUE;        if(! icmp->event_handled) {
583        if(! eval_actions(icmp->action, s, report, "icmp",          icmp->event_handled= TRUE;
584                          EVENT_CONNECTION)) {          icmp->event_flag= TRUE;
585          return FALSE;          if(! eval_actions(icmp->action, s, report, "icmp",
586                              EVENT_CONNECTION)) {
587              return FALSE;
588            }
589        }        }
590      } else {      } else {
591        icmp->is_available= TRUE;        icmp->is_available= TRUE;
592          icmp->event_handled= FALSE;
593      }      }
594    }    }
595    
# Line 539  static int check_remote_host(Service_T s Line 604  static int check_remote_host(Service_T s
604   */   */
605  static int check_process(Service_T s, ProcessTree_T * pt, int treesize) {  static int check_process(Service_T s, ProcessTree_T * pt, int treesize) {
606    
   Port_T pp;  
   Resource_T pr;  
607    pid_t  pid= -1;    pid_t  pid= -1;
608      Port_T pp= NULL;
609      Resource_T pr= NULL;
610    char report[STRLEN]={0};    char report[STRLEN]={0};
611        
612    /* Test for running process */    /* Test for running process */
# Line 566  static int check_process(Service_T s, Pr Line 631  static int check_process(Service_T s, Pr
631        for(pr= s->resourcelist; pr; pr= pr->next) {        for(pr= s->resourcelist; pr; pr= pr->next) {
632          if(!check_process_resources(s, pr, report)) {          if(!check_process_resources(s, pr, report)) {
633            pr->cycle=0;            pr->cycle=0;
634            pr->event_flag= TRUE; /* Turn on the object's event_flag to            if(! pr->event_handled) {
635                                   * indicate that the resource event              pr->event_flag= TRUE;
636                                   * occured on this particular              pr->event_handled= TRUE;
637                                   * object */              if(! eval_actions(pr->action, s, report, "resource",
638            if(! eval_actions(pr->action, s, report, "resource",                                EVENT_RESOURCE)) {
639                              EVENT_RESOURCE)) {                reset_resource_counter(s);
640              reset_resource_counter(s);                return FALSE;
641              return FALSE;              }
642            }            }
643            } else {
644              pr->event_handled= FALSE;
645          }          }
646        }        }
647      } else {      } else {
648        log("'%s' failed to get service data\n", s->name);        log("'%s' failed to get service data\n", s->name);
649      }      }
650    }    }
651      
652    /* Test each host:port and protocol in the service's portlist */    /* Test each host:port and protocol in the service's portlist */
653    for(pp= s->portlist; pp; pp= pp->next) {    for(pp= s->portlist; pp; pp= pp->next) {
654      if(!check_process_connection(s, pp, report)) {      if(!check_process_connection(s, pp, report)) {
655        pp->event_flag= TRUE; /* Turn on the object's event_flag to        if(! pp->event_handled) {
656                               * indicate that the port event          pp->event_flag= TRUE;
657                               * occured on this particular          pp->event_handled= TRUE;
658                               * object */          if(! eval_actions(pp->action, s, report, "connection",
659        if(! eval_actions(pp->action, s, report, "connection",                            EVENT_CONNECTION)) {
660                          EVENT_CONNECTION)) {            return FALSE;
661          return FALSE;          }
662        }        }
663        } else {
664          pp->event_handled= FALSE;
665      }      }
666    }    }
667        
# Line 1076  static int check_timestamp_item(Service_ Line 1145  static int check_timestamp_item(Service_
1145      }      }
1146    } else {    } else {
1147      if(compare_value(t->operator, (int)(now - timestamp), t->time)) {      if(compare_value(t->operator, (int)(now - timestamp), t->time)) {
1148        snprintf(report, STRLEN, "timestamp test failed for %s", s->path);        if(! t->event_handled) {
1149        return FALSE;          snprintf(report, STRLEN, "timestamp test failed for %s", s->path);
1150            t->event_handled= TRUE;
1151            return FALSE;
1152          }
1153        } else {
1154          t->event_handled= FALSE;
1155      }      }
1156    }    }
1157    

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.92

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26