Changeset d94c4d2a0febabfc7d914c1ff5ffc305f137b378
- Timestamp:
- 02/01/10 17:35:06 (3 years ago)
- git-parent:
- Files:
-
- src/stratcon_jlog_streamer.c (modified) (17 diffs)
- src/stratcond.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/stratcon_jlog_streamer.c
r35d80a0 rd94c4d2 778 778 void 779 779 stratcon_jlog_streamer_reload(const char *toplevel) { 780 if(!stratcon_datastore_get_enabled()) return; 780 781 stratcon_streamer_connection(toplevel, NULL, 781 782 stratcon_jlog_recv_handler, … … 791 792 void *closure) { 792 793 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 793 uuid_tkey_id;794 void *key_id; 794 795 int klen, n = 0, i; 795 796 void *vconn; … … 819 820 xmlDocPtr doc; 820 821 xmlNodePtr root; 822 noit_hash_table seen = NOIT_HASH_EMPTY; 821 823 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; 824 827 void *vconn; 825 828 noit_connection_ctx_t **ctxs; 829 noit_conf_section_t *noit_configs; 826 830 struct timeval now, diff, last; 831 xmlNodePtr node; 832 827 833 gettimeofday(&now, NULL); 828 834 … … 841 847 root = xmlNewDocNode(doc, NULL, (xmlChar *)"noits", NULL); 842 848 xmlDocSetRootElement(doc, root); 849 843 850 for(i=0; i<n; i++) { 844 851 char buff[256]; 845 852 const char *feedtype = "unknown", *state = "unknown"; 846 xmlNodePtr node;847 853 noit_connection_ctx_t *ctx = ctxs[i]; 848 854 jlog_streamer_ctx_t *jctx = ctx->consumer_ctx; … … 882 888 } 883 889 } 890 noit_hash_replace(&seen, strdup(ctx->remote_str), strlen(ctx->remote_str), 891 0, free, NULL); 884 892 xmlSetProp(node, (xmlChar *)"remote", (xmlChar *)ctx->remote_str); 885 893 feedtype = feed_type_to_str(ntohl(jctx->jlog_feed_cmd)); … … 938 946 free(ctxs); 939 947 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 940 970 noit_http_response_ok(restc->http_ctx, "text/xml"); 941 971 noit_http_response_xml(restc->http_ctx, doc); … … 945 975 } 946 976 static int 947 stratcon_add_noit(const char *target, unsigned short port) { 977 stratcon_add_noit(const char *target, unsigned short port, 978 const char *cn) { 948 979 int cnt; 949 980 char path[256]; 950 981 char port_str[6]; 951 982 noit_conf_section_t *noit_configs, parent; 952 xmlNodePtr newnoit ;983 xmlNodePtr newnoit, config, cnnode; 953 984 954 985 snprintf(path, sizeof(path), … … 956 987 noit_configs = noit_conf_get_sections(NULL, path, &cnt); 957 988 free(noit_configs); 958 if(cnt != 0) return 0;989 if(cnt != 0) return -1; 959 990 960 991 parent = noit_conf_get_section(NULL, "//noits"); 961 if(!parent) return 0;992 if(!parent) return -1; 962 993 snprintf(port_str, sizeof(port_str), "%d", port); 963 994 newnoit = xmlNewNode(NULL, (xmlChar *)"noit"); … … 965 996 xmlSetProp(newnoit, (xmlChar *)"port", (xmlChar *)port_str); 966 997 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 } 967 1005 if(stratcon_datastore_get_enabled()) 968 1006 stratcon_streamer_connection(NULL, target, … … 982 1020 stratcon_remove_noit(const char *target, unsigned short port) { 983 1021 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 984 uuid_tkey_id;985 int klen, n = 0, i, cnt = 0;1022 void *key_id; 1023 int klen, n = -1, i, cnt = 0; 986 1024 void *vconn; 987 1025 noit_connection_ctx_t **ctx; … … 998 1036 xmlUnlinkNode(noit_configs[i]); 999 1037 xmlFreeNode(noit_configs[i]); 1038 n = 0; 1000 1039 } 1001 1040 free(noit_configs); … … 1022 1061 rest_set_noit(noit_http_rest_closure_t *restc, 1023 1062 int npats, char **pats) { 1063 void *vcn; 1064 const char *cn = NULL; 1024 1065 noit_http_session_ctx *ctx = restc->http_ctx; 1025 1066 unsigned short port = 43191; … … 1027 1068 noit_http_response_server_error(ctx, "text/xml"); 1028 1069 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) 1030 1074 noit_http_response_ok(ctx, "text/xml"); 1031 1075 else … … 1045 1089 noit_http_response_server_error(ctx, "text/xml"); 1046 1090 if(npats == 2) port = atoi(pats[1]); 1047 if(stratcon_remove_noit(pats[0], port) )1091 if(stratcon_remove_noit(pats[0], port) >= 0) 1048 1092 noit_http_response_ok(ctx, "text/xml"); 1049 1093 else … … 1073 1117 else strlcpy(target, argv[0], sizeof(target)); 1074 1118 if(adding) { 1075 if(stratcon_add_noit(target, port )) {1119 if(stratcon_add_noit(target, port, NULL) >= 0) { 1076 1120 nc_printf(ncct, "Added noit at %s:%d\n", target, port); 1077 1121 } … … 1081 1125 } 1082 1126 else { 1083 if(stratcon_remove_noit(target, port) ) {1127 if(stratcon_remove_noit(target, port) >= 0) { 1084 1128 nc_printf(ncct, "Removed noit at %s:%d\n", target, port); 1085 1129 } … … 1125 1169 register_console_streamer_commands(); 1126 1170 stratcon_jlog_streamer_reload(toplevel); 1171 stratcon_streamer_connection(toplevel, "", NULL, NULL, NULL, NULL); 1127 1172 assert(noit_http_rest_register_auth( 1128 1173 "GET", "/noits/", "^show$", rest_show_noits, src/stratcond.c
r35d80a0 rd94c4d2 252 252 } 253 253 254 stratcon_jlog_streamer_init(APPNAME); 255 254 256 if(stratcon_iep_get_enabled()) 255 257 stratcon_iep_init(); 256 258 if(stratcon_datastore_get_enabled()) { 257 stratcon_jlog_streamer_init(APPNAME);258 259 /* Write our log out, and setup a watchdog to write it out on change. */ 259 260 stratcon_datastore_saveconfig(NULL);
