root/src/noit_check.c

Revision eacf8d5134454850a8d9391db1790ce0df6d6f05, 21.4 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

make the stutter work

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #include "noit_defines.h"
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 #include <assert.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15
16 #include "utils/noit_log.h"
17 #include "utils/noit_hash.h"
18 #include "utils/noit_skiplist.h"
19 #include "noit_conf.h"
20 #include "noit_check.h"
21 #include "noit_module.h"
22 #include "noit_console.h"
23 #include "eventer/eventer.h"
24
25 /* 60 seconds of possible stutter */
26 #define MAX_INITIAL_STUTTER 60
27
28 static noit_hash_table polls = NOIT_HASH_EMPTY;
29 static noit_skiplist polls_by_name = { 0 };
30 static u_int32_t __config_load_generation = 0;
31 struct uuid_dummy {
32   uuid_t foo;
33 };
34
35 static void register_console_check_commands();
36
37 #define UUID_SIZE sizeof(struct uuid_dummy)
38
39 static const char *
40 __noit_check_available_string(int16_t available) {
41   switch(available) {
42     case NP_AVAILABLE:    return "available";
43     case NP_UNAVAILABLE:  return "unavailable";
44     case NP_UNKNOWN:      return "unknown";
45   }
46   return "???";
47 }
48 static const char *
49 __noit_check_state_string(int16_t state) {
50   switch(state) {
51     case NP_GOOD:         return "good";
52     case NP_BAD:          return "bad";
53     case NP_UNKNOWN:      return "unknown";
54   }
55   return "???";
56 }
57 static int __check_name_compare(void *a, void *b) {
58   noit_check_t *ac = a;
59   noit_check_t *bc = b;
60   int rv;
61   if((rv = strcmp(ac->target, bc->target)) != 0) return rv;
62   if((rv = strcmp(ac->name, bc->name)) != 0) return rv;
63   return 0;
64 }
65 int
66 noit_check_max_initial_stutter() {
67   int stutter;
68   if(!noit_conf_get_int(NULL, "/noit/checks/@max_initial_stutter", &stutter))
69     stutter = MAX_INITIAL_STUTTER;
70   return stutter * 1000;
71 }
72 void
73 noit_check_fake_last_check(noit_check_t *check,
74                            struct timeval *lc, struct timeval *_now) {
75   struct timeval now, period;
76   double r;
77   int offset, max;
78
79   r = drand48();
80   max = noit_check_max_initial_stutter();
81   offset = r * (MIN(max, check->period));
82   period.tv_sec = (check->period - offset) / 1000;
83   period.tv_usec = ((check->period - offset) % 1000) * 1000;
84   if(!_now) {
85     gettimeofday(&now, NULL);
86     _now = &now;
87   }
88   sub_timeval(*_now, period, lc);
89 }
90 void
91 noit_poller_process_checks(const char *xpath) {
92   int i, flags, cnt = 0;
93   noit_conf_section_t *sec;
94   __config_load_generation++;
95   sec = noit_conf_get_sections(NULL, xpath, &cnt);
96   for(i=0; i<cnt; i++) {
97     noit_check_t *existing_check;
98     char uuid_str[37];
99     char target[256];
100     char module[256];
101     char name[256];
102     char oncheck[1024] = "";
103     int no_period = 0;
104     int no_oncheck = 0;
105     int period = 0, timeout = 0;
106     noit_conf_boolean disabled = noit_false, busted = noit_false;
107     uuid_t uuid, out_uuid;
108     noit_hash_table *options;
109
110 #define NEXT(...) noitL(noit_stderr, __VA_ARGS__); continue
111 #define MYATTR(type,a,...) noit_conf_get_##type(sec[i], "@" #a, __VA_ARGS__)
112 #define INHERIT(type,a,...) \
113   noit_conf_get_##type(sec[i], "ancestor-or-self::node()/@" #a, __VA_ARGS__)
114
115     if(!MYATTR(stringbuf, uuid, uuid_str, sizeof(uuid_str))) {
116       noitL(noit_stderr, "check %d has no uuid\n", i+1);
117       continue;
118     }
119
120     if(uuid_parse(uuid_str, uuid)) {
121       noitL(noit_stderr, "check uuid: '%s' is invalid\n", uuid_str);
122       continue;
123     }
124
125     if(!INHERIT(stringbuf, target, target, sizeof(target))) {
126       noitL(noit_stderr, "check uuid: '%s' has no target\n", uuid_str);
127       busted = noit_true;
128     }
129     if(!INHERIT(stringbuf, module, module, sizeof(module))) {
130       noitL(noit_stderr, "check uuid: '%s' has no module\n", uuid_str);
131       busted = noit_true;
132     }
133
134     if(!MYATTR(stringbuf, name, name, sizeof(name)))
135       strlcpy(name, module, sizeof(name));
136
137     if(!INHERIT(int, period, &period) || period == 0)
138       no_period = 1;
139
140     if(!INHERIT(stringbuf, oncheck, oncheck, sizeof(oncheck)) || !oncheck[0])
141       no_oncheck = 1;
142
143     if(no_period && no_oncheck) {
144       noitL(noit_stderr, "check uuid: '%s' has neither period nor oncheck\n",
145             uuid_str);
146       busted = noit_true;
147     }
148     if(!(no_period || no_oncheck)) {
149       noitL(noit_stderr, "check uuid: '%s' has oncheck and period.\n",
150             uuid_str);
151       busted = noit_true;
152     }
153     if(!INHERIT(int, timeout, &timeout)) {
154       noitL(noit_stderr, "check uuid: '%s' has no timeout\n", uuid_str);
155       busted = noit_true;
156     }
157     if(!no_period && timeout >= period) {
158       noitL(noit_stderr, "check uuid: '%s' timeout > period\n", uuid_str);
159       timeout = period/2;
160     }
161     options = noit_conf_get_hash(sec[i], "config");
162
163     INHERIT(boolean, disable, &disabled);
164     flags = 0;
165     if(busted) flags |= NP_UNCONFIG;
166     if(disabled) flags |= NP_DISABLED;
167
168     if(noit_hash_retrieve(&polls, (char *)uuid, UUID_SIZE,
169                           (void **)&existing_check)) {
170       /* Once set, we can never change it. */
171       assert(!existing_check->module || !existing_check->module[0] ||
172              !strcmp(existing_check->module, module));
173       /* Only set it if it is not yet set */
174       if(!existing_check->module || !existing_check->module[0]) {
175         if(existing_check->module) free(existing_check->module);
176         existing_check->module = strdup(module);
177       }
178       noit_check_update(existing_check, target, name, options,
179                            period, timeout, oncheck[0] ? oncheck : NULL,
180                            flags);
181       noitL(noit_debug, "reloaded uuid: %s\n", uuid_str);
182     }
183     else {
184       noit_poller_schedule(target, module, name, options,
185                            period, timeout, oncheck[0] ? oncheck : NULL,
186                            flags, uuid, out_uuid);
187       noitL(noit_debug, "loaded uuid: %s\n", uuid_str);
188     }
189   }
190 }
191
192 void
193 noit_poller_initiate() {
194   noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
195   uuid_t key_id;
196   int klen;
197   noit_check_t *check;
198   while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen,
199                        (void **)&check)) {
200     noit_module_t *mod;
201     mod = noit_module_lookup(check->module);
202     if(mod) {
203       if(NOIT_CHECK_LIVE(check))
204         continue;
205       if((check->flags & NP_DISABLED) == 0) {
206         if(mod->initiate_check)
207           mod->initiate_check(mod, check, 0, NULL);
208       }
209       else
210         noitL(noit_debug, "Skipping %s`%s, disabled.\n",
211               check->target, check->name);
212     }
213     else {
214       noitL(noit_stderr, "Cannot find module '%s'\n", check->module);
215       check->flags |= NP_DISABLED;
216     }
217   }
218 }
219
220 void
221 noit_poller_flush_epoch(int oldest_allowed) {
222   noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
223   uuid_t key_id;
224   int klen;
225   noit_check_t *check, *tofree = NULL;
226
227   /* Cleanup any previous causal map */
228   while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen,
229                        (void **)&check)) {
230     /* We don't free the one we're looking at... we free it on the next
231      * pass.  This leaves out iterator in good shape.  We just need to
232      * remember to free it one last time outside the while loop, down...
233      */
234     if(tofree) {
235       noit_poller_deschedule(tofree->checkid);
236       tofree = NULL;
237     }
238     if(check->generation < oldest_allowed) {
239       tofree = check;
240     }
241   }
242   /* ... here */
243   if(tofree) noit_poller_deschedule(tofree->checkid);
244 }
245
246 void
247 noit_poller_make_causal_map() {
248   noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
249   uuid_t key_id;
250   int klen;
251   noit_check_t *check, *parent;
252
253   /* Cleanup any previous causal map */
254   while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen,
255                        (void **)&check)) {
256     dep_list_t *dep;
257     while((dep = check->causal_checks) != NULL) {
258       check->causal_checks = dep->next;
259       free(dep);
260     }
261   }
262
263   memset(&iter, 0, sizeof(iter));
264   /* Walk all checks and add check dependencies to their parents */
265   while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen,
266                        (void **)&check)) {
267     if(check->oncheck) {
268       /* This service is causally triggered by another service */
269       char fullcheck[1024];
270       char *name = check->oncheck;
271       char *target = NULL;
272
273       noitL(noit_debug, "Searching for upstream trigger on %s\n", name);
274       if((target = strchr(check->oncheck, '`')) != NULL) {
275         strlcpy(fullcheck, check->oncheck, target - check->oncheck);
276         name = target + 1;
277         target = fullcheck;
278       }
279       else
280        target = check->target;
281
282       parent = noit_poller_lookup_by_name(target, name);
283       if(!parent) {
284         check->flags |= NP_DISABLED;
285         noitL(noit_stderr, "Disabling check %s`%s, can't find oncheck %s`%s\n",
286               check->target, check->name, target, name);
287       }
288       else {
289         dep_list_t *dep;
290         dep = malloc(sizeof(*dep));
291         dep->check = check;
292         dep->next = parent->causal_checks;
293         parent->causal_checks = dep;
294         noitL(noit_debug, "Causal map %s`%s --> %s`%s\n",
295               parent->target, parent->name, check->target, check->name);
296       }
297     }
298   }
299 }
300 void
301 noit_poller_reload(const char *xpath)
302 {
303   noit_poller_process_checks(xpath ? xpath : "/noit/checks//check");
304   if(!xpath) {
305     /* Full reload, we need to wipe old checks */
306     noit_poller_flush_epoch(__config_load_generation);
307   }
308   noit_poller_make_causal_map();
309   noit_poller_initiate();
310 }
311 void
312 noit_poller_init() {
313   noit_skiplist_init(&polls_by_name);
314   noit_skiplist_set_compare(&polls_by_name, __check_name_compare,
315                             __check_name_compare);
316   register_console_check_commands();
317   noit_poller_reload(NULL);
318 }
319
320 int
321 noit_check_update(noit_check_t *new_check,
322                   const char *target,
323                   const char *name,
324                   noit_hash_table *config,
325                   u_int32_t period,
326                   u_int32_t timeout,
327                   const char *oncheck,
328                   int flags) {
329   int8_t family;
330   int rv;
331   int mask = NP_DISABLED | NP_UNCONFIG;
332   union {
333     struct in_addr addr4;
334     struct in6_addr addr6;
335   } a;
336
337
338   family = AF_INET;
339   rv = inet_pton(family, target, &a);
340   if(rv != 1) {
341     family = AF_INET6;
342     rv = inet_pton(family, target, &a);
343     if(rv != 1) {
344       noitL(noit_stderr, "Cannot translate '%s' to IP\n", target);
345       memset(&a, 0, sizeof(a));
346       flags |= (NP_UNCONFIG & NP_DISABLED);
347     }
348   }
349
350   new_check->generation = __config_load_generation;
351   new_check->target_family = family;
352   memcpy(&new_check->target_addr, &a, sizeof(a));
353   if(new_check->target) free(new_check->target);
354   new_check->target = strdup(target);
355   if(new_check->name) free(new_check->name);
356   new_check->name = name ? strdup(name): NULL;
357
358   if(config != NULL) {
359     noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
360     const char *k;
361     int klen;
362     void *data;
363     if(new_check->config) noit_hash_delete_all(new_check->config, free, free);
364     else new_check->config = calloc(1, sizeof(*new_check->config));
365     while(noit_hash_next(config, &iter, &k, &klen, &data)) {
366       noit_hash_store(new_check->config, strdup(k), klen, strdup((char *)data));
367     }
368   }
369   if(new_check->oncheck) free(new_check->oncheck);
370   new_check->oncheck = oncheck ? strdup(oncheck) : NULL;
371   new_check->period = period;
372   new_check->timeout = timeout;
373
374   /* Unset what could be set.. then set what should be set */
375   new_check->flags = (new_check->flags & ~mask) | flags;
376
377   /* This remove could fail -- no big deal */
378   noit_skiplist_remove(&polls_by_name, new_check, NULL);
379
380   /* This insert could fail.. which means we have a conflict on
381    * target`name.  That should result in the check being disabled. */
382   if(!noit_skiplist_insert(&polls_by_name, new_check)) {
383     noitL(noit_stderr, "Check %s`%s disabled due to naming conflict\n",
384           new_check->target, new_check->name);
385     new_check->flags |= NP_DISABLED;
386   }
387   noit_check_log_check(new_check);
388   return 0;
389 }
390 int
391 noit_poller_schedule(const char *target,
392                      const char *module,
393                      const char *name,
394                      noit_hash_table *config,
395                      u_int32_t period,
396                      u_int32_t timeout,
397                      const char *oncheck,
398                      int flags,
399                      uuid_t in,
400                      uuid_t out) {
401   noit_check_t *new_check;
402   new_check = calloc(1, sizeof(*new_check));
403   if(!new_check) return -1;
404
405   /* The module and the UUID can never be changed */
406   new_check->module = strdup(module);
407   if(uuid_is_null(in))
408     uuid_generate(new_check->checkid);
409   else
410     uuid_copy(new_check->checkid, in);
411
412   noit_check_update(new_check, target, name, config,
413                     period, timeout, oncheck, flags);
414   assert(noit_hash_store(&polls,
415                          (char *)new_check->checkid, UUID_SIZE,
416                          new_check));
417   uuid_copy(out, new_check->checkid);
418
419   return 0;
420 }
421
422 int
423 noit_poller_deschedule(uuid_t in) {
424   noit_check_t *checker;
425   noit_module_t *mod;
426   if(noit_hash_retrieve(&polls,
427                         (char *)in, UUID_SIZE,
428                         (void **)&checker) == 0) {
429     return -1;
430   }
431   if(checker->flags & NP_RUNNING) {
432     checker->flags |= NP_KILLED;
433     return 0;
434   }
435   checker->flags |= NP_KILLED;
436
437   noit_skiplist_remove(&polls_by_name, checker, NULL);
438   noit_hash_delete(&polls, (char *)in, UUID_SIZE, NULL, NULL);
439
440   mod = noit_module_lookup(checker->module);
441   mod->cleanup(mod, checker);
442   if(checker->fire_event) {
443      eventer_remove(checker->fire_event);
444      eventer_free(checker->fire_event);
445      checker->fire_event = NULL;
446   }
447
448   if(checker->target) free(checker->target);
449   if(checker->module) free(checker->module);
450   if(checker->name) free(checker->name);
451   if(checker->config) {
452     noit_hash_destroy(checker->config, free, free);
453     free(checker->config);
454     checker->config = NULL;
455   }
456   free(checker);
457   return 0;
458 }
459
460 noit_check_t *
461 noit_poller_lookup(uuid_t in) {
462   noit_check_t *check;
463   if(noit_hash_retrieve(&polls,
464                         (char *)in, UUID_SIZE,
465                         (void **)&check)) {
466     return check;
467   }
468   return NULL;
469 }
470 noit_check_t *
471 noit_poller_lookup_by_name(char *target, char *name) {
472   noit_check_t *check, *tmp_check;
473   tmp_check = calloc(1, sizeof(*tmp_check));
474   tmp_check->target = target;
475   tmp_check->name = name;
476   check = noit_skiplist_find(&polls_by_name, tmp_check, NULL);
477   free(tmp_check);
478   return check;
479 }
480
481 void
482 noit_check_stats_clear(stats_t *s) {
483   memset(s, 0, sizeof(*s));
484   s->state = NP_UNKNOWN;
485   s->available = NP_UNKNOWN;
486 }
487 static void
488 __free_metric(void *vm) {
489   metric_t *m = vm;
490   free(m->metric_name);
491   if(m->metric_value.i) free(m->metric_value.i);
492 }
493
494 void
495 __stats_add_metric(stats_t *newstate, metric_t *m) {
496   noit_hash_replace(&newstate->metrics, m->metric_name, strlen(m->metric_name),
497                     m, NULL, __free_metric);
498 }
499
500 static size_t
501 noit_metric_sizes(metric_type_t type, void *value) {
502   switch(type) {
503     case METRIC_INT32:
504     case METRIC_UINT32:
505       return sizeof(int32_t);
506     case METRIC_INT64:
507     case METRIC_UINT64:
508       return sizeof(int64_t);
509     case METRIC_DOUBLE:
510       return sizeof(double);
511     case METRIC_STRING:
512       return strlen((char *)value) + 1;
513     case METRIC_GUESS:
514       break;
515   }
516   assert(type != type);
517   return 0;
518 }
519 static metric_type_t
520 noit_metric_guess_type(const char *s, void **replacement) {
521   char *copy, *cp, *trailer, *rpl;
522   int negative = 0, bigF = 0;
523   metric_type_t type = METRIC_STRING;
524
525   if(!s) return METRIC_GUESS;
526   copy = cp = strdup(s);
527
528   /* TRIM the string */
529   while(*cp && isspace(*cp)) cp++; /* ltrim */
530   s = cp; /* found a good starting point */
531   while(*cp) cp++; /* advance to \0 */
532   cp--; /* back up one */
533   while(cp > s && isspace(*cp)) *cp-- = '\0'; /* rtrim */
534
535   /* Find the first space */
536   cp = (char *)s;
537   while(*cp && !isspace(*cp)) cp++;
538   trailer = cp;
539   cp--; /* backup one */
540   if(cp > s && *cp == '%') *cp-- = '\0'; /* chop a last % is there is one */
541
542   while(*trailer && isspace(*trailer)) *trailer++; /* rtrim */
543
544   /* string was       '  -1.23e-01%  inodes used  ' */
545   /* copy is (~ = \0) '  -1.23e-01~  inodes used~~' */
546   /*                     ^           ^              */
547   /*                     s           trailer        */
548
549   /* So, the trailer must not contain numbers */
550   while(*trailer) { if(isdigit(*trailer)) goto notanumber; trailer++; }
551
552   /* And the 's' must be of the form:
553    *  0) may start with a sign [-+]?
554    *  1) [1-9][0-9]*
555    *  2) [0]?.[0-9]+
556    *  3) 0
557    *  4) [1-9][0-9]*.[0-9]+
558    *  5) all of the above ending with e[+-][0-9]+
559    */
560    rpl = (char *)s;
561    /* CASE 0 */
562    if(s[0] == '-' || s[0] == '+') {
563      if(s[0] == '-') negative = 1;
564      s++;
565    }
566
567    if(s[0] == '.') goto decimal; /* CASE 2 */
568    if(s[0] == '0') { /* CASE 2 & 3 */
569      s++;
570      if(!s[0]) goto scanint; /* CASE 3 */
571      if(s[0] == '.') goto decimal; /* CASE 2 */
572      goto notanumber;
573    }
574    if(s[0] >= '1' && s[0] <= '9') { /* CASE 1 & 4 */
575      s++;
576      while(isdigit(s[0])) s++; /* CASE 1 & 4 */
577      if(!s[0]) goto scanint; /* CASE 1 */
578      if(s[0] == '.') goto decimal; /* CASE 4 */
579      goto notanumber;
580    }
581    /* Not case 1,2,3,4 */
582    goto notanumber;
583
584   decimal:
585    s++;
586    if(!isdigit(s[0])) goto notanumber;
587    s++;
588    while(isdigit(s[0])) s++;
589    if(!s[0]) goto scandouble;
590    if(s[0] == 'e' || s[0] == 'E') goto exponent; /* CASE 5 */
591    goto notanumber;
592
593   exponent:
594    if(s[0] == 'E') bigF = 1; /* We want the caps variant */
595    s++;
596    if(s[0] != '-' && s[0] != '+') goto notanumber;
597    s++;
598    if(!isdigit(s[0])) goto notanumber;
599    s++;
600    while(isdigit(s[0])) s++;
601    if(!s[0]) goto scandouble;
602    goto notanumber;
603
604  scanint:
605    if(negative) {
606      int64_t *v;
607      v = calloc(1, sizeof(*v));
608      *v = strtoll(rpl, NULL, 10);
609      *replacement = v;
610      type = METRIC_INT64;
611      goto alldone;
612    }
613    else {
614      u_int64_t *v;
615      v = calloc(1, sizeof(*v));
616      *v = strtoull(rpl, NULL, 10);
617      *replacement = v;
618      type = METRIC_UINT64;
619      goto alldone;
620    }
621  scandouble:
622    {
623      double *v;
624      v = calloc(1, sizeof(*v));
625      *v = strtod(rpl, NULL);
626      *replacement = v;
627      type = METRIC_DOUBLE;
628      goto alldone;
629    }
630
631  alldone:
632  notanumber:
633   free(copy);
634   return type;
635 }
636 void
637 noit_stats_set_metric(stats_t *newstate, char *name, metric_type_t type,
638                       void *value) {
639   metric_t *m;
640   void *replacement = NULL;
641   if(type == METRIC_GUESS)
642     type = noit_metric_guess_type((char *)value, &replacement);
643   if(type == METRIC_GUESS) return;
644
645   m = calloc(1, sizeof(*m));
646   m->metric_name = strdup(name);
647   m->metric_type = type;
648   if(replacement)
649     m->metric_value.vp = replacement;
650   else if(value) {
651     size_t len;
652     len = noit_metric_sizes(type, value);
653     m->metric_value.vp = calloc(1, len);
654     memcpy(m->metric_value.vp, value, len);
655   }
656   __stats_add_metric(newstate, m);
657 }
658
659 void
660 noit_check_set_stats(struct _noit_module *module,
661                      noit_check_t *check, stats_t *newstate) {
662   int report_change = 0;
663   dep_list_t *dep;
664   if(check->stats.previous.status)
665     free(check->stats.previous.status);
666   noit_hash_destroy(&check->stats.previous.metrics, NULL, __free_metric);
667   memcpy(&check->stats.previous, &check->stats.current, sizeof(stats_t));
668   memcpy(&check->stats.current, newstate, sizeof(stats_t));
669   if(check->stats.current.status)
670     check->stats.current.status = strdup(check->stats.current.status);
671
672   /* check for state changes */
673   if(check->stats.current.available != NP_UNKNOWN &&
674      check->stats.previous.available != NP_UNKNOWN &&
675      check->stats.current.available != check->stats.previous.available)
676     report_change = 1;
677   if(check->stats.current.state != NP_UNKNOWN &&
678      check->stats.previous.state != NP_UNKNOWN &&
679      check->stats.current.state != check->stats.previous.state)
680     report_change = 1;
681
682   noitL(noit_error, "%s`%s <- [%s]\n", check->target, check->name,
683         check->stats.current.status);
684   if(report_change) {
685     noitL(noit_error, "%s`%s -> [%s:%s]\n",
686           check->target, check->name,
687           __noit_check_available_string(check->stats.current.available),
688           __noit_check_state_string(check->stats.current.state));
689   }
690
691   /* Write out our status */
692   noit_check_log_status(check);
693   /* Write out all metrics */
694   noit_check_log_metrics(check);
695
696   for(dep = check->causal_checks; dep; dep = dep->next) {
697     noit_module_t *mod;
698     mod = noit_module_lookup(dep->check->module);
699     assert(mod);
700     noitL(noit_debug, "Firing %s`%s in response to %s`%s\n",
701           dep->check->target, dep->check->name,
702           check->target, check->name);
703     mod->initiate_check(mod, dep->check, 1, check);
704   }
705 }
706
707 static void
708 nc_printf_check_brief(noit_console_closure_t ncct,
709                       noit_check_t *check) {
710   char out[512];
711   char uuid_str[37];
712   snprintf(out, sizeof(out), "%s`%s", check->target, check->name);
713   uuid_unparse_lower(check->checkid, uuid_str);
714   nc_printf(ncct, "%s %s\n", uuid_str, out);
715   if(check->stats.current.status)
716     nc_printf(ncct, "\t%s\n", check->stats.current.status);
717 }
718
719 static int
720 noit_console_show_checks(noit_console_closure_t ncct,
721                          int argc, char **argv,
722                          noit_console_state_t *dstate,
723                          void *closure) {
724   struct timeval _now;
725   noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
726   uuid_t key_id;
727   int klen;
728   noit_check_t *check;
729
730   gettimeofday(&_now, NULL);
731   while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen,
732                        (void **)&check)) {
733     nc_printf_check_brief(ncct, check);
734   }
735   return 0;
736 }
737
738 static void
739 register_console_check_commands() {
740   noit_console_state_t *tl;
741   cmd_info_t *showcmd;
742
743   tl = noit_console_state_initial();
744   showcmd = noit_console_state_get_cmd(tl, "show");
745   assert(showcmd && showcmd->dstate);
746
747   noit_console_state_add_cmd(showcmd->dstate,
748     NCSCMD("checks", noit_console_show_checks, NULL, NULL));
749 }
750
Note: See TracBrowser for help on using the browser.