Changeset d94c4d2a0febabfc7d914c1ff5ffc305f137b378

Show
Ignore:
Timestamp:
02/01/10 17:35:06 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1265045706 +0000
git-parent:

[df5d2f09411fc779d39bc1fa5f3ff24ad0e5cff4]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1265045706 +0000
Message:

First attempt, refs #248

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/stratcon_jlog_streamer.c

    r35d80a0 rd94c4d2  
    778778void 
    779779stratcon_jlog_streamer_reload(const char *toplevel) { 
     780  if(!stratcon_datastore_get_enabled()) return; 
    780781  stratcon_streamer_connection(toplevel, NULL, 
    781782                               stratcon_jlog_recv_handler, 
     
    791792                            void *closure) { 
    792793  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
    793   uuid_t key_id; 
     794  void *key_id; 
    794795  int klen, n = 0, i; 
    795796  void *vconn; 
     
    819820  xmlDocPtr doc; 
    820821  xmlNodePtr root; 
     822  noit_hash_table seen = NOIT_HASH_EMPTY; 
    821823  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
    822   uuid_t key_id; 
    823   int klen, n = 0, i; 
     824  char path[256]; 
     825  void *key_id; 
     826  int klen, n = 0, i, di, cnt; 
    824827  void *vconn; 
    825828  noit_connection_ctx_t **ctxs; 
     829  noit_conf_section_t *noit_configs; 
    826830  struct timeval now, diff, last; 
     831  xmlNodePtr node; 
     832 
    827833  gettimeofday(&now, NULL); 
    828834 
     
    841847  root = xmlNewDocNode(doc, NULL, (xmlChar *)"noits", NULL); 
    842848  xmlDocSetRootElement(doc, root); 
     849 
    843850  for(i=0; i<n; i++) { 
    844851    char buff[256]; 
    845852    const char *feedtype = "unknown", *state = "unknown"; 
    846     xmlNodePtr node; 
    847853    noit_connection_ctx_t *ctx = ctxs[i]; 
    848854    jlog_streamer_ctx_t *jctx = ctx->consumer_ctx; 
     
    882888      } 
    883889    } 
     890    noit_hash_replace(&seen, strdup(ctx->remote_str), strlen(ctx->remote_str), 
     891                      0, free, NULL); 
    884892    xmlSetProp(node, (xmlChar *)"remote", (xmlChar *)ctx->remote_str); 
    885893    feedtype = feed_type_to_str(ntohl(jctx->jlog_feed_cmd)); 
     
    938946  free(ctxs); 
    939947 
     948  snprintf(path, sizeof(path), "//noits//noit"); 
     949  noit_configs = noit_conf_get_sections(NULL, path, &cnt); 
     950  for(di=0; di<cnt; di++) { 
     951    char address[64], port_str[32], remote_str[98]; 
     952    if(noit_conf_get_stringbuf(noit_configs[di], "self::node()/@address", 
     953                               address, sizeof(address))) { 
     954      void *v; 
     955      if(!noit_conf_get_stringbuf(noit_configs[di], "self::node()/@port", 
     956                                 port_str, sizeof(port_str))) 
     957        strlcpy(port_str, "43191", sizeof(port_str)); 
     958      snprintf(remote_str, sizeof(remote_str), "%s:%s", address, port_str); 
     959      if(!noit_hash_retrieve(&seen, remote_str, strlen(remote_str), &v)) { 
     960        node = xmlNewNode(NULL, (xmlChar *)"noit"); 
     961        xmlSetProp(node, (xmlChar *)"remote", (xmlChar *)remote_str); 
     962        xmlSetProp(node, (xmlChar *)"type", (xmlChar *)"durable/inactive"); 
     963        xmlAddChild(root, node); 
     964      } 
     965    } 
     966  } 
     967  free(noit_configs); 
     968  noit_hash_destroy(&seen, free, NULL); 
     969 
    940970  noit_http_response_ok(restc->http_ctx, "text/xml"); 
    941971  noit_http_response_xml(restc->http_ctx, doc); 
     
    945975} 
    946976static int 
    947 stratcon_add_noit(const char *target, unsigned short port) { 
     977stratcon_add_noit(const char *target, unsigned short port, 
     978                  const char *cn) { 
    948979  int cnt; 
    949980  char path[256]; 
    950981  char port_str[6]; 
    951982  noit_conf_section_t *noit_configs, parent; 
    952   xmlNodePtr newnoit
     983  xmlNodePtr newnoit, config, cnnode
    953984 
    954985  snprintf(path, sizeof(path), 
     
    956987  noit_configs = noit_conf_get_sections(NULL, path, &cnt); 
    957988  free(noit_configs); 
    958   if(cnt != 0) return 0
     989  if(cnt != 0) return -1
    959990 
    960991  parent = noit_conf_get_section(NULL, "//noits"); 
    961   if(!parent) return 0
     992  if(!parent) return -1
    962993  snprintf(port_str, sizeof(port_str), "%d", port); 
    963994  newnoit = xmlNewNode(NULL, (xmlChar *)"noit"); 
     
    965996  xmlSetProp(newnoit, (xmlChar *)"port", (xmlChar *)port_str); 
    966997  xmlAddChild(parent, newnoit); 
     998  if(cn) { 
     999    config = xmlNewNode(NULL, (xmlChar *)"config"); 
     1000    cnnode = xmlNewNode(NULL, (xmlChar *)"cn"); 
     1001    xmlNodeAddContent(cnnode, (xmlChar *)cn); 
     1002    xmlAddChild(config, cnnode); 
     1003    xmlAddChild(newnoit, config); 
     1004  } 
    9671005  if(stratcon_datastore_get_enabled()) 
    9681006    stratcon_streamer_connection(NULL, target, 
     
    9821020stratcon_remove_noit(const char *target, unsigned short port) { 
    9831021  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
    984   uuid_t key_id; 
    985   int klen, n = 0, i, cnt = 0; 
     1022  void *key_id; 
     1023  int klen, n = -1, i, cnt = 0; 
    9861024  void *vconn; 
    9871025  noit_connection_ctx_t **ctx; 
     
    9981036    xmlUnlinkNode(noit_configs[i]); 
    9991037    xmlFreeNode(noit_configs[i]); 
     1038    n = 0; 
    10001039  } 
    10011040  free(noit_configs); 
     
    10221061rest_set_noit(noit_http_rest_closure_t *restc, 
    10231062              int npats, char **pats) { 
     1063  void *vcn; 
     1064  const char *cn = NULL; 
    10241065  noit_http_session_ctx *ctx = restc->http_ctx; 
    10251066  unsigned short port = 43191; 
     
    10271068    noit_http_response_server_error(ctx, "text/xml"); 
    10281069  if(npats == 2) port = atoi(pats[1]); 
    1029   if(stratcon_add_noit(pats[0], port)) 
     1070  noit_http_process_querystring(&ctx->req); 
     1071  if(noit_hash_retrieve(&ctx->req.querystring, "cn", 2, &vcn)) 
     1072    cn = vcn; 
     1073  if(stratcon_add_noit(pats[0], port, cn) >= 0) 
    10301074    noit_http_response_ok(ctx, "text/xml"); 
    10311075  else 
     
    10451089    noit_http_response_server_error(ctx, "text/xml"); 
    10461090  if(npats == 2) port = atoi(pats[1]); 
    1047   if(stratcon_remove_noit(pats[0], port)
     1091  if(stratcon_remove_noit(pats[0], port) >= 0
    10481092    noit_http_response_ok(ctx, "text/xml"); 
    10491093  else 
     
    10731117  else strlcpy(target, argv[0], sizeof(target)); 
    10741118  if(adding) { 
    1075     if(stratcon_add_noit(target, port)) { 
     1119    if(stratcon_add_noit(target, port, NULL) >= 0) { 
    10761120      nc_printf(ncct, "Added noit at %s:%d\n", target, port); 
    10771121    } 
     
    10811125  } 
    10821126  else { 
    1083     if(stratcon_remove_noit(target, port)) { 
     1127    if(stratcon_remove_noit(target, port) >= 0) { 
    10841128      nc_printf(ncct, "Removed noit at %s:%d\n", target, port); 
    10851129    } 
     
    11251169  register_console_streamer_commands(); 
    11261170  stratcon_jlog_streamer_reload(toplevel); 
     1171  stratcon_streamer_connection(toplevel, "", NULL, NULL, NULL, NULL); 
    11271172  assert(noit_http_rest_register_auth( 
    11281173    "GET", "/noits/", "^show$", rest_show_noits, 
  • src/stratcond.c

    r35d80a0 rd94c4d2  
    252252  } 
    253253 
     254  stratcon_jlog_streamer_init(APPNAME); 
     255 
    254256  if(stratcon_iep_get_enabled()) 
    255257    stratcon_iep_init(); 
    256258  if(stratcon_datastore_get_enabled()) { 
    257     stratcon_jlog_streamer_init(APPNAME); 
    258259    /* Write our log out, and setup a watchdog to write it out on change. */ 
    259260    stratcon_datastore_saveconfig(NULL);