root/src/noit_conf_checks.c

Revision 86e1c05fa7c180d9d908fc39e800e0ed70c8aeb8, 39.4 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 years ago)

check to make sure we have a config

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include "noit_defines.h"
34
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <errno.h>
39 #include <assert.h>
40 #include <libxml/parser.h>
41 #include <libxml/tree.h>
42 #include <libxml/xpath.h>
43
44 #include "noit_conf.h"
45 #include "noit_conf_private.h"
46 #include "noit_conf_checks.h"
47 #include "noit_check.h"
48 #include "noit_check_tools.h"
49 #include "noit_filters.h"
50 #include "noit_console.h"
51 #include "utils/noit_hash.h"
52 #include "utils/noit_log.h"
53
54 static void register_console_config_check_commands();
55
56 static struct _valid_attr_t {
57   const char *scope;
58   const char *name;
59   const char *xpath;
60   int checks_fixate;
61 } valid_attrs[] = {
62   { "/checks", "name", "@name", 0 },
63   { "/checks", "target", "@target", 0 },
64   { "/checks", "period", "@period", 0 },
65   { "/checks", "timeout", "@timeout", 0 },
66   { "/checks", "oncheck", "@oncheck", 0 },
67   { "/checks", "disable", "@disable", 0 },
68   { "/checks", "filterset", "@filterset", 0 },
69   { "/checks", "module", "@module", 1 },
70   { "/filtersets", "target", "@target", 0 },
71   { "/filtersets", "module", "@module", 0 },
72   { "/filtersets", "name", "@name", 0 },
73   { "/filtersets", "metric", "@metric", 0 },
74 };
75
76 void
77 noit_console_state_add_check_attrs(noit_console_state_t *state,
78                                    console_cmd_func_t f,
79                                    const char *scope) {
80   int i;
81   for(i = 0;
82       i < sizeof(valid_attrs)/sizeof(valid_attrs[0]);
83       i++) {
84     if(strcmp(valid_attrs[i].scope, scope)) continue;
85     noit_console_state_add_cmd(state,
86       NCSCMD(valid_attrs[i].name, f, NULL,
87              NULL, &valid_attrs[i]));
88   }
89 }
90 static noit_hash_table check_attrs = NOIT_HASH_EMPTY;
91
92 void noit_console_conf_checks_init() {
93   int i;
94   for(i=0;i<sizeof(valid_attrs)/sizeof(*valid_attrs);i++) {
95     noit_hash_store(&check_attrs,
96                     valid_attrs[i].name, strlen(valid_attrs[i].name),
97                     &valid_attrs[i]);
98   }
99   register_console_config_check_commands();
100 }
101
102 static int
103 noit_console_mkcheck_xpath(char *xpath, int len,
104                            noit_conf_t_userdata_t *info,
105                            const char *arg) {
106   int rv;
107   rv = noit_check_xpath(xpath, len, "/", arg);
108   if(rv == -1) return -1;
109   if(rv == 0) {
110     char *path = (!info || !strcmp(info->path, "/")) ? "" : info->path;
111     snprintf(xpath, len, "/noit%s%s%s[@uuid]",
112              path, arg ? "/" : "", arg ? arg : "");
113   }
114   return 0;
115 }
116 static void
117 nc_attr_show(noit_console_closure_t ncct, const char *name, xmlNodePtr cnode,
118              xmlNodePtr anode, const char *value) {
119   const char *cpath, *apath;
120   cpath = cnode ? (char *)xmlGetNodePath(cnode) : "";
121   apath = anode ? (char *)xmlGetNodePath(anode) : "";
122   nc_printf(ncct, " %s: %s", name, value ? value : "[undef]");
123   if(value && cpath && apath) {
124     int clen = strlen(cpath);
125     int plen = strlen("/noit/checks/");
126     if(!strncmp(cpath, apath, clen) && apath[clen] == '/') {
127       /* we have a match, which means it isn't inherited */
128     }
129     else {
130       nc_printf(ncct, " [inherited from %s]",
131                 strlen(apath) > plen ? apath + plen : apath);
132     }
133   }
134   nc_write(ncct, "\n", 1);
135 }
136 static void
137 refresh_subchecks(noit_console_closure_t ncct,
138                   noit_conf_t_userdata_t *info) {
139   char *path;
140   char xpath[1024];
141  
142   path = info->path;
143   if(!strcmp(path, "/")) path = "";
144
145   /* The first one is just a process_checks, the second is the reload.
146    * Reload does a lot of work and there is no need to do it twice.
147    */
148   snprintf(xpath, sizeof(xpath), "/noit/%s[@uuid]", path);
149   noit_poller_process_checks(xpath);
150   snprintf(xpath, sizeof(xpath), "/noit/%s//check[@uuid]", path);
151   noit_poller_reload(xpath);
152 }
153 static int
154 noit_config_check_update_attrs(xmlNodePtr node, int argc, char **argv) {
155   int i, error = 0;
156   if(argc % 2) return -1;
157
158   for(i=0; i<argc; i+=2) {
159     void *vattrinfo;
160     struct _valid_attr_t *attrinfo;
161     char *attr = argv[i], *val = NULL;
162     if(!strcasecmp(argv[i], "no")) attr = argv[i+1];
163     else val = argv[i+1];
164     if(!noit_hash_retrieve(&check_attrs, attr, strlen(attr),
165                            &vattrinfo)) {
166       error = 1;
167       break;
168     }
169     attrinfo = vattrinfo;
170     /* The fixation stuff doesn't matter here, this check is brand-new */
171     xmlUnsetProp(node, (xmlChar *)attrinfo->name);
172     if(val)
173       xmlSetProp(node, (xmlChar *)attrinfo->name, (xmlChar *)val);
174     noit_conf_mark_changed();
175   }
176   return error;
177 }
178
179 static int
180 noit_conf_mkcheck_under(const char *ppath, int argc, char **argv, uuid_t out) {
181   int rv = -1;
182   const char *path;
183   char xpath[1024];
184   xmlXPathContextPtr xpath_ctxt = NULL;
185   xmlXPathObjectPtr pobj = NULL;
186   xmlNodePtr node = NULL, newnode;
187
188   /* attr val [or] no attr (sets of two) */
189   if(argc % 2) goto out;
190
191   noit_conf_xml_xpath(NULL, &xpath_ctxt);
192   path = strcmp(ppath, "/") ? ppath : "";
193   snprintf(xpath, sizeof(xpath), "/noit%s", path);
194   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
195   if(!pobj || pobj->type != XPATH_NODESET ||
196      xmlXPathNodeSetGetLength(pobj->nodesetval) != 1) {
197     goto out;
198   }
199   node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
200   if((newnode = xmlNewChild(node, NULL, (xmlChar *)"check", NULL)) != NULL) {
201     char outstr[37];
202     uuid_generate(out);
203     uuid_unparse_lower(out, outstr);
204     xmlSetProp(newnode, (xmlChar *)"uuid", (xmlChar *)outstr);
205     xmlSetProp(newnode, (xmlChar *)"disable", (xmlChar *)"true");
206
207     /* No risk of running off the end (we checked this above) */
208     if(noit_config_check_update_attrs(newnode, argc, argv)) {
209       /* Something went wrong, remove the node */
210       xmlUnlinkNode(newnode);
211     }
212     else {
213       noit_conf_mark_changed();
214       rv = 0;
215     }
216   }
217  out:
218   if(pobj) xmlXPathFreeObject(pobj);
219   return rv;
220 }
221
222 static int
223 noit_console_check(noit_console_closure_t ncct,
224                    int argc, char **argv,
225                    noit_console_state_t *state, void *closure) {
226   int cnt;
227   noit_conf_t_userdata_t *info;
228   char xpath[1024], newuuid_str[37];
229   char *uuid_conf, *wanted;
230   uuid_t checkid;
231   xmlXPathContextPtr xpath_ctxt = NULL;
232   xmlXPathObjectPtr pobj = NULL;
233   xmlNodePtr node = NULL;
234   noit_boolean creating_new = noit_false;
235
236   if(closure) {
237     char *fake_argv[1] = { ".." };
238     noit_console_state_pop(ncct, 0, argv, NULL, NULL);
239     noit_console_config_cd(ncct, 1, fake_argv, NULL, NULL);
240   }
241
242   noit_conf_xml_xpath(NULL, &xpath_ctxt);
243   if(argc < 1) {
244     nc_printf(ncct, "requires at least one argument\n");
245     return -1;
246   }
247   if(argc % 2 == 0) {
248     nc_printf(ncct, "wrong number of arguments\n");
249     return -1;
250   }
251
252   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
253   wanted = strcmp(argv[0], "new") ? argv[0] : NULL;
254   if(info && !wanted) {
255     /* We are creating a new node */
256     uuid_t out;
257     creating_new = noit_true;
258     if(strncmp(info->path, "/checks/", strlen("/checks/")) &&
259        strcmp(info->path, "/checks")) {
260       nc_printf(ncct, "New checks must be under /checks/\n");
261       return -1;
262     }
263     if(noit_conf_mkcheck_under(info->path, argc - 1, argv + 1, out)) {
264       nc_printf(ncct, "Error creating new check\n");
265       return -1;
266     }
267     newuuid_str[0] = '\0';
268     uuid_unparse_lower(out, newuuid_str);
269     wanted = newuuid_str;
270   }
271   /* We many not be in conf-t mode -- that's fine */
272   if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, wanted)) {
273     nc_printf(ncct, "could not find check '%s'\n", wanted);
274     return -1;
275   }
276
277   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
278   if(!pobj || pobj->type != XPATH_NODESET ||
279      xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
280     nc_printf(ncct, "no checks found for '%s'\n", wanted);
281     goto out;
282   }
283   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
284   if(info && cnt != 1) {
285     nc_printf(ncct, "Ambiguous check specified\n");
286     goto out;
287   }
288   node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
289   uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
290   if(!uuid_conf || uuid_parse(uuid_conf, checkid)) {
291     nc_printf(ncct, "%s has invalid or missing UUID!\n",
292               (char *)xmlGetNodePath(node) + strlen("/noit"));
293     goto out;
294   }
295   if(argc > 1 && !creating_new)
296     if(noit_config_check_update_attrs(node, argc - 1, argv + 1))
297       nc_printf(ncct, "Partially successful, error setting some attributes\n");
298
299   if(info) {
300     if(info->path) free(info->path);
301     info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit"));
302     uuid_copy(info->current_check, checkid);
303     if(argc > 1) refresh_subchecks(ncct, info);
304     if(state) {
305       noit_console_state_push_state(ncct, state);
306       noit_console_state_init(ncct);
307     }
308     goto out;
309   }
310  out:
311   if(pobj) xmlXPathFreeObject(pobj);
312   return 0;
313 }
314 static int
315 noit_console_watch_check(noit_console_closure_t ncct,
316                          int argc, char **argv,
317                          noit_console_state_t *state, void *closure) {
318   int i, cnt;
319   int adding = (int)closure;
320   int period = 0;
321   char xpath[1024];
322   xmlXPathObjectPtr pobj = NULL;
323   xmlXPathContextPtr xpath_ctxt = NULL;
324
325   noit_conf_xml_xpath(NULL, &xpath_ctxt);
326   if(argc < 1 || argc > 2) {
327     nc_printf(ncct, "requires one or two arguments\n");
328     return -1;
329   }
330   /* An alternate period */
331   if(argc == 2) period = atoi(argv[1]);
332
333   if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), NULL,
334                                 argc ? argv[0] : NULL)) {
335     nc_printf(ncct, "ERROR: could not find check '%s'\n", argv[0]);
336     return -1;
337   }
338
339   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
340   if(!pobj || pobj->type != XPATH_NODESET ||
341      xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
342     nc_printf(ncct, "no checks found\n");
343     goto out;
344   }
345   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
346   for(i=0; i<cnt; i++) {
347     uuid_t checkid;
348     noit_check_t *check;
349     xmlNodePtr node;
350     char *uuid_conf;
351
352     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
353     uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
354     if(!uuid_conf || uuid_parse(uuid_conf, checkid)) {
355       nc_printf(ncct, "%s has invalid or missing UUID!\n",
356                 (char *)xmlGetNodePath(node) + strlen("/noit"));
357       continue;
358     }
359     if(period == 0) {
360       check = noit_poller_lookup(checkid);
361       if(!check) continue;
362       if(adding) noit_check_transient_add_feed(check, ncct->feed_path);
363       else noit_check_transient_remove_feed(check, ncct->feed_path);
364     }
365     else {
366       if(adding) {
367         check = noit_check_watch(checkid, period);
368         /* This check must be watched from the console */
369         noit_check_transient_add_feed(check, ncct->feed_path);
370         /* Note the check */
371         noit_check_log_check(check);
372         /* kick it off, if it isn't running already */
373         if(!NOIT_CHECK_LIVE(check)) noit_check_activate(check);
374       }
375       else {
376         check = noit_check_get_watch(checkid, period);
377         if(check) noit_check_transient_remove_feed(check, ncct->feed_path);
378       }
379     }
380   }
381  out:
382   if(pobj) xmlXPathFreeObject(pobj);
383   return 0;
384 }
385 static int
386 noit_console_show_check(noit_console_closure_t ncct,
387                         int argc, char **argv,
388                         noit_console_state_t *state, void *closure) {
389   int i, cnt;
390   noit_conf_t_userdata_t *info;
391   char xpath[1024];
392   xmlXPathObjectPtr pobj = NULL;
393   xmlXPathContextPtr xpath_ctxt = NULL;
394
395   noit_conf_xml_xpath(NULL, &xpath_ctxt);
396   if(argc > 1) {
397     nc_printf(ncct, "requires zero or one arguments\n");
398     return -1;
399   }
400
401   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
402   /* We many not be in conf-t mode -- that's fine */
403   if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info,
404                                 argc ? argv[0] : NULL)) {
405     nc_printf(ncct, "could not find check '%s'\n", argv[0]);
406     return -1;
407   }
408
409   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
410   if(!pobj || pobj->type != XPATH_NODESET ||
411      xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
412     nc_printf(ncct, "no checks found\n");
413     goto out;
414   }
415   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
416   if(info && cnt != 1) {
417     nc_printf(ncct, "Ambiguous check specified\n");
418     goto out;
419   }
420   for(i=0; i<cnt; i++) {
421     noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
422     const char *k;
423     int klen;
424     void *data;
425     uuid_t checkid;
426     noit_check_t *check;
427     noit_hash_table *config;
428     xmlNodePtr node, anode, mnode = NULL;
429     char *uuid_conf;
430     char *module, *value;
431
432     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
433     uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
434     if(!uuid_conf || uuid_parse(uuid_conf, checkid)) {
435       nc_printf(ncct, "%s has invalid or missing UUID!\n",
436                 (char *)xmlGetNodePath(node) + strlen("/noit"));
437       continue;
438     }
439     nc_printf(ncct, "==== %s ====\n", uuid_conf);
440
441 #define MYATTR(a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b))
442 #define INHERIT(a,n,b) \
443   _noit_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b))
444 #define SHOW_ATTR(a) do { \
445   anode = NULL; \
446   value = NULL; \
447   INHERIT(a, anode, value); \
448   nc_attr_show(ncct, #a, node, anode, value); \
449 } while(0)
450
451     if(!INHERIT(module, mnode, module)) module = NULL;
452     if(MYATTR(name, anode, value))
453       nc_printf(ncct, " name: %s\n", value);
454     else
455       nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]");
456     nc_attr_show(ncct, "module", node, mnode, module);
457     SHOW_ATTR(target);
458     SHOW_ATTR(period);
459     SHOW_ATTR(timeout);
460     SHOW_ATTR(oncheck);
461     SHOW_ATTR(filterset);
462     SHOW_ATTR(disable);
463     /* Print out all the config settings */
464     config = noit_conf_get_hash(node, "config");
465     while(noit_hash_next(config, &iter, &k, &klen, &data)) {
466       nc_printf(ncct, " config::%s: %s\n", k, (const char *)data);
467     }
468     noit_hash_destroy(config, free, free);
469     free(config);
470
471     check = noit_poller_lookup(checkid);
472     if(!check) {
473       nc_printf(ncct, " ERROR: not in running system\n");
474     }
475     else {
476       int idx = 0;
477       nc_printf(ncct, " currently: ");
478       if(NOIT_CHECK_RUNNING(check)) nc_printf(ncct, "%srunning", idx++?",":"");
479       if(NOIT_CHECK_KILLED(check)) nc_printf(ncct, "%skilled", idx++?",":"");
480       if(!NOIT_CHECK_CONFIGURED(check)) nc_printf(ncct, "%sunconfig", idx++?",":"");
481       if(NOIT_CHECK_DISABLED(check)) nc_printf(ncct, "%sdisabled", idx++?",":"");
482       if(!idx) nc_printf(ncct, "idle");
483       nc_write(ncct, "\n", 1);
484       if(check->stats.current.whence.tv_sec == 0) {
485         nc_printf(ncct, " last run: never\n");
486       }
487       else {
488         stats_t *c = &check->stats.current;
489         struct timeval now, diff;
490         gettimeofday(&now, NULL);
491         sub_timeval(now, c->whence, &diff);
492         nc_printf(ncct, " last run: %0.3f seconds ago\n",
493                   diff.tv_sec + (diff.tv_usec / 1000000.0));
494         nc_printf(ncct, " availability/state: %s/%s\n",
495                   noit_check_available_string(c->available),
496                   noit_check_state_string(c->state));
497         nc_printf(ncct, " status: %s\n", c->status ? c->status : "[[null]]");
498         nc_printf(ncct, " metrics:\n");
499         memset(&iter, 0, sizeof(iter));
500         while(noit_hash_next(&c->metrics, &iter, &k, &klen, &data)) {
501           char buff[256];
502           noit_boolean filtered;
503           noit_stats_snprint_metric(buff, sizeof(buff), (metric_t *)data);
504           filtered = !noit_apply_filterset(check->filterset, check, (metric_t *)data);
505           nc_printf(ncct, "  %c%s\n", filtered ? '*' : ' ', buff);
506         }
507       }
508     }
509   }
510  out:
511   if(pobj) xmlXPathFreeObject(pobj);
512   return 0;
513 }
514 static int
515 noit_console_config_nocheck(noit_console_closure_t ncct,
516                             int argc, char **argv,
517                             noit_console_state_t *state, void *closure) {
518   int i, cnt;
519   const char *err = "internal error";
520   noit_conf_t_userdata_t *info;
521   xmlXPathObjectPtr pobj = NULL;
522   xmlXPathContextPtr xpath_ctxt = NULL;
523   char xpath[1024];
524   uuid_t checkid;
525
526   noit_conf_xml_xpath(NULL, &xpath_ctxt);
527   if(argc < 1) {
528     nc_printf(ncct, "requires one argument\n");
529     return -1;
530   }
531
532   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
533   if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, argv[0])) {
534     nc_printf(ncct, "could not find check '%s'\n", argv[0]);
535     return -1;
536   }
537   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
538   if(!pobj || pobj->type != XPATH_NODESET ||
539      xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
540     err = "no checks found";
541     goto bad;
542   }
543   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
544   for(i=0; i<cnt; i++) {
545     xmlNodePtr node;
546     char *uuid_conf;
547     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
548     uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
549     if(!uuid_conf || uuid_parse(uuid_conf, checkid)) {
550       nc_printf(ncct, "%s has invalid or missing UUID!\n",
551                 (char *)xmlGetNodePath(node) + strlen("/noit"));
552     }
553     else {
554       if(argc > 1) {
555         int j;
556         for(j=1;j<argc;j++)
557           xmlUnsetProp(node, (xmlChar *)argv[j]);
558       } else {
559         nc_printf(ncct, "descheduling %s\n", uuid_conf);
560         noit_poller_deschedule(checkid);
561         xmlUnlinkNode(node);
562       }
563       noit_conf_mark_changed();
564     }
565   }
566   if(argc > 1) {
567     noit_poller_process_checks(xpath);
568     noit_poller_reload(xpath);
569   }
570   nc_printf(ncct, "rebuilding causal map...\n");
571   noit_poller_make_causal_map();
572   if(pobj) xmlXPathFreeObject(pobj);
573   return 0;
574  bad:
575   if(pobj) xmlXPathFreeObject(pobj);
576   nc_printf(ncct, "%s\n", err);
577   return -1;
578 }
579 static int
580 noit_console_config_show(noit_console_closure_t ncct,
581                          int argc, char **argv,
582                          noit_console_state_t *state, void *closure) {
583   noit_hash_iter iter = NOIT_HASH_ITER_ZERO;
584   const char *k;
585   int klen;
586   void *data;
587   int i, cnt, titled = 0, cliplen = 0;
588   const char *path = "", *basepath = NULL;
589   char xpath[1024];
590   noit_conf_t_userdata_t *info = NULL;
591   noit_hash_table *config;
592   xmlXPathObjectPtr pobj = NULL;
593   xmlXPathContextPtr xpath_ctxt = NULL, current_ctxt;
594   xmlDocPtr master_config = NULL;
595   xmlNodePtr node = NULL;
596
597   noit_conf_xml_xpath(&master_config, &xpath_ctxt);
598   if(argc > 1) {
599     nc_printf(ncct, "too many arguments\n");
600     return -1;
601   }
602
603   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
604   if(info) path = basepath = info->path;
605   if(!info && argc == 0) {
606     nc_printf(ncct, "argument required when not in configuration mode\n");
607     return -1;
608   }
609
610   if(argc == 1) path = argv[0];
611   if(!basepath) basepath = path;
612
613   /* { / } is a special case */
614   if(!strcmp(basepath, "/")) basepath = "";
615   if(!strcmp(path, "/")) path = "";
616
617   if(!master_config) {
618     nc_printf(ncct, "no config\n");
619     return -1;
620   }
621
622   /* { / } is the only path that will end with a /
623    * in XPath { / / * } means something _entirely different than { / * }
624    * Ever notice how it is hard to describe xpath in C comments?
625    */
626   /* We don't want to show the root node */
627   cliplen = strlen("/noit/");
628
629   /* If we are in configuration mode
630    * and we are without an argument or the argument is absolute,
631    * clip the current path off */
632   if(info && (argc == 0 || path[0] != '/')) cliplen += strlen(basepath);
633   if(!path[0] || path[0] == '/') /* base only, or absolute path requested */
634     snprintf(xpath, sizeof(xpath), "/noit%s/@*", path);
635   else
636     snprintf(xpath, sizeof(xpath), "/noit%s/%s/@*", basepath, path);
637
638   current_ctxt = xpath_ctxt;
639   pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt);
640   if(!pobj || pobj->type != XPATH_NODESET) {
641     nc_printf(ncct, "no such object\n");
642     goto bad;
643   }
644   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
645   titled = 0;
646   for(i=0; i<cnt; i++) {
647     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
648     if(!strcmp((char *)node->name, "check")) continue;
649     if(node->children && node->children == xmlGetLastChild(node) &&
650       xmlNodeIsText(node->children)) {
651       if(!titled++) nc_printf(ncct, "== Section Settings ==\n");
652       nc_printf(ncct, "%s: %s\n", xmlGetNodePath(node) + cliplen,
653                 xmlXPathCastNodeToString(node->children));
654     }
655   }
656   xmlXPathFreeObject(pobj);
657
658   /* Print out all the config settings */
659   if(!path[0] || path[0] == '/') /* base only, or absolute path requested */
660     snprintf(xpath, sizeof(xpath), "/noit%s", path);
661   else
662     snprintf(xpath, sizeof(xpath), "/noit%s/%s", basepath, path);
663   pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt);
664   if(!pobj || pobj->type != XPATH_NODESET) {
665     nc_printf(ncct, "no such object\n");
666     goto bad;
667   }
668   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
669   if(cnt > 0) {
670     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
671     titled = 0;
672     config = noit_conf_get_hash(node, "config");
673     while(noit_hash_next(config, &iter, &k, &klen, &data)) {
674       if(!titled++) nc_printf(ncct, "== Section [Aggregated] Config ==\n");
675       nc_printf(ncct, "config::%s: %s\n", k, (const char *)data);
676     }
677     noit_hash_destroy(config, free, free);
678     free(config);
679   }
680   xmlXPathFreeObject(pobj);
681
682   /* _shorten string_ turning last { / @ * } to { / * } */
683   if(!path[0] || path[0] == '/') /* base only, or absolute path requested */
684     snprintf(xpath, sizeof(xpath), "/noit%s/*", path);
685   else
686     snprintf(xpath, sizeof(xpath), "/noit%s/%s/*", basepath, path);
687   pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt);
688   if(!pobj || pobj->type != XPATH_NODESET) {
689     nc_printf(ncct, "no such object\n");
690     goto bad;
691   }
692   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
693   titled = 0;
694   for(i=0; i<cnt; i++) {
695     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
696     if(!strcmp((char *)node->name, "check")) continue;
697     if(!strcmp((char *)node->name, "filterset")) continue;
698     if(!strcmp((char *)xmlGetNodePath(node) + cliplen, "config")) continue;
699     if(!(node->children && node->children == xmlGetLastChild(node) &&
700          xmlNodeIsText(node->children))) {
701       if(!titled++) nc_printf(ncct, "== Subsections ==\n");
702       nc_printf(ncct, "%s\n", xmlGetNodePath(node) + cliplen);
703     }
704   }
705
706   titled = 0;
707   for(i=0; i<cnt; i++) {
708     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
709     if(!strcmp((char *)node->name, "filterset")) {
710       xmlAttr *attr;
711       char *filter_name = NULL;
712       for(attr=node->properties; attr; attr = attr->next) {
713         if(!strcmp((char *)attr->name, "name"))
714           filter_name = (char *)xmlXPathCastNodeToString(attr->children);
715       }
716       if(filter_name) {
717         nc_printf(ncct, "filterset[@name=\"%s\"]\n", filter_name);
718         xmlFree(filter_name);
719       }
720       else nc_printf(ncct, "fitlerset\n");
721     }
722     else if(!strcmp((char *)node->name, "check")) {
723       int busted = 1;
724       xmlAttr *attr;
725       char *uuid_str = "undefined";
726
727       if(!titled++) nc_printf(ncct, "== Checks ==\n");
728
729       for(attr=node->properties; attr; attr = attr->next) {
730         if(!strcmp((char *)attr->name, "uuid"))
731           uuid_str = (char *)xmlXPathCastNodeToString(attr->children);
732       }
733       if(uuid_str) {
734         uuid_t checkid;
735         nc_printf(ncct, "check[@uuid=\"%s\"] ", uuid_str);
736         if(uuid_parse(uuid_str, checkid) == 0) {
737           noit_check_t *check;
738           check = noit_poller_lookup(checkid);
739           if(check) {
740             busted = 0;
741             nc_printf(ncct, "%s`%s`%s", check->target, check->module, check->name);
742           }
743         }
744       }
745       else
746         nc_printf(ncct, "%s ", xmlGetNodePath(node) + cliplen);
747       if(busted) nc_printf(ncct, "[check not in running system]");
748       nc_write(ncct, "\n", 1);
749     }
750   }
751   xmlXPathFreeObject(pobj);
752   return 0;
753  bad:
754   if(pobj) xmlXPathFreeObject(pobj);
755   return -1;
756 }
757
758 static char *
759 conf_t_check_prompt(EditLine *el) {
760   noit_console_closure_t ncct;
761   noit_conf_t_userdata_t *info;
762   noit_check_t *check;
763   static char *tl = "noit(conf)# ";
764   static char *pfmt = "noit(conf:%s%s%s)# ";
765
766   el_get(el, EL_USERDATA, (void *)&ncct);
767   if(!ncct) return tl;
768   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
769   if(!info) return tl;
770
771   check = noit_poller_lookup(info->current_check);
772   if(check &&
773      check->target && check->target[0] &&
774      check->name && check->name[0])
775     snprintf(info->prompt, sizeof(info->prompt),
776              pfmt, check->target, "`", check->name);
777   else {
778     char uuid_str[37];
779     uuid_unparse_lower(info->current_check, uuid_str);
780     snprintf(info->prompt, sizeof(info->prompt), pfmt, "[", uuid_str, "]");
781   }
782   return info->prompt;
783 }
784 static int
785 noit_conf_checks_reload(noit_console_closure_t ncct,
786                         int argc, char **argv,
787                         noit_console_state_t *state, void *closure) {
788   if(noit_conf_reload(ncct, argc, argv, state, closure)) return -1;
789   noit_poller_reload(NULL);
790   return 0;
791 }
792
793 static int
794 validate_attr_set_scope(noit_conf_t_userdata_t *info,
795                         struct _valid_attr_t *attrinfo) {
796   int len;
797   len = strlen(attrinfo->scope);
798   if(strncmp(info->path, attrinfo->scope, len) ||
799      (info->path[len] != '\0' && info->path[len] != '/')) {
800     return -1;
801   }
802   return 0;
803 }
804 static int
805 replace_config(noit_console_closure_t ncct,
806                noit_conf_t_userdata_t *info, const char *name,
807                const char *value) {
808   int i, cnt, rv = -1, active = 0;
809   xmlXPathObjectPtr pobj = NULL;
810   xmlXPathContextPtr xpath_ctxt = NULL;
811   xmlNodePtr node, confignode;
812   char xpath[1024], *path;
813
814   path = info->path;
815   if(!strcmp(path, "/")) path = "";
816
817   noit_conf_xml_xpath(NULL, &xpath_ctxt);
818
819   /* Only if checks will fixate this attribute shall we check for
820    * child <check> nodes.
821    * NOTE: this return nothing and "seems" okay if we are _in_
822    *       a <check> node.  That case is handled below.
823    */
824   snprintf(xpath, sizeof(xpath), "/noit/%s//check[@uuid]", path);
825   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
826   if(!pobj || pobj->type != XPATH_NODESET) goto out;
827   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
828   for(i=0; i<cnt; i++) {
829     uuid_t checkid;
830     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
831     if(noit_conf_get_uuid(node, "@uuid", checkid)) {
832       noit_check_t *check;
833       check = noit_poller_lookup(checkid);
834       if(check && NOIT_CHECK_LIVE(check)) active++;
835     }
836   }
837   if(pobj) xmlXPathFreeObject(pobj);
838
839   snprintf(xpath, sizeof(xpath), "/noit/%s", path);
840   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
841   if(!pobj || pobj->type != XPATH_NODESET) goto out;
842   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
843   if(cnt != 1) {
844     nc_printf(ncct, "Internal error: context node disappeared\n");
845     goto out;
846   }
847   node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
848   if(strcmp((const char *)node->name, "check")) {
849     uuid_t checkid;
850     /* Detect if  we are actually a <check> node and attempting to
851      * change something we shouldn't.
852      * This is the counterpart noted above.
853      */
854     if(noit_conf_get_uuid(node, "@uuid", checkid)) {
855       noit_check_t *check;
856       check = noit_poller_lookup(checkid);
857       if(NOIT_CHECK_LIVE(check)) active++;
858     }
859   }
860 #ifdef UNSAFE_RECONFIG
861   if(active) {
862     nc_printf(ncct, "Cannot set '%s', it would effect %d live check(s)\n",
863               name, active);
864     goto out;
865   }
866 #endif
867   if(pobj) xmlXPathFreeObject(pobj);
868
869   /* Here we want to remove /noit/path/config/name */
870   snprintf(xpath, sizeof(xpath), "/noit/%s/config/%s", path, name);
871   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
872   if(!pobj || pobj->type != XPATH_NODESET) goto out;
873   if(xmlXPathNodeSetGetLength(pobj->nodesetval) > 0) {
874     xmlNodePtr toremove;
875     toremove = xmlXPathNodeSetItem(pobj->nodesetval, 0);
876     xmlUnlinkNode(toremove);
877   }
878   /* TODO: if there are no more children of config, remove config? */
879   if(value) {
880     if(pobj) xmlXPathFreeObject(pobj);
881     /* He we create config if needed and place a child node under it */
882     snprintf(xpath, sizeof(xpath), "/noit/%s/config", path);
883     pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
884     if(!pobj || pobj->type != XPATH_NODESET) goto out;
885     if(xmlXPathNodeSetGetLength(pobj->nodesetval) == 0) {
886       if(pobj) xmlXPathFreeObject(pobj);
887       snprintf(xpath, sizeof(xpath), "/noit/%s", path);
888       pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
889       if(!pobj || pobj->type != XPATH_NODESET) goto out;
890       if(xmlXPathNodeSetGetLength(pobj->nodesetval) != 1) {
891         nc_printf(ncct, "Node disappeared from under you!\n");
892         goto out;
893       }
894       confignode = xmlNewChild(xmlXPathNodeSetItem(pobj->nodesetval, 0),
895                                NULL, (xmlChar *)"config", NULL);
896       if(confignode == NULL) {
897         nc_printf(ncct, "Error creating config child node.\n");
898         goto out;
899       }
900     }
901     else confignode = xmlXPathNodeSetItem(pobj->nodesetval, 0);
902
903     assert(confignode);
904     /* Now we create a child */
905     xmlNewChild(confignode, NULL, (xmlChar *)name, (xmlChar *)value);
906   }
907   noit_conf_mark_changed();
908   rv = 0;
909  out:
910   if(pobj) xmlXPathFreeObject(pobj);
911   return rv;
912 }
913 static int
914 replace_attr(noit_console_closure_t ncct,
915              noit_conf_t_userdata_t *info, struct _valid_attr_t *attrinfo,
916              const char *value) {
917   int i, cnt, rv = -1, active = 0;
918   xmlXPathObjectPtr pobj = NULL;
919   xmlXPathContextPtr xpath_ctxt = NULL;
920   xmlNodePtr node;
921   char xpath[1024], *path;
922
923   path = info->path;
924   if(!strcmp(path, "/")) path = "";
925
926   noit_conf_xml_xpath(NULL, &xpath_ctxt);
927   if(attrinfo->checks_fixate) {
928     /* Only if checks will fixate this attribute shall we check for
929      * child <check> nodes.
930      * NOTE: this return nothing and "seems" okay if we are _in_
931      *       a <check> node.  That case is handled below.
932      */
933     snprintf(xpath, sizeof(xpath), "/noit/%s//check[@uuid]", path);
934     pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
935     if(!pobj || pobj->type != XPATH_NODESET) goto out;
936     cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
937     for(i=0; i<cnt; i++) {
938       uuid_t checkid;
939       node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i);
940       if(noit_conf_get_uuid(node, "@uuid", checkid)) {
941         noit_check_t *check;
942         check = noit_poller_lookup(checkid);
943         if(check && NOIT_CHECK_LIVE(check)) active++;
944       }
945     }
946     if(pobj) xmlXPathFreeObject(pobj);
947   }
948   snprintf(xpath, sizeof(xpath), "/noit/%s", path);
949   pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
950   if(!pobj || pobj->type != XPATH_NODESET) goto out;
951   cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
952   if(cnt != 1) {
953     nc_printf(ncct, "Internal error: context node disappeared\n");
954     goto out;
955   }
956   node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
957   if(attrinfo->checks_fixate &&
958      !strcmp((const char *)node->name, "check")) {
959     uuid_t checkid;
960     /* Detect if  we are actually a <check> node and attempting to
961      * change something we shouldn't.
962      * This is the counterpart noted above.
963      */
964     if(noit_conf_get_uuid(node, "@uuid", checkid)) {
965       noit_check_t *check;
966       check = noit_poller_lookup(checkid);
967       if(check && NOIT_CHECK_LIVE(check)) active++;
968     }
969   }
970   if(active) {
971     nc_printf(ncct, "Cannot set '%s', it would effect %d live check(s)\n",
972               attrinfo->name, active);
973     goto out;
974   }
975   xmlUnsetProp(node, (xmlChar *)attrinfo->name);
976   if(value)
977     xmlSetProp(node, (xmlChar *)attrinfo->name, (xmlChar *)value);
978   noit_conf_mark_changed();
979   rv = 0;
980  out:
981   if(pobj) xmlXPathFreeObject(pobj);
982   return rv;
983 }
984 int
985 noit_conf_check_set_attr(noit_console_closure_t ncct,
986                          int argc, char **argv,
987                          noit_console_state_t *state, void *closure) {
988   struct _valid_attr_t *attrinfo = closure;
989   noit_conf_t_userdata_t *info;
990
991   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
992   if(!info || validate_attr_set_scope(info, attrinfo)) {
993     nc_printf(ncct, "'%s' attribute only valid in %s scope\n",
994               attrinfo->name, attrinfo->scope);
995     return -1;
996   }
997
998   if(argc != 1) {
999     nc_printf(ncct, "set requires exactly one value\n");
1000     return -1;
1001   }
1002   /* Okay, we have an attribute and it should be set/replaced on the
1003    * current path.
1004    */
1005   if(replace_attr(ncct, info, attrinfo, argv[0])) {
1006     return -1;
1007   }
1008
1009   /* So, we updated an attribute, so we need to reload all checks
1010    * that are descendent-or-self of this node.
1011    */
1012   if(!strncmp(info->path, "/checks", strlen("/checks")))
1013     refresh_subchecks(ncct, info);
1014   if(!strncmp(info->path, "/filtersets", strlen("/filtersets")))
1015     noit_refresh_filtersets(ncct, info);
1016   return 0;
1017 }
1018
1019 int
1020 noit_conf_check_unset_attr(noit_console_closure_t ncct,
1021                            int argc, char **argv,
1022                            noit_console_state_t *state, void *closure) {
1023   struct _valid_attr_t *attrinfo = closure;
1024   noit_conf_t_userdata_t *info;
1025
1026   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
1027   if(!info || validate_attr_set_scope(info, attrinfo)) {
1028     nc_printf(ncct, "'%s' attribute only valid in %s scope\n",
1029               attrinfo->name, attrinfo->scope);
1030     return -1;
1031   }
1032
1033   if(argc != 0) {
1034     nc_printf(ncct, "no arguments allowed to this command.\n");
1035     return -1;
1036   }
1037   /* Okay, we have an attribute and it should be set/replaced on the
1038    * current path.
1039    */
1040   if(replace_attr(ncct, info, attrinfo, NULL)) {
1041     return -1;
1042   }
1043
1044   /* So, we updated an attribute, so we need to reload all checks
1045    * that are descendent-or-self of this node.
1046    */
1047   if(!strncmp(info->path, "/checks", strlen("/checks")))
1048     refresh_subchecks(ncct, info);
1049   if(!strncmp(info->path, "/filterset", strlen("/filterest")))
1050     noit_refresh_filtersets(ncct, info);
1051   return 0;
1052 }
1053
1054 int
1055 noit_console_config_setconfig(noit_console_closure_t ncct,
1056                                 int argc, char **argv,
1057                                 noit_console_state_t *state, void *closure) {
1058   noit_conf_t_userdata_t *info;
1059
1060   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
1061
1062   if(argc != 2) {
1063     nc_printf(ncct, "two arguments required.\n");
1064     return -1;
1065   }
1066   /* Okay, we have an child name and it should be culled from
1067    * current path/config.
1068    */
1069   if(replace_config(ncct, info, argv[0], argv[1])) {
1070     return -1;
1071   }
1072
1073   /* So, we updated an attribute, so we need to reload all checks
1074    * that are descendent-or-self of this node.
1075    */
1076   refresh_subchecks(ncct, info);
1077   return 0;
1078 }
1079
1080 int
1081 noit_console_config_unsetconfig(noit_console_closure_t ncct,
1082                                 int argc, char **argv,
1083                                 noit_console_state_t *state, void *closure) {
1084   noit_conf_t_userdata_t *info;
1085
1086   info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA);
1087
1088   if(argc != 1) {
1089     nc_printf(ncct, "one argument required.\n");
1090     return -1;
1091   }
1092   /* Okay, we have an child name and it should be culled from
1093    * current path/config.
1094    */
1095   if(replace_config(ncct, info, argv[0], NULL)) {
1096     return -1;
1097   }
1098
1099   /* So, we updated an attribute, so we need to reload all checks
1100    * that are descendent-or-self of this node.
1101    */
1102   refresh_subchecks(ncct, info);
1103   return 0;
1104 }
1105
1106
1107 #define NEW_STATE(a) (a) = noit_console_state_alloc()
1108 #define ADD_CMD(a,cmd,func,ac,ss,c) \
1109   noit_console_state_add_cmd((a), \
1110     NCSCMD(cmd, func, ac, ss, c))
1111 #define DELEGATE_CMD(a,cmd,ac,ss) \
1112   noit_console_state_add_cmd((a), \
1113     NCSCMD(cmd, noit_console_state_delegate, ac, ss, NULL))
1114
1115 static
1116 void register_console_config_check_commands() {
1117   cmd_info_t *showcmd, *nocmd, *confcmd, *conftcmd, *conftnocmd, *lscmd;
1118   noit_console_state_t *tl, *_conf_t_check_state, *_unset_state,
1119                        *_attr_state, *_uattr_state;
1120
1121   tl = noit_console_state_initial();
1122   showcmd = noit_console_state_get_cmd(tl, "show");
1123   nocmd = noit_console_state_get_cmd(tl, "no");
1124   confcmd = noit_console_state_get_cmd(tl, "configure");
1125   conftcmd = noit_console_state_get_cmd(confcmd->dstate, "terminal");
1126   conftnocmd = noit_console_state_get_cmd(conftcmd->dstate, "no");
1127   lscmd = noit_console_state_get_cmd(conftcmd->dstate, "ls");
1128   lscmd->func = noit_console_config_show;
1129   /* attribute <attrname> <value> */
1130   NEW_STATE(_attr_state);
1131   noit_console_state_add_check_attrs(_attr_state, noit_conf_check_set_attr,
1132                                      "/checks");
1133  
1134   /* no attribute <attrname> <value> */
1135   NEW_STATE(_uattr_state);
1136   noit_console_state_add_check_attrs(_uattr_state, noit_conf_check_unset_attr,
1137                                      "/checks");
1138   NEW_STATE(_unset_state);
1139   DELEGATE_CMD(_unset_state, "attribute",
1140                noit_console_opt_delegate, _uattr_state);
1141   ADD_CMD(_unset_state, "config",
1142           noit_console_config_unsetconfig, NULL, NULL, NULL);
1143
1144   DELEGATE_CMD(conftnocmd->dstate, "attribute",
1145                noit_console_opt_delegate, _uattr_state);
1146   ADD_CMD(conftnocmd->dstate, "config",
1147           noit_console_config_unsetconfig, NULL, NULL, NULL);
1148   ADD_CMD(conftnocmd->dstate, "check",
1149           noit_console_config_nocheck, NULL, NULL, NULL);
1150  
1151   NEW_STATE(_conf_t_check_state);
1152   _conf_t_check_state->console_prompt_function = conf_t_check_prompt;
1153   DELEGATE_CMD(_conf_t_check_state, "attribute",
1154                noit_console_opt_delegate, _attr_state);
1155   DELEGATE_CMD(_conf_t_check_state, "no",
1156                noit_console_opt_delegate, _unset_state);
1157   ADD_CMD(_conf_t_check_state, "config",
1158           noit_console_config_setconfig, NULL, NULL, NULL);
1159   ADD_CMD(_conf_t_check_state, "status",
1160           noit_console_show_check, NULL, NULL, NULL);
1161   ADD_CMD(_conf_t_check_state, "exit",
1162           noit_console_config_cd, NULL, NULL, "..");
1163   ADD_CMD(_conf_t_check_state, "check",
1164           noit_console_check, noit_console_conf_check_opts,
1165           _conf_t_check_state, "..");
1166
1167   ADD_CMD(conftcmd->dstate, "config",
1168           noit_console_config_setconfig, NULL, NULL, NULL);
1169   ADD_CMD(conftcmd->dstate, "check",
1170           noit_console_check, noit_console_conf_check_opts,
1171           _conf_t_check_state, NULL);
1172
1173   ADD_CMD(showcmd->dstate, "check",
1174           noit_console_show_check, noit_console_check_opts, NULL, NULL);
1175
1176   ADD_CMD(tl, "watch",
1177           noit_console_watch_check, noit_console_check_opts, NULL, (void *)1);
1178
1179   ADD_CMD(nocmd->dstate, "watch",
1180           noit_console_watch_check, noit_console_check_opts, NULL, (void *)0);
1181
1182   DELEGATE_CMD(conftcmd->dstate, "attribute",
1183                noit_console_opt_delegate, _attr_state);
1184
1185   ADD_CMD(tl, "reload", noit_conf_checks_reload, NULL, NULL, NULL);
1186 }
1187
Note: See TracBrowser for help on using the browser.