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

Diff of /monit/util.c

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

revision 1.162 by martinp, Thu Sep 1 01:10:27 2005 UTC revision 1.163 by martinp, Mon Sep 5 09:51:37 2005 UTC
# Line 608  void Util_printService(Service_T s) { Line 608  void Util_printService(Service_T s) {
608    Match_T ml;    Match_T ml;
609    Dependant_T d;    Dependant_T d;
610    char string[STRLEN];    char string[STRLEN];
611      char ratio1[STRLEN];
612      char ratio2[STRLEN];
613    
614    ASSERT(s);    ASSERT(s);
615    
# Line 641  void Util_printService(Service_T s) { Line 643  void Util_printService(Service_T s) {
643        printf(" %-20s = %s\n", "Depends on Service", d->dependant);        printf(" %-20s = %s\n", "Depends on Service", d->dependant);
644    
645    if(s->type == TYPE_PROCESS) {    if(s->type == TYPE_PROCESS) {
646      printf(" %-20s = if changed then %s\n",      printf(" %-20s = if changed %s then %s\n",
647        "Pid", actionnames[s->action_PID->failed->id]);        "Pid",
648      printf(" %-20s = if changed then %s\n",        Util_getEventratio(s->action_PID->failed, ratio1),
649        "Ppid", actionnames[s->action_PPID->failed->id]);        actionnames[s->action_PID->failed->id]);
650        printf(" %-20s = if changed %s then %s\n",
651          "Ppid",
652          Util_getEventratio(s->action_PPID->failed, ratio1),
653          actionnames[s->action_PPID->failed->id]);
654    }    }
655    
656    if(s->checksum && s->checksum->action) {    if(s->checksum && s->checksum->action) {
657      Checksum_T cs= s->checksum;      Checksum_T cs= s->checksum;
658      EventAction_T a= cs->action;      EventAction_T a= cs->action;
659    
660        Util_getEventratio(a->failed, ratio1);
661        Util_getEventratio(a->passed, ratio2);
662    
663      if(cs->test_changes)      if(cs->test_changes)
664        printf(" %-20s = if changed %s then %s\n",        printf(" %-20s = if changed %s %s then %s\n",
665          "Checksum", checksumnames[cs->type], actionnames[a->failed->id]);          "Checksum", checksumnames[cs->type],
666            ratio1, actionnames[a->failed->id]);
667      else      else
668        printf(" %-20s = if failed %s(%s) then %s else if recovered %s\n",        printf(" %-20s = if failed %s(%s) %s then %s else if passed %s then %s\n",
669          "Checksum", cs->hash, checksumnames[cs->type],          "Checksum", cs->hash, checksumnames[cs->type],
670          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
671            ratio2, actionnames[a->passed->id]);
672    }    }
673        
674    if(s->perm && s->perm->action) {    if(s->perm && s->perm->action) {
675      EventAction_T a= s->perm->action;      EventAction_T a= s->perm->action;
676    
677      printf(" %-20s = if failed %o then %s else if recovered then %s\n",      Util_getEventratio(a->failed, ratio1);
678        "Permission", s->perm->perm, actionnames[a->failed->id],      Util_getEventratio(a->passed, ratio2);
679        actionnames[a->passed->id]);  
680        printf(" %-20s = if failed %o %s then %s else if passed %s then %s\n",
681          "Permission", s->perm->perm,
682          ratio1, actionnames[a->failed->id],
683          ratio2, actionnames[a->passed->id]);
684    }    }
685    
686    if(s->uid && s->uid->action) {    if(s->uid && s->uid->action) {
687      EventAction_T a= s->uid->action;      EventAction_T a= s->uid->action;
688    
689      printf(" %-20s = if failed %d then %s else if recovered then %s\n",      Util_getEventratio(a->failed, ratio1);
690        "UID", (int)s->uid->uid, actionnames[a->failed->id],      Util_getEventratio(a->passed, ratio2);
691        actionnames[a->passed->id]);  
692        printf(" %-20s = if failed %d %s then %s else if passed %s then %s\n",
693          "UID", (int)s->uid->uid,
694          ratio1, actionnames[a->failed->id],
695          ratio2, actionnames[a->passed->id]);
696    }    }
697    
698    if(s->gid && s->gid->action) {    if(s->gid && s->gid->action) {
699      EventAction_T a= s->gid->action;      EventAction_T a= s->gid->action;
700    
701      printf(" %-20s = if failed %d then %s else if recovered then %s\n",      Util_getEventratio(a->failed, ratio1);
702        "GID", (int)s->gid->gid, actionnames[a->failed->id],      Util_getEventratio(a->passed, ratio2);
703        actionnames[a->passed->id]);  
704        printf(" %-20s = if failed %d %s then %s else if passed %s then %s\n",
705          "GID", (int)s->gid->gid,
706          ratio1, actionnames[a->failed->id],
707          ratio2, actionnames[a->passed->id]);
708    }    }
709    
710    if(s->icmplist)    if(s->icmplist)
711      for(i= s->icmplist; i; i= i->next) {      for(i= s->icmplist; i; i= i->next) {
712        EventAction_T a= i->action;        EventAction_T a= i->action;
713    
714        printf(" %-20s = if failed %s count %d with timeout %d seconds then %s "        Util_getEventratio(a->failed, ratio1);
715          "else if recovered then %s\n",        Util_getEventratio(a->passed, ratio2);
716    
717          printf(" %-20s = if failed %s count %d with timeout %d seconds %s then %s "
718            "else if passed %s then %s\n",
719          "ICMP", icmpnames[i->type], i->count, i->timeout,          "ICMP", icmpnames[i->type], i->count, i->timeout,
720          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
721            ratio2, actionnames[a->passed->id]);
722      }      }
723    
724    if(s->portlist) {    if(s->portlist) {
# Line 699  void Util_printService(Service_T s) { Line 726  void Util_printService(Service_T s) {
726      for(n= s->portlist; n; n= n->next) {      for(n= s->portlist; n; n= n->next) {
727        EventAction_T a= n->action;        EventAction_T a= n->action;
728                
729          Util_getEventratio(a->failed, ratio1);
730          Util_getEventratio(a->passed, ratio2);
731    
732        if(n->family == AF_INET) {        if(n->family == AF_INET) {
733                    
734          if(n->SSL.use_ssl) {             if(n->SSL.use_ssl) {
735                        
736            printf(" %-20s = if failed %s:%d%s [protocol %s via SSL] with "               printf(" %-20s = if failed %s:%d%s [protocol %s via SSL] with "
737                  "timeout %d seconds then %s else if recovered then %s\n",                 "timeout %d seconds %s then %s else if passed %s then %s\n",
738                  "Port", n->hostname, n->port, n->request?n->request:"",                 "Port", n->hostname, n->port, n->request?n->request:"",
739                   n->protocol->name, n->timeout, actionnames[a->failed->id],                 n->protocol->name, n->timeout,
740                   actionnames[a->passed->id]);                 ratio1, actionnames[a->failed->id],
741                   ratio2, actionnames[a->passed->id]);
742                        
743            if(n->SSL.certmd5 != NULL)               if(n->SSL.certmd5 != NULL)
744                printf(" %-20s = %s\n", "Server cert md5 sum", n->SSL.certmd5);                 printf(" %-20s = %s\n", "Server cert md5 sum", n->SSL.certmd5);
745                        
746          } else {          } else {
747    
748            printf(" %-20s = if failed %s:%d%s [protocol %s] with timeout %d "               printf(" %-20s = if failed %s:%d%s [protocol %s] with timeout %d "
749                   "seconds then %s else if recovered then %s\n",                 "seconds %s then %s else if passed %s then %s\n",
750                   "Port", n->hostname, n->port, n->request?n->request:"",                 "Port", n->hostname, n->port, n->request?n->request:"",
751                   n->protocol->name, n->timeout, actionnames[a->failed->id],                 n->protocol->name, n->timeout,
752                   actionnames[a->passed->id]);                 ratio1, actionnames[a->failed->id],
753                   ratio2, actionnames[a->passed->id]);
754                        
755          }             }
756                    
757        } else if(n->family == AF_UNIX) {        } else if(n->family == AF_UNIX) {
758                    
759          printf(" %-20s = if failed %s [protocol %s] with timeout %d seconds "          printf(" %-20s = if failed %s [protocol %s] with timeout %d seconds "
760                 "then %s else if recovered then %s\n",            "%s then %s else if passed %s then %s\n",
761                 "Unix Socket", n->pathname, n->protocol->name, n->timeout,            "Unix Socket", n->pathname, n->protocol->name, n->timeout,
762                 actionnames[a->failed->id], actionnames[a->passed->id]);            ratio1, actionnames[a->failed->id],
763              ratio2, actionnames[a->passed->id]);
764                    
765        }        }
766                
# Line 738  void Util_printService(Service_T s) { Line 771  void Util_printService(Service_T s) {
771    for(t= s->timestamplist; t; t= t->next) {    for(t= s->timestamplist; t; t= t->next) {
772      EventAction_T a= t->action;      EventAction_T a= t->action;
773    
774        Util_getEventratio(a->failed, ratio1);
775        Util_getEventratio(a->passed, ratio2);
776    
777      if(t->test_changes)      if(t->test_changes)
778        printf(" %-20s = if changed then %s\n",        printf(" %-20s = if changed %s then %s\n",
779          "Timestamp", actionnames[a->failed->id]);          "Timestamp",
780            ratio1, actionnames[a->failed->id]);
781      else      else
782        printf(" %-20s = if %s %d second(s) then %s else if recovered then %s\n",        printf(" %-20s = if %s %d second(s) %s then %s else if passed %s then %s\n",
783          "Timestamp", operatornames[t->operator], t->time,          "Timestamp", operatornames[t->operator], t->time,
784          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
785            ratio2, actionnames[a->passed->id]);
786            
787    }    }
788    
789    for(sl= s->sizelist; sl; sl= sl->next) {    for(sl= s->sizelist; sl; sl= sl->next) {
790      EventAction_T a= sl->action;      EventAction_T a= sl->action;
791            
792        Util_getEventratio(a->failed, ratio1);
793        Util_getEventratio(a->passed, ratio2);
794    
795      if(sl->test_changes)      if(sl->test_changes)
796        printf(" %-20s = if changed then %s\n",        printf(" %-20s = if changed %s then %s\n",
797          "Size", actionnames[a->failed->id]);          "Size",
798            ratio1, actionnames[a->failed->id]);
799      else      else
800        printf(" %-20s = if %s %lu byte(s) then %s else if recovered then %s\n",        printf(" %-20s = if %s %lu byte(s) %s then %s else if passed %s then %s\n",
801          "Size", operatornames[sl->operator], sl->size,          "Size", operatornames[sl->operator], sl->size,
802          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
803            ratio2, actionnames[a->passed->id]);
804            
805    }    }
806    
807    for(ml= s->matchlist; ml; ml= ml->next) {    for(ml= s->matchlist; ml; ml= ml->next) {
808      EventAction_T a= ml->action;      EventAction_T a= ml->action;
809            
810      printf(" %-20s = if%s match \"%s\" then %s\n",      Util_getEventratio(a->failed, ratio1);
811             "Regex", ml->not?" not":"",ml->match_string,  
812             actionnames[a->failed->id]);      printf(" %-20s = if%s match \"%s\" %s then %s\n",
813               "Regex", ml->not?" not":"", ml->match_string,
814               ratio1, actionnames[a->failed->id]);
815            
816    }    }
817        
818    for(dl= s->devicelist; dl; dl= dl->next) {    for(dl= s->devicelist; dl; dl= dl->next) {
819      EventAction_T a= dl->action;      EventAction_T a= dl->action;
820            
821        Util_getEventratio(a->failed, ratio1);
822        Util_getEventratio(a->passed, ratio2);
823    
824      if(dl->resource == RESOURCE_ID_INODE) {      if(dl->resource == RESOURCE_ID_INODE) {
825                            
826        if(dl->limit_absolute > -1) {        if(dl->limit_absolute > -1) {
827          printf(" %-20s = if %s %ld then %s else if recovered then %s\n",          printf(" %-20s = if %s %ld %s then %s else if passed %s then %s\n",
828            "Inodes usage limit",            "Inodes usage limit",
829            operatornames[dl->operator],            operatornames[dl->operator],
830            dl->limit_absolute,            dl->limit_absolute,
831            actionnames[a->failed->id], actionnames[a->passed->id]);            ratio1, actionnames[a->failed->id],
832              ratio2, actionnames[a->passed->id]);
833        } else {        } else {
834          printf(" %-20s = if %s %.1f%% then %s else if recovered then %s\n",          printf(" %-20s = if %s %.1f%% %s then %s else if passed %s then %s\n",
835            "Inodes usage limit",            "Inodes usage limit",
836            operatornames[dl->operator],            operatornames[dl->operator],
837            dl->limit_percent/10.,            dl->limit_percent/10.,
838            actionnames[a->failed->id], actionnames[a->passed->id]);            ratio1, actionnames[a->failed->id],
839              ratio2, actionnames[a->passed->id]);
840        }        }
841                
842      } else if(dl->resource == RESOURCE_ID_SPACE) {      } else if(dl->resource == RESOURCE_ID_SPACE) {
843                            
844        if(dl->limit_absolute > -1) {        if(dl->limit_absolute > -1) {
845          printf(" %-20s = if %s %ld blocks then %s else if recovered then %s\n",          printf(" %-20s = if %s %ld blocks %s then %s else if passed %s then %s\n",
846            "Space usage limit",            "Space usage limit",
847            operatornames[dl->operator],            operatornames[dl->operator],
848            dl->limit_absolute,            dl->limit_absolute,
849            actionnames[a->failed->id], actionnames[a->passed->id]);            ratio1, actionnames[a->failed->id],
850              ratio2, actionnames[a->passed->id]);
851        } else {        } else {
852          printf(" %-20s = if %s %.1f%% then %s else if recovered then %s\n",          printf(" %-20s = if %s %.1f%% %s then %s else if passed %s then %s\n",
853            "Space usage limit",            "Space usage limit",
854            operatornames[dl->operator],            operatornames[dl->operator],
855            dl->limit_percent/10.,            dl->limit_percent/10.,
856            actionnames[a->failed->id], actionnames[a->passed->id]);            ratio1, actionnames[a->failed->id],
857              ratio2, actionnames[a->passed->id]);
858        }        }
859    
860      }      }
# Line 812  void Util_printService(Service_T s) { Line 864  void Util_printService(Service_T s) {
864    for(q= s->resourcelist; q; q= q->next) {    for(q= s->resourcelist; q; q= q->next) {
865      EventAction_T a= q->action;      EventAction_T a= q->action;
866    
867        Util_getEventratio(a->failed, ratio1);
868        Util_getEventratio(a->passed, ratio2);
869    
870      switch(q->resource_id) {      switch(q->resource_id) {
871    
872      case RESOURCE_ID_CPU_PERCENT:      case RESOURCE_ID_CPU_PERCENT:
873    
874        printf(" %-20s = if %s %.1f%% for %d cycle(s) then %s "        printf(" %-20s = if %s %.1f%% %s then %s "
875          "else if recovered then %s\n",          "else if passed %s then %s\n",
876          "CPU usage limit",          "CPU usage limit",
877          operatornames[q->operator], q->limit/10.0, q->max_cycle,          operatornames[q->operator], q->limit/10.0,
878          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
879            ratio2, actionnames[a->passed->id]);
880        break;        break;
881    
882      case RESOURCE_ID_MEM_PERCENT:      case RESOURCE_ID_MEM_PERCENT:
883    
884        printf(" %-20s = if %s %.1f%% for %d cycle(s) then %s "        printf(" %-20s = if %s %.1f%% %s then %s "
885          "else if recovered then %s\n",          "else if passed %s then %s\n",
886          "Memory usage limit",          "Memory usage limit",
887          operatornames[q->operator], q->limit/10.0, q->max_cycle,          operatornames[q->operator], q->limit/10.0,
888          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
889            ratio2, actionnames[a->passed->id]);
890        break;        break;
891    
892      case RESOURCE_ID_MEM_KBYTE:      case RESOURCE_ID_MEM_KBYTE:
893    
894        printf(" %-20s = if %s %ldkB for %d cycle(s) then %s "        printf(" %-20s = if %s %ldkB %s then %s "
895          "else if recovered then %s\n",          "else if passed %s then %s\n",
896          "Memory amount limit",          "Memory amount limit",
897          operatornames[q->operator], q->limit, q->max_cycle,          operatornames[q->operator], q->limit,
898          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
899            ratio2, actionnames[a->passed->id]);
900        break;        break;
901    
902      case RESOURCE_ID_LOAD1:      case RESOURCE_ID_LOAD1:
903    
904        printf(" %-20s = if %s %.1f for %d cycle(s) then %s "        printf(" %-20s = if %s %.1f %s then %s "
905          "else if recovered then %s\n",          "else if passed %s then %s\n",
906          "Load avg. (1min)",          "Load avg. (1min)",
907          operatornames[q->operator], q->limit/10.0, q->max_cycle,          operatornames[q->operator], q->limit/10.0,
908          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
909            ratio2, actionnames[a->passed->id]);
910        break;        break;
911    
912      case RESOURCE_ID_LOAD5:      case RESOURCE_ID_LOAD5:
913    
914        printf(" %-20s = if %s %.1f for %d cycle(s) then %s "        printf(" %-20s = if %s %.1f %s then %s "
915          "else if recovered then %s\n",          "else if passed %s then %s\n",
916          "Load avg. (5min)",          "Load avg. (5min)",
917          operatornames[q->operator], q->limit/10.0, q->max_cycle,          operatornames[q->operator], q->limit/10.0,
918          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
919            ratio2, actionnames[a->passed->id]);
920        break;        break;
921    
922      case RESOURCE_ID_LOAD15:      case RESOURCE_ID_LOAD15:
923    
924        printf(" %-20s = if %s %.1f for %d cycle(s) then %s "        printf(" %-20s = if %s %.1f %s then %s "
925          "else if recovered then %s\n",          "else if passed %s then %s\n",
926          "Load avg. (15min)",          "Load avg. (15min)",
927          operatornames[q->operator], q->limit/10.0, q->max_cycle,          operatornames[q->operator], q->limit/10.0,
928          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
929            ratio2, actionnames[a->passed->id]);
930        break;        break;
931    
932      case RESOURCE_ID_CHILDREN:      case RESOURCE_ID_CHILDREN:
933    
934        printf(" %-20s = If %s %ld for %d cycle(s) then %s "        printf(" %-20s = If %s %ld %s then %s "
935          "else if recovered then %s\n",          "else if passed %s then %s\n",
936          "Children", operatornames[q->operator], q->limit, q->max_cycle,          "Children", operatornames[q->operator], q->limit,
937          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
938            ratio2, actionnames[a->passed->id]);
939        break;        break;
940    
941      case RESOURCE_ID_TOTAL_MEM_KBYTE:      case RESOURCE_ID_TOTAL_MEM_KBYTE:
942    
943        printf(" %-20s = If %s %ld for %d cycle(s) then %s "        printf(" %-20s = If %s %ld %s then %s "
944          "else if recovered then %s\n",          "else if passed %s then %s\n",
945          "Memory amount limit (incl. children)",          "Memory amount limit (incl. children)",
946          operatornames[q->operator], q->limit, q->max_cycle,          operatornames[q->operator], q->limit,
947          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
948            ratio2, actionnames[a->passed->id]);
949        break;        break;
950    
951      case RESOURCE_ID_TOTAL_MEM_PERCENT:      case RESOURCE_ID_TOTAL_MEM_PERCENT:
952    
953        printf(" %-20s = If %s %.1f%% for %d cycle(s) then %s "        printf(" %-20s = If %s %.1f%% %s then %s "
954          "else if recovered then %s\n",          "else if passed %s then %s\n",
955          "Memory usage limit (incl. children)",          "Memory usage limit (incl. children)",
956          operatornames[q->operator], q->limit/10.0, q->max_cycle,          operatornames[q->operator], q->limit/10.0,
957          actionnames[a->failed->id], actionnames[a->passed->id]);          ratio1, actionnames[a->failed->id],
958            ratio2, actionnames[a->passed->id]);
959        break;        break;
960    
961      }          }    
# Line 903  void Util_printService(Service_T s) { Line 967  void Util_printService(Service_T s) {
967    if(s->def_timeout && s->action_TIMEOUT) {    if(s->def_timeout && s->action_TIMEOUT) {
968      EventAction_T a= s->action_TIMEOUT;      EventAction_T a= s->action_TIMEOUT;
969      printf(" %-20s = If %d restart within %d cycles then %s "      printf(" %-20s = If %d restart within %d cycles then %s "
970        "else if recovered then %s\n",        "else if passed then %s\n",
971        "Timeout", s->to_start, s->to_cycle, actionnames[a->failed->id],        "Timeout", s->to_start, s->to_cycle, actionnames[a->failed->id],
972        actionnames[a->passed->id]);        actionnames[a->passed->id]);
973    }    }
# Line 1684  int Util_getAction(const char *action) { Line 1748  int Util_getAction(const char *action) {
1748    return ACTION_IGNORE;    return ACTION_IGNORE;
1749  }  }
1750    
1751    
1752    /**
1753     * Print event ratio needed to trigger the action to the buffer
1754     * @param action A action string
1755     * @return the action id
1756     */
1757    char *Util_getEventratio(Action_T action, char *buf) {
1758      snprintf(buf, STRLEN,
1759        "%d times within %d cycle(s)",
1760        action->count, action->cycles);
1761    
1762      return buf;
1763    }
1764    
1765    
1766  /* ----------------------------------------------------------------- Private */  /* ----------------------------------------------------------------- Private */
1767    
1768    
# Line 1772  static void printevents(unsigned int eve Line 1851  static void printevents(unsigned int eve
1851    printf("\n");    printf("\n");
1852  }  }
1853    
1854    

Legend:
Removed from v.1.162  
changed lines
  Added in v.1.163

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