void plugin_extfile_add_svctype(const char* name, vscf_data_t* svc_cfg, const unsigned interval, const unsigned timeout) { dmn_assert(name); dmn_assert(svc_cfg); service_types = xrealloc(service_types, (num_svcs + 1) * sizeof(extf_svc_t)); extf_svc_t* svc = &service_types[num_svcs++]; svc->name = strdup(name); svc->timeout = timeout; svc->interval = interval; vscf_data_t* path_cfg = vscf_hash_get_data_byconstkey(svc_cfg, "file", true); if(!path_cfg || !vscf_is_simple(path_cfg)) log_fatal("plugin_extfile: service_type '%s': the 'file' option is required and must be a string filename", name); svc->path = gdnsd_resolve_path_state(vscf_simple_get_data(path_cfg), "extfile"); svc->direct = false; svc->def_sttl = GDNSD_STTL_TTL_MAX; SVC_OPT_BOOL(svc_cfg, name, direct, svc->direct); SVC_OPT_UINT(svc_cfg, name, def_ttl, svc->def_sttl, 1LU, (unsigned long)GDNSD_STTL_TTL_MAX); bool def_down = false; SVC_OPT_BOOL(svc_cfg, name, def_down, def_down); if(def_down) svc->def_sttl |= GDNSD_STTL_DOWN; svc->num_mons = 0; svc->mons = NULL; }
void plugin_http_status_add_svctype(const char* name, const vscf_data_t* svc_cfg, const unsigned interval, const unsigned timeout) { dmn_assert(name); // defaults const char* url_path = "/"; const char* vhost = NULL; unsigned port = 80; service_types = realloc(service_types, (num_http_svcs + 1) * sizeof(http_svc_t)); http_svc_t* this_svc = &service_types[num_http_svcs++]; this_svc->name = strdup(name); this_svc->num_ok_codes = 0; this_svc->ok_codes = NULL; bool ok_codes_set = false; if(svc_cfg) { SVC_OPT_STR(svc_cfg, name, url_path); SVC_OPT_STR(svc_cfg, name, vhost); SVC_OPT_UINT(svc_cfg, name, port, 1LU, 65534LU); const vscf_data_t* ok_codes_cfg = vscf_hash_get_data_byconstkey(svc_cfg, "ok_codes", true); if(ok_codes_cfg) { ok_codes_set = true; this_svc->num_ok_codes = vscf_array_get_len(ok_codes_cfg); this_svc->ok_codes = malloc(sizeof(unsigned long) * this_svc->num_ok_codes); for(unsigned i = 0; i < this_svc->num_ok_codes; i++) { const vscf_data_t* code_cfg = vscf_array_get_data(ok_codes_cfg, i); if(!vscf_simple_get_as_ulong(code_cfg, &this_svc->ok_codes[i])) log_fatal("plugin_http_status: service type '%s': illegal ok_codes value '%s', must be numeric http status code (100-999)", this_svc->name, vscf_simple_get_data(code_cfg)); if(this_svc->ok_codes[i] < 100LU || this_svc->ok_codes[i] > 999LU) log_fatal("plugin_http_status: service type '%s': illegal ok_codes value '%lu', must be numeric http status code (100-999)", this_svc->name, this_svc->ok_codes[i]); } } } // no config at all, but not the empty array... if(!ok_codes_set) { this_svc->num_ok_codes = 1; this_svc->ok_codes = malloc(sizeof(unsigned long)); this_svc->ok_codes[0] = 200LU; } make_req_data(this_svc, url_path, vhost); this_svc->port = port; this_svc->timeout = timeout; this_svc->interval = interval; }
void plugin_tcp_connect_add_svctype(const char* name, vscf_data_t* svc_cfg, const unsigned interval, const unsigned timeout) { dmn_assert(name); dmn_assert(svc_cfg); service_types = xrealloc(service_types, (num_tcp_svcs + 1) * sizeof(tcp_svc_t)); tcp_svc_t* this_svc = &service_types[num_tcp_svcs++]; this_svc->name = strdup(name); unsigned port = 0U; SVC_OPT_UINT(svc_cfg, name, port, 1LU, 65534LU); if(!port) log_fatal("plugin_tcp_connect: service type '%s' must have a 'port' parameter", name); this_svc->port = port; this_svc->timeout = timeout; this_svc->interval = interval; }