[Reconnoiter-devel] [reconnoiter commit] r844 - trunk/src

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Wed Sep 16 10:59:30 EDT 2009


Author: jesus
Date: 2009-09-16 10:59:30 -0400 (Wed, 16 Sep 2009)
New Revision: 844

Modified:
   trunk/src/noit_check_rest.c
   trunk/src/noit_rest.c
   trunk/src/noit_rest.h
Log:
support check deletes, refs #171

Modified: trunk/src/noit_check_rest.c
===================================================================
--- trunk/src/noit_check_rest.c	2009-09-16 05:01:19 UTC (rev 843)
+++ trunk/src/noit_check_rest.c	2009-09-16 14:59:30 UTC (rev 844)
@@ -44,6 +44,7 @@
 #include "noit_conf.h"
 #include "noit_conf_private.h"
 
+#define FAIL(a) do { error = (a); goto error; } while(0)
 #define UUID_REGEX "[0-9a-fA-F]{4}(?:[0-9a-fA-F]{4}-){4}[0-9a-fA-F]{12}"
 
 struct rest_xml_payload {
@@ -380,6 +381,71 @@
   return start;
 }
 static int
+rest_delete_check(noit_http_rest_closure_t *restc,
+                  int npats, char **pats) {
+  noit_http_session_ctx *ctx = restc->http_ctx;
+  xmlXPathObjectPtr pobj = NULL;
+  xmlXPathContextPtr xpath_ctxt = NULL;
+  xmlNodePtr node;
+  uuid_t checkid;
+  noit_check_t *check;
+  const char *error;
+  char xpath[1024], *uuid_conf;
+  int rv, cnt;
+  noit_boolean exists = noit_false;
+
+  if(npats != 2) goto error;
+
+  if(uuid_parse(pats[1], checkid)) goto error;
+  check = noit_poller_lookup(checkid);
+  if(check)
+    exists = noit_true;
+
+  rv = noit_check_xpath(xpath, sizeof(xpath), pats[0], pats[1]);
+  if(rv == 0) FAIL("uuid not valid");
+  if(rv < 0) FAIL("Tricky McTrickster... No");
+
+  noit_conf_xml_xpath(NULL, &xpath_ctxt);
+  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt);
+  if(!pobj || pobj->type != XPATH_NODESET ||
+     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {
+    if(exists) FAIL("uuid not yours");
+    goto not_found;
+  }
+  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
+  if(cnt != 1) FAIL("internal error, |checkid| > 1");
+  node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
+  uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
+  if(!uuid_conf || strcasecmp(uuid_conf, pats[1]))
+    FAIL("internal error uuid");
+
+  /* delete this here */
+  noit_poller_deschedule(check->checkid);
+  xmlUnlinkNode(node);
+  xmlFreeNode(node);
+  if(noit_conf_write_file(NULL) != 0)
+    noitL(noit_error, "local config write failed\n");
+  noit_conf_mark_changed();
+  noit_http_response_ok(ctx, "text/html");
+  noit_http_response_end(ctx);
+  goto cleanup;
+
+ not_found:
+  noit_http_response_not_found(ctx, "text/html");
+  noit_http_response_end(ctx);
+  goto cleanup;
+
+ error:
+  noit_http_response_server_error(ctx, "text/html");
+  noit_http_response_end(ctx);
+  goto cleanup;
+
+ cleanup:
+  if(pobj) xmlXPathFreeObject(pobj);
+  return 0;
+}
+
+static int
 rest_set_check(noit_http_rest_closure_t *restc,
                int npats, char **pats) {
   noit_http_session_ctx *ctx = restc->http_ctx;
@@ -397,8 +463,6 @@
 
   if(npats != 2) goto error;
 
-#define FAIL(a) do { error = (a); goto error; } while(0)
-
   if(restc->call_closure == NULL) {
     rxc = restc->call_closure = calloc(1, sizeof(*rxc));
     restc->call_closure_free = rest_xml_payload_free;
@@ -475,6 +539,7 @@
     char *target, *name, *module;
     xmlNodePtr a;
     noit_check_t *ocheck;
+
     cnt = xmlXPathNodeSetGetLength(pobj->nodesetval);
     if(cnt != 1) FAIL("internal error, |checkid| > 1");
     node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0);
@@ -549,5 +614,11 @@
     "^set(/.*)(?<=/)(" UUID_REGEX ")$",
     rest_set_check
   ) == 0);
+  assert(noit_http_rest_register(
+    "DELETE",
+    "/checks/",
+    "^delete(/.*)(?<=/)(" UUID_REGEX ")$",
+    rest_delete_check
+  ) == 0);
 }
 

Modified: trunk/src/noit_rest.c
===================================================================
--- trunk/src/noit_rest.c	2009-09-16 05:01:19 UTC (rev 843)
+++ trunk/src/noit_rest.c	2009-09-16 14:59:30 UTC (rev 844)
@@ -222,6 +222,9 @@
       case NOIT_CONTROL_HEAD:
         primer = "HEAD";
         break;
+      case NOIT_CONTROL_DELETE:
+        primer = "DELE";
+        break;
       default:
         goto socket_error;
     }
@@ -241,5 +244,8 @@
   noit_control_dispatch_delegate(noit_control_dispatch,
                                  NOIT_CONTROL_POST,
                                  noit_http_rest_handler);
+  noit_control_dispatch_delegate(noit_control_dispatch,
+                                 NOIT_CONTROL_DELETE,
+                                 noit_http_rest_handler);
 }
 

Modified: trunk/src/noit_rest.h
===================================================================
--- trunk/src/noit_rest.h	2009-09-16 05:01:19 UTC (rev 843)
+++ trunk/src/noit_rest.h	2009-09-16 14:59:30 UTC (rev 844)
@@ -37,9 +37,10 @@
 #ifndef NOIT_REST_H
 #define NOIT_REST_H
 
-#define NOIT_CONTROL_GET  0x47455420
-#define NOIT_CONTROL_HEAD 0x48454144
-#define NOIT_CONTROL_POST 0x504f5354
+#define NOIT_CONTROL_GET    0x47455420 /* "GET " */
+#define NOIT_CONTROL_HEAD   0x48454144 /* "HEAD" */
+#define NOIT_CONTROL_POST   0x504f5354 /* "POST" */
+#define NOIT_CONTROL_DELETE 0x44454c45 /* "DELE" */
 
 typedef struct noit_http_rest_closure noit_http_rest_closure_t;
 



More information about the Reconnoiter-devel mailing list