mirror of
https://github.com/simon987/sist2.git
synced 2025-12-11 14:38:54 +00:00
add /status endpoint
This commit is contained in:
@@ -274,3 +274,28 @@ cJSON *elastic_get_document(const char *uuid_str) {
|
||||
free_response(r);
|
||||
return json;
|
||||
}
|
||||
|
||||
char *elastic_get_status() {
|
||||
char url[4096];
|
||||
snprintf(url, 4096,
|
||||
"%s/_cluster/state/metadata/sist2?filter_path=metadata.indices.*.state", WebCtx.es_url);
|
||||
|
||||
response_t *r = web_get(url);
|
||||
cJSON *json = NULL;
|
||||
char *status = malloc(128 * sizeof(char));
|
||||
status[0] = '\0';
|
||||
|
||||
if (r->status_code == 200) {
|
||||
json = cJSON_Parse(r->body);
|
||||
const cJSON *metadata = cJSON_GetObjectItem(json, "metadata");
|
||||
if (metadata != NULL) {
|
||||
const cJSON *indices = cJSON_GetObjectItem(metadata, "indices");
|
||||
const cJSON *sist2 = cJSON_GetObjectItem(indices, "sist2");
|
||||
const cJSON *state = cJSON_GetObjectItem(sist2, "state");
|
||||
strcpy(status, state->valuestring);
|
||||
}
|
||||
}
|
||||
free_response(r);
|
||||
cJSON_Delete(json);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -30,4 +30,6 @@ void elastic_init(int force_reset);
|
||||
|
||||
cJSON *elastic_get_document(const char *uuid_str);
|
||||
|
||||
char *elastic_get_status();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -431,6 +431,23 @@ int file(UNUSED(void *p), onion_request *req, onion_response *res) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int status(UNUSED(void *p), UNUSED(onion_request *req), onion_response *res) {
|
||||
set_default_headers(res);
|
||||
|
||||
onion_response_set_header(res, "Content-Type", "application/x-empty");
|
||||
|
||||
char *status = elastic_get_status();
|
||||
if (strcmp(status, "open") == 0) {
|
||||
onion_response_set_code(res, 204);
|
||||
} else {
|
||||
onion_response_set_code(res, 500);
|
||||
}
|
||||
|
||||
free(status);
|
||||
|
||||
return OCS_PROCESSED;
|
||||
}
|
||||
|
||||
void serve(const char *hostname, const char *port) {
|
||||
onion *o = onion_new(O_POOL);
|
||||
onion_set_timeout(o, 3500);
|
||||
@@ -450,6 +467,7 @@ void serve(const char *hostname, const char *port) {
|
||||
|
||||
onion_url_add(urls, "es", search);
|
||||
onion_url_add(urls, "scroll", scroll);
|
||||
onion_url_add(urls, "status", status);
|
||||
onion_url_add(
|
||||
urls,
|
||||
"^t/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/"
|
||||
|
||||
Reference in New Issue
Block a user