static int noit_console_version(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *dstate, void *unused) { char buff[256]; noit_build_version(buff, sizeof(buff)); nc_printf(ncct, "version: %s\n", buff); return 0; }
static void selfcheck_log_results(noit_module_t *self, noit_check_t *check) { char buff[128]; u_int64_t u64; int64_t s64; int32_t s32; struct threadq_crutch crutch; struct timeval duration, epoch, diff; selfcheck_info_t *ci = check->closure; crutch.check = check; noit_check_stats_clear(check, &check->stats.inprogress); gettimeofday(&check->stats.inprogress.whence, NULL); sub_timeval(check->stats.inprogress.whence, check->last_fire_time, &duration); check->stats.inprogress.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; check->stats.inprogress.available = NP_UNAVAILABLE; check->stats.inprogress.state = NP_BAD; if(ci->timed_out) check->stats.inprogress.status = "timeout"; else { check->stats.inprogress.available = NP_AVAILABLE; check->stats.inprogress.state = NP_GOOD; check->stats.inprogress.status = "ok"; } /* Set all the metrics here */ s64 = (int64_t)ci->logsize; noit_stats_set_metric(check, &check->stats.inprogress, "feed_bytes", METRIC_INT64, &s64); s32 = noit_poller_check_count(); noit_stats_set_metric(check, &check->stats.inprogress, "check_cnt", METRIC_INT32, &s32); s32 = noit_poller_transient_check_count(); noit_stats_set_metric(check, &check->stats.inprogress, "transient_cnt", METRIC_INT32, &s32); if(eventer_get_epoch(&epoch)) s64 = 0; else { sub_timeval(check->stats.inprogress.whence, epoch, &diff); s64 = diff.tv_sec; } noit_stats_set_metric(check, &check->stats.inprogress, "uptime", METRIC_INT64, &s64); eventer_jobq_process_each(jobq_thread_helper, &crutch); noit_build_version(buff, sizeof(buff)); noit_stats_set_metric(check, &check->stats.inprogress, "version", METRIC_STRING, buff); u64 = noit_check_completion_count(); noit_stats_set_metric(check, &check->stats.inprogress, "checks_run", METRIC_UINT64, &u64); /* feed pull info */ noit_jlog_foreach_feed_stats(selfcheck_feed_details, &crutch); noit_check_set_stats(check, &check->stats.inprogress); noit_check_stats_clear(check, &check->stats.inprogress); }
static int noit_console_version(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *dstate, void *unused) { char buff[256]; struct utsname utsn; nc_printf(ncct, "build sysname:\t%s\nbuild nodename:\t%s\n" "build release:\t%s\nbuild version:\t%s\n" "build machine:\t%s\n", UNAME_S, UNAME_N, UNAME_R, UNAME_V, UNAME_M); if(uname(&utsn) < 0) nc_printf(ncct, "run:\terror; %s\n", strerror(errno)); else nc_printf(ncct, "run sysname:\t%s\nrun nodename:\t%s\n" "run release:\t%s\nrun version:\t%s\n" "run machine:\t%s\n", utsn.sysname, utsn.nodename, utsn.release, utsn.version, utsn.machine); nc_printf(ncct, "bitwidth:\t%dbit\n", (int)sizeof(void *)*8); noit_build_version(buff, sizeof(buff)); nc_printf(ncct, "version:\t%s\n", buff); return 0; }
static int child_main() { char conf_str[1024]; char stratcon_version[80]; mtev_watchdog_child_heartbeat(); /* Next (re)load the configs */ if(mtev_conf_load(config_file) == -1) { fprintf(stderr, "Cannot load config: '%s'\n", config_file); exit(2); } mtev_log_reopen_all(); mtevL(noit_notice, "process starting: %d\n", (int)getpid()); mtev_log_go_asynch(); /* Lastly, run through all other system inits */ if(!mtev_conf_get_stringbuf(NULL, "/" APPNAME "/eventer/@implementation", conf_str, sizeof(conf_str))) { mtevL(noit_stderr, "Cannot find '%s' in configuration\n", "/" APPNAME "/eventer/@implementation"); exit(2); } if(eventer_choose(conf_str) == -1) { mtevL(noit_stderr, "Cannot choose eventer %s\n", conf_str); exit(2); } if(configure_eventer() != 0) { mtevL(noit_stderr, "Cannot configure eventer\n"); exit(2); } if(eventer_init() == -1) { mtevL(noit_stderr, "Cannot init eventer %s\n", conf_str); exit(2); } /* rotation init requires, eventer_init() */ mtev_conf_log_init_rotate(APPNAME, mtev_false); mtev_watchdog_child_eventer_heartbeat(); mtev_console_init(APPNAME); mtev_console_conf_init(); mtev_http_rest_init(); mtev_reverse_socket_init(reverse_prefix, reverse_prefix_cns); mtev_reverse_socket_acl(mtev_reverse_socket_denier); mtev_events_rest_init(); stratcon_realtime_http_init(APPNAME); mtev_capabilities_listener_init(); noit_build_version(stratcon_version, sizeof(stratcon_version)); mtev_capabilities_add_feature("stratcon", stratcon_version); mtev_listener_init(APPNAME); mtev_dso_init(); mtev_dso_post_init(); if(strict_module_load && mtev_dso_load_failures() > 0) { mtevL(noit_stderr, "Failed to load some modules and -M given.\n"); exit(2); } if(stratcon_datastore_get_enabled()) stratcon_datastore_init(); /* Drop privileges */ mtev_conf_security_init(APPNAME, droptouser, droptogroup, chrootpath); stratcon_jlog_streamer_init(APPNAME); if(stratcon_iep_get_enabled()) stratcon_iep_init(); if(stratcon_datastore_get_enabled()) { /* Write our log out, and setup a watchdog to write it out on change. */ stratcon_datastore_saveconfig(NULL); mtev_conf_coalesce_changes(10); /* 10 seconds of no changes before we write */ } else mtev_conf_coalesce_changes(INT_MAX); mtev_conf_watch_and_journal_watchdog(stratcon_datastore_saveconfig, NULL); eventer_loop(); return 0; }
static void noit_capabilities_tobuff(noit_capsvc_closure_t *cl, eventer_func_t curr) { const char **mod_names; struct utsname utsn; char vbuff[128], bwstr[4]; noit_hash_table *lc; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen, i, nmods; void *data; struct timeval now; xmlDocPtr xmldoc; xmlNodePtr root, cmds, bi, ri, mods, feat; /* fill out capabilities */ /* Create an XML Document */ xmldoc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)"noit_capabilities", NULL); xmlDocSetRootElement(xmldoc, root); /* Fill in the document */ noit_build_version(vbuff, sizeof(vbuff)); xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff); snprintf(bwstr, sizeof(bwstr), "%d", (int)sizeof(void *)*8); /* Build info */ bi = xmlNewNode(NULL, (xmlChar *)"unameBuild"); xmlSetProp(bi, (xmlChar *)"bitwidth", (xmlChar *)bwstr); xmlAddChild(root, bi); xmlNewTextChild(bi, NULL, (xmlChar *)"sysname", (xmlChar *)UNAME_S); xmlNewTextChild(bi, NULL, (xmlChar *)"nodename", (xmlChar *)UNAME_N); xmlNewTextChild(bi, NULL, (xmlChar *)"release", (xmlChar *)UNAME_R); xmlNewTextChild(bi, NULL, (xmlChar *)"version", (xmlChar *)UNAME_V); xmlNewTextChild(bi, NULL, (xmlChar *)"machine", (xmlChar *)UNAME_M); /* Run info */ ri = xmlNewNode(NULL, (xmlChar *)"unameRun"); xmlSetProp(ri, (xmlChar *)"bitwidth", (xmlChar *)bwstr); xmlAddChild(root, ri); if(uname(&utsn)) { xmlNewTextChild(ri, NULL, (xmlChar *)"error", (xmlChar *)strerror(errno)); } else { xmlNewTextChild(ri, NULL, (xmlChar *)"sysname", (xmlChar *)utsn.sysname); xmlNewTextChild(ri, NULL, (xmlChar *)"nodename", (xmlChar *)utsn.nodename); xmlNewTextChild(ri, NULL, (xmlChar *)"release", (xmlChar *)utsn.release); xmlNewTextChild(ri, NULL, (xmlChar *)"version", (xmlChar *)utsn.version); xmlNewTextChild(ri, NULL, (xmlChar *)"machine", (xmlChar *)utsn.machine); } /* features */ feat = xmlNewNode(NULL, (xmlChar *)"features"); xmlAddChild(root, feat); if(features.size) { noit_hash_iter iter2 = NOIT_HASH_ITER_ZERO; void *vfv; const char *f; int flen; while(noit_hash_next(&features, &iter2, &f, &flen, &vfv)) { xmlNodePtr featnode; featnode = xmlNewNode(NULL, (xmlChar *)"feature"); xmlSetProp(featnode, (xmlChar *)"name", (xmlChar *)f); if(vfv) xmlSetProp(featnode, (xmlChar *)"version", (xmlChar *)vfv); xmlAddChild(feat, featnode); } } /* time (poor man's time check) */ gettimeofday(&now, NULL); snprintf(vbuff, sizeof(vbuff), "%llu.%03d", (unsigned long long)now.tv_sec, (int)(now.tv_usec / 1000)); xmlNewTextChild(root, NULL, (xmlChar *)"current_time", (xmlChar *)vbuff); cmds = xmlNewNode(NULL, (xmlChar *)"services"); xmlAddChild(root, cmds); lc = noit_listener_commands(); while(noit_hash_next(lc, &iter, &k, &klen, &data)) { xmlNodePtr cnode; char hexcode[11]; const char *name; eventer_func_t *f = (eventer_func_t *)k; noit_hash_table *sc = (noit_hash_table *)data; noit_hash_iter sc_iter = NOIT_HASH_ITER_ZERO; const char *sc_k; int sc_klen; void *sc_data; name = eventer_name_for_callback(*f); cnode = xmlNewNode(NULL, (xmlChar *)"service"); xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); if(*f == curr) xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true"); xmlAddChild(cmds, cnode); while(noit_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { xmlNodePtr scnode; char *name_copy, *version = NULL; eventer_func_t *f = (eventer_func_t *)sc_data; snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); name = eventer_name_for_callback(*f); name_copy = strdup(name ? name : "[[unknown]]"); version = strchr(name_copy, '/'); if(version) *version++ = '\0'; scnode = xmlNewNode(NULL, (xmlChar *)"command"); xmlSetProp(scnode, (xmlChar *)"name", (xmlChar *)name_copy); if(version) xmlSetProp(scnode, (xmlChar *)"version", (xmlChar *)version); xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode); xmlAddChild(cnode, scnode); free(name_copy); } } mods = xmlNewNode(NULL, (xmlChar *)"modules"); xmlAddChild(root, mods); #define list_modules(func, name) do { \ nmods = func(&mod_names); \ for(i=0; i<nmods; i++) { \ xmlNodePtr pnode; \ pnode = xmlNewNode(NULL, (xmlChar *)"module"); \ xmlSetProp(pnode, (xmlChar *)"type", (xmlChar *)name); \ xmlSetProp(pnode, (xmlChar *)"name", (xmlChar *)mod_names[i]); \ xmlAddChild(mods, pnode); \ } \ if(mod_names) free(mod_names); \ } while(0) list_modules(noit_module_list_loaders, "loader"); list_modules(noit_module_list_modules, "module"); list_modules(noit_module_list_generics, "generic"); /* Write it out to a buffer and copy it for writing */ cl->buff = noit_xmlSaveToBuffer(xmldoc); cl->towrite = strlen(cl->buff); /* Clean up after ourselves */ xmlFreeDoc(xmldoc); }
static void noit_capabilities_tobuff_json(noit_capsvc_closure_t *cl, eventer_func_t curr) { const char **mod_names; struct utsname utsn; char vbuff[128]; noit_hash_table *lc; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen, i, nmods; void *data; struct timeval now; struct json_object *doc; struct json_object *svcs, *bi, *ri, *mods, *feat; /* fill out capabilities */ /* Create an XML Document */ doc = json_object_new_object(); /* Fill in the document */ noit_build_version(vbuff, sizeof(vbuff)); json_object_object_add(doc, "version", json_object_new_string(vbuff)); /* Build info */ bi = json_object_new_object(); json_object_object_add(bi, "bitwidth", json_object_new_int(sizeof(void *)*8)); json_object_object_add(bi, "sysname", json_object_new_string(UNAME_S)); json_object_object_add(bi, "nodename", json_object_new_string(UNAME_N)); json_object_object_add(bi, "release", json_object_new_string(UNAME_R)); json_object_object_add(bi, "version", json_object_new_string(UNAME_V)); json_object_object_add(bi, "machine", json_object_new_string(UNAME_M)); json_object_object_add(doc, "unameBuild", bi); /* Run info */ ri = json_object_new_object(); json_object_object_add(ri, "bitwidth", json_object_new_int(sizeof(void *)*8)); if(uname(&utsn)) { json_object_object_add(ri, "error", json_object_new_string(strerror(errno))); } else { json_object_object_add(ri, "sysname", json_object_new_string(utsn.sysname)); json_object_object_add(ri, "nodename", json_object_new_string(utsn.nodename)); json_object_object_add(ri, "release", json_object_new_string(utsn.release)); json_object_object_add(ri, "version", json_object_new_string(utsn.version)); json_object_object_add(ri, "machine", json_object_new_string(utsn.machine)); } json_object_object_add(doc, "unameRun", ri); /* features */ feat = json_object_new_object(); if(features.size) { noit_hash_iter iter2 = NOIT_HASH_ITER_ZERO; void *vfv; const char *f; int flen; while(noit_hash_next(&features, &iter2, &f, &flen, &vfv)) { struct json_object *featnode; featnode = json_object_new_object(); if(vfv) json_object_object_add(featnode, "version", json_object_new_string(vfv)); json_object_object_add(feat, f, featnode); } } json_object_object_add(doc, "features", feat); /* time (poor man's time check) */ gettimeofday(&now, NULL); snprintf(vbuff, sizeof(vbuff), "%llu%03d", (unsigned long long)now.tv_sec, (int)(now.tv_usec / 1000)); json_object_object_add(doc, "current_time", json_object_new_string(vbuff)); svcs = json_object_new_object(); lc = noit_listener_commands(); while(noit_hash_next(lc, &iter, &k, &klen, &data)) { struct json_object *cnode, *cmds; char hexcode[11]; const char *name; eventer_func_t *f = (eventer_func_t *)k; noit_hash_table *sc = (noit_hash_table *)data; noit_hash_iter sc_iter = NOIT_HASH_ITER_ZERO; const char *sc_k; int sc_klen; void *sc_data; name = eventer_name_for_callback(*f); cnode = json_object_new_object(); if(klen == 8) snprintf(hexcode, sizeof(hexcode), "0x%0llx", (unsigned long long int)(vpsized_uint)**f); else snprintf(hexcode, sizeof(hexcode), "0x%0x", (unsigned int)(vpsized_uint)**f); json_object_object_add(svcs, hexcode, cnode); if(name) json_object_object_add(cnode, name, json_object_new_string(name)); cmds = json_object_new_object(); json_object_object_add(cnode, "commands", cmds); while(noit_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { struct json_object *scnode; char *name_copy, *version = NULL; eventer_func_t *f = (eventer_func_t *)sc_data; scnode = json_object_new_object(); snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); name = eventer_name_for_callback(*f); name_copy = strdup(name ? name : "[[unknown]]"); version = strchr(name_copy, '/'); if(version) *version++ = '\0'; json_object_object_add(scnode, "name", json_object_new_string(name_copy)); if(version) json_object_object_add(scnode, "version", json_object_new_string(version)); json_object_object_add(cmds, hexcode, scnode); free(name_copy); } } json_object_object_add(doc, "services", svcs); mods = json_object_new_object(); #define list_modules_json(func, name) do { \ nmods = func(&mod_names); \ for(i=0; i<nmods; i++) { \ struct json_object *pnode; \ pnode = json_object_new_object(); \ json_object_object_add(pnode, "type", json_object_new_string(name)); \ json_object_object_add(mods, mod_names[i], pnode); \ } \ if(mod_names) free(mod_names); \ } while(0) list_modules_json(noit_module_list_loaders, "loader"); list_modules_json(noit_module_list_modules, "module"); list_modules_json(noit_module_list_generics, "generic"); json_object_object_add(doc, "modules", mods); /* Write it out to a buffer and copy it for writing */ cl->buff = strdup(json_object_to_json_string(doc)); cl->towrite = strlen(cl->buff); /* Clean up after ourselves */ json_object_put(doc); }
static void noit_capabilities_tobuff(noit_capsvc_closure_t *cl, eventer_func_t curr) { char vbuff[128]; noit_hash_table *lc; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; struct timeval now; xmlDocPtr xmldoc; xmlNodePtr root, cmds; /* fill out capabilities */ /* Create an XML Document */ xmldoc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)"noit_capabilities", NULL); xmlDocSetRootElement(xmldoc, root); /* Fill in the document */ noit_build_version(vbuff, sizeof(vbuff)); xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff); /* time (poor man's time check) */ gettimeofday(&now, NULL); snprintf(vbuff, sizeof(vbuff), "%llu.%03d", (unsigned long long)now.tv_sec, (int)(now.tv_usec / 1000)); xmlNewTextChild(root, NULL, (xmlChar *)"current_time", (xmlChar *)vbuff); cmds = xmlNewNode(NULL, (xmlChar *)"services"); xmlAddChild(root, cmds); lc = noit_listener_commands(); while(noit_hash_next(lc, &iter, &k, &klen, &data)) { xmlNodePtr cnode; char hexcode[11]; const char *name; eventer_func_t *f = (eventer_func_t *)k; noit_hash_table *sc = (noit_hash_table *)data; noit_hash_iter sc_iter = NOIT_HASH_ITER_ZERO; const char *sc_k; int sc_klen; void *sc_data; name = eventer_name_for_callback(*f); cnode = xmlNewNode(NULL, (xmlChar *)"service"); xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); if(*f == curr) xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true"); xmlAddChild(cmds, cnode); while(noit_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { xmlNodePtr scnode; char *name_copy, *version = NULL; eventer_func_t *f = (eventer_func_t *)sc_data; snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); name = eventer_name_for_callback(*f); name_copy = strdup(name ? name : "[[unknown]]"); version = strchr(name_copy, '/'); if(version) *version++ = '\0'; scnode = xmlNewNode(NULL, (xmlChar *)"command"); xmlSetProp(scnode, (xmlChar *)"name", (xmlChar *)name_copy); if(version) xmlSetProp(scnode, (xmlChar *)"version", (xmlChar *)version); xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode); xmlAddChild(cnode, scnode); free(name_copy); } } /* Write it out to a buffer and copy it for writing */ cl->buff = noit_xmlSaveToBuffer(xmldoc); cl->towrite = strlen(cl->buff); /* Clean up after ourselves */ xmlFreeDoc(xmldoc); }
int noit_capabilities_handler(eventer_t e, int mask, void *closure, struct timeval *now) { int newmask = EVENTER_WRITE | EVENTER_EXCEPTION; acceptor_closure_t *ac = closure; noit_capsvc_closure_t *cl = ac->service_ctx; if(mask & EVENTER_EXCEPTION) { socket_error: /* Exceptions cause us to simply snip the connection */ cleanup_shutdown: eventer_remove_fd(e->fd); e->opset->close(e->fd, &newmask, e); if(cl) { if(cl->buff) free(cl->buff); free(cl); } if(ac) acceptor_closure_free(ac); return 0; } if(!ac->service_ctx) { char vbuff[128]; noit_hash_table *lc; noit_hash_iter iter = NOIT_HASH_ITER_ZERO; const char *k; int klen; void *data; xmlDocPtr xmldoc; xmlNodePtr root, cmds; cl = ac->service_ctx = calloc(1, sizeof(*cl)); /* fill out capabilities */ noit_build_version(vbuff, sizeof(vbuff)); /* Create an XML Document */ xmldoc = xmlNewDoc((xmlChar *)"1.0"); root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)"noit_capabilities", NULL); xmlDocSetRootElement(xmldoc, root); /* Fill in the document */ xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff); cmds = xmlNewNode(NULL, (xmlChar *)"services"); xmlAddChild(root, cmds); lc = noit_listener_commands(); while(noit_hash_next(lc, &iter, &k, &klen, &data)) { xmlNodePtr cnode; char hexcode[11]; const char *name; eventer_func_t *f = (eventer_func_t *)k; noit_hash_table *sc = (noit_hash_table *)data; noit_hash_iter sc_iter = NOIT_HASH_ITER_ZERO; const char *sc_k; int sc_klen; void *sc_data; name = eventer_name_for_callback(*f); cnode = xmlNewNode(NULL, (xmlChar *)"service"); xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); if(*f == ac->dispatch) xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true"); xmlAddChild(cmds, cnode); while(noit_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { xmlNodePtr scnode; char *name_copy, *version = NULL; eventer_func_t *f = (eventer_func_t *)sc_data; snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); name = eventer_name_for_callback(*f); name_copy = strdup(name ? name : "[[unknown]]"); version = strchr(name_copy, '/'); if(version) *version++ = '\0'; scnode = xmlNewNode(NULL, (xmlChar *)"command"); xmlSetProp(scnode, (xmlChar *)"name", (xmlChar *)name_copy); if(version) xmlSetProp(scnode, (xmlChar *)"version", (xmlChar *)version); xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode); xmlAddChild(cnode, scnode); free(name_copy); } } /* Write it out to a buffer and copy it for writing */ cl->buff = noit_xmlSaveToBuffer(xmldoc); cl->towrite = strlen(cl->buff); /* Clean up after ourselves */ xmlFreeDoc(xmldoc); } while(cl->towrite > cl->written) { int len; while((len = e->opset->write(e->fd, cl->buff + cl->written, cl->towrite - cl->written, &newmask, e)) == -1 && errno == EINTR); if(len < 0) { if(errno == EAGAIN) return newmask | EVENTER_EXCEPTION; goto socket_error; } cl->written += len; } goto cleanup_shutdown; }