mirror of
https://github.com/simon987/sist2.git
synced 2025-04-16 08:56:45 +00:00
Error handling in get_es_version()
This commit is contained in:
parent
e9f92330fd
commit
2b639bd4ac
@ -21,6 +21,8 @@ void free_queue(int max);
|
||||
|
||||
void elastic_flush();
|
||||
|
||||
void print_error(response_t *r);
|
||||
|
||||
void destroy_indexer(es_indexer_t *indexer) {
|
||||
|
||||
if (indexer == NULL) {
|
||||
@ -413,12 +415,20 @@ es_version_t *elastic_get_version(const char *es_url) {
|
||||
*(tmp + r->size) = '\0';
|
||||
cJSON *response = cJSON_Parse(tmp);
|
||||
free(tmp);
|
||||
free_response(r);
|
||||
|
||||
if (response == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cJSON_GetObjectItem(response, "error") != NULL) {
|
||||
LOG_WARNING("elastic.c", "Could not get Elasticsearch version")
|
||||
print_error(r);
|
||||
free_response(r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free_response(r);
|
||||
|
||||
if (cJSON_GetObjectItem(response, "version") == NULL ||
|
||||
cJSON_GetObjectItem(cJSON_GetObjectItem(response, "version"), "number") == NULL) {
|
||||
cJSON_Delete(response);
|
||||
|
@ -20,8 +20,8 @@ typedef struct {
|
||||
} es_version_t;
|
||||
|
||||
#define VERSION_GE(version, maj, min) ((version)->major > (maj) || ((version)->major == (maj) && (version)->minor >= (min)))
|
||||
#define IS_SUPPORTED_ES_VERSION(es_version) VERSION_GE((es_version), 6, 8)
|
||||
#define USE_LEGACY_ES_SETTINGS(es_version) (!VERSION_GE((es_version), 7, 14))
|
||||
#define IS_SUPPORTED_ES_VERSION(es_version) ((es_version) != NULL && VERSION_GE((es_version), 6, 8))
|
||||
#define USE_LEGACY_ES_SETTINGS(es_version) ((es_version) != NULL && (!VERSION_GE((es_version), 7, 14)))
|
||||
|
||||
__always_inline
|
||||
static const char *format_es_version(es_version_t *version) {
|
||||
|
@ -282,7 +282,7 @@ void serve_file_from_disk(cJSON *json, index_t *idx, struct mg_connection *nc, s
|
||||
char disposition[8192];
|
||||
snprintf(disposition, sizeof(disposition),
|
||||
HTTP_SERVER_HEADER "Content-Disposition: inline; filename=\"%s%s%s\"\r\n"
|
||||
"Accept-Ranges: bytes\r\nCache-Control: no-store\r\n",
|
||||
"Accept-Ranges: bytes\r\nCache-Control: no-store\r\n",
|
||||
name, strlen(ext) == 0 ? "" : ".", ext);
|
||||
|
||||
char mime_mapping[1024];
|
||||
@ -313,13 +313,18 @@ void index_info(struct mg_connection *nc) {
|
||||
|
||||
cache_es_version();
|
||||
|
||||
const char *es_version = "0.0.0";
|
||||
if (WebCtx.es_version != NULL) {
|
||||
es_version = format_es_version(WebCtx.es_version);
|
||||
}
|
||||
|
||||
cJSON *json = cJSON_CreateObject();
|
||||
cJSON *arr = cJSON_AddArrayToObject(json, "indices");
|
||||
|
||||
cJSON_AddStringToObject(json, "mongooseVersion", MG_VERSION);
|
||||
cJSON_AddStringToObject(json, "esIndex", WebCtx.es_index);
|
||||
cJSON_AddStringToObject(json, "version", Version);
|
||||
cJSON_AddStringToObject(json, "esVersion", format_es_version(WebCtx.es_version));
|
||||
cJSON_AddStringToObject(json, "esVersion", es_version);
|
||||
cJSON_AddBoolToObject(json, "esVersionSupported", IS_SUPPORTED_ES_VERSION(WebCtx.es_version));
|
||||
cJSON_AddBoolToObject(json, "esVersionLegacy", USE_LEGACY_ES_SETTINGS(WebCtx.es_version));
|
||||
cJSON_AddStringToObject(json, "platform", QUOTE(SIST_PLATFORM));
|
||||
|
Loading…
x
Reference in New Issue
Block a user