Zabbix Patches

Zabbix is Fantastic, let me start like that. But nothing is this world is perfect.

Although the universe is made out of imperfections, Open Source software allow us to carve a bit more on that turkey.

Here's a bit of my problems and what I did to fix them.

Make sure to use the sentia-custom-zabbix-4.0.3.patch.gz, instead of copy pasting from the code blocks!

Timeouts

The first thing I have noticed years ago, is that 30 seconds, which is the default Zabbix timeout, is a quite short period of time.

When you run an external script type of item, some scripts can take quite some time, then the real problem arise:

  • If your script "times out" you will have no result;
  • If he times out consistently and you empty responses, your item will go unsupported;
  • Sometimes it is important to "hear" the exit code of a command, timing out it is not optimal.

A reasonable amount of timeout is about 300 seconds.

After several years running different types of commands that exceed the 30 seconds, I see no problem to extend this on the source code, allowing me to increase this when I need.

As such, I have the following patch:

diff -Naur zabbix-4.0.3/src/zabbix_agent/zabbix_agentd.c zabbix-4.0.3-sentia/src/zabbix_agent/zabbix_agentd.c
--- zabbix-4.0.3/src/zabbix_agent/zabbix_agentd.c       2018-12-20 12:24:27.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_agent/zabbix_agentd.c        2019-01-10 16:02:48.697392838 +0100
@@ -769,7 +769,7 @@
                {"LogFileSize",                 &CONFIG_LOG_FILE_SIZE,                  TYPE_INT,
                        PARM_OPT,       0,                      1024},
                {"Timeout",                     &CONFIG_TIMEOUT,                        TYPE_INT,
-                       PARM_OPT,       1,                      30},
+                       PARM_OPT,       1,                      300},
                {"ListenPort",                  &CONFIG_LISTEN_PORT,                    TYPE_INT,
                        PARM_OPT,       1024,                   32767},
                {"ListenIP",                    &CONFIG_LISTEN_IP,                      TYPE_STRING_LIST,
diff -Naur zabbix-4.0.3/src/zabbix_proxy/proxy.c zabbix-4.0.3-sentia/src/zabbix_proxy/proxy.c
--- zabbix-4.0.3/src/zabbix_proxy/proxy.c       2018-12-20 12:24:26.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_proxy/proxy.c        2019-01-10 17:12:19.482271578 +0100
@@ -647,7 +649,7 @@
                {"Fping6Location",              &CONFIG_FPING6_LOCATION,                TYPE_STRING,
                        PARM_OPT,       0,                      0},
                {"Timeout",                     &CONFIG_TIMEOUT,                        TYPE_INT,
-                       PARM_OPT,       1,                      30},
+                       PARM_OPT,       1,                      300},
                {"TrapperTimeout",              &CONFIG_TRAPPER_TIMEOUT,                TYPE_INT,
                        PARM_OPT,       1,                      300},
                {"UnreachablePeriod",           &CONFIG_UNREACHABLE_PERIOD,             TYPE_INT,
@@ -664,6 +666,8 @@
                        PARM_OPT,       0,                      0},
                {"DebugLevel",                  &CONFIG_LOG_LEVEL,                      TYPE_INT,
                        PARM_OPT,       0,                      5},
+                {"DebugWebCheck",               &CONFIG_LOG_WEB,                        TYPE_INT,
+                        PARM_OPT,       0,                      0},
                {"PidFile",                     &CONFIG_PID_FILE,                       TYPE_STRING,
                        PARM_OPT,       0,                      0},
                {"LogType",                     &CONFIG_LOG_TYPE_STR,                   TYPE_STRING,
diff -Naur zabbix-4.0.3/src/zabbix_server/server.c zabbix-4.0.3-sentia/src/zabbix_server/server.c
--- zabbix-4.0.3/src/zabbix_server/server.c     2018-12-20 12:24:26.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_server/server.c      2019-01-10 16:07:37.142678163 +0100
@@ -630,7 +633,7 @@
                {"Fping6Location",              &CONFIG_FPING6_LOCATION,                TYPE_STRING,
                        PARM_OPT,       0,                      0},
                {"Timeout",                     &CONFIG_TIMEOUT,                        TYPE_INT,
-                       PARM_OPT,       1,                      30},
+                       PARM_OPT,       1,                      300},
                {"TrapperTimeout",              &CONFIG_TRAPPER_TIMEOUT,                TYPE_INT,
                        PARM_OPT,       1,                      300},
                {"UnreachablePeriod",           &CONFIG_UNREACHABLE_PERIOD,             TYPE_INT,


Web Check Debugging

Web check is awesome. Until it goes bust.

When the web check is unable to find the required text, you will be unable to figure out why.

In my opinion, most of the regular web checks, if are configured without a required text, the results could be misleading.

Tired of not being able to know why some thing simply doesn't work. I have built a patch to increase the debug level of the web check separately from the rest.

On the configuration file it looks like:

### Option: DebugWebCheck
#      Enable ability to spit the page captured via curl into the log file
#      (-) To enable on the run, requires a restart of the main daemon (proxy or server)
#      (+) Everytime the webcheck stumbles in a error, the entire page will be shown on the log
#      0 - disabled
#      1 - enabled
#
# Mandatory: no
# Range: 0-1
# Default:
# DebugWebCheck=0

When enabled it will spit out all the log lines from the httptest.c including an entire raw HTML copy of the page as downloaded via Curl (internal lib used to make web checks).

The patch for the source code is:

diff -Naur zabbix-4.0.3/src/zabbix_server/httppoller/httptest.c zabbix-4.0.3-sentia/src/zabbix_server/httppoller/httptest.c
--- zabbix-4.0.3/src/zabbix_server/httppoller/httptest.c        2018-12-20 12:24:26.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_server/httppoller/httptest.c 2019-01-10 15:44:02.663416334 +0100
@@ -40,6 +40,7 @@
 zbx_httpstat_t;

 extern int     CONFIG_HTTPPOLLER_FORKS;
+extern int     CONFIG_LOG_WEB;

 #ifdef HAVE_LIBCURL

@@ -125,7 +126,11 @@
        size_t          i, num = 0;
        AGENT_RESULT    value;

-       zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: In %s()", __function_name);
+        }

        result = DBselect("select type,itemid from httptestitem where httptestid=" ZBX_FS_UI64, httptestid);

@@ -202,7 +207,12 @@
                DCconfig_clean_items(items, errcodes, num);
        }

-       zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: End of %s()", __function_name);
+        }
+
 }

 /******************************************************************************
@@ -276,8 +286,13 @@
        size_t          i, num = 0;
        AGENT_RESULT    value;

-       zabbix_log(LOG_LEVEL_DEBUG, "In %s() rspcode:%ld time:" ZBX_FS_DBL " speed:" ZBX_FS_DBL,
-                       __function_name, stat->rspcode, stat->total_time, stat->speed_download);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "In %s() rspcode:%ld time:" ZBX_FS_DBL " speed:" ZBX_FS_DBL,
+                                __function_name, stat->rspcode, stat->total_time, stat->speed_download);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: In %s() rspcode:%ld time:" ZBX_FS_DBL " speed:" ZBX_FS_DBL,
+                                __function_name, stat->rspcode, stat->total_time, stat->speed_download);
+        }

        result = DBselect("select type,itemid from httpstepitem where httpstepid=" ZBX_FS_UI64, httpstepid);

@@ -347,7 +362,12 @@
                DCconfig_clean_items(items, errcodes, num);
        }

-       zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: End of %s()", __function_name);
+        }
+
 }

 /******************************************************************************
@@ -462,7 +482,11 @@
        {
                /* URL contains fragment delimiter, so it must be dropped */

-               zabbix_log(LOG_LEVEL_DEBUG, "URL contains fragment delimiter, fragment part is deleted from URL");
+                if (CONFIG_LOG_WEB == 0) {
+                        zabbix_log(LOG_LEVEL_DEBUG, "URL contains fragment delimiter, fragment part is deleted from URL");
+                } else {
+                        zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: URL contains fragment delimiter, fragment part is deleted from URL");
+                }
                *value = '\0';
                offset = value - url;
        }
@@ -629,8 +653,13 @@
        zbx_httpstep_t  httpstep;
 #endif

-       zabbix_log(LOG_LEVEL_DEBUG, "In %s() httptestid:" ZBX_FS_UI64 " name:'%s'",
-                       __function_name, httptest->httptest.httptestid, httptest->httptest.name);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "In %s() httptestid:" ZBX_FS_UI64 " name:'%s'",
+                                __function_name, httptest->httptest.httptestid, httptest->httptest.name);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: In %s() httptestid:" ZBX_FS_UI64 " name:'%s'",
+                                __function_name, httptest->httptest.httptestid, httptest->httptest.name);
+        }

        result = DBselect(
                        "select httpstepid,no,name,url,timeout,posts,required,status_codes,post_type,follow_redirects,"
@@ -746,8 +775,13 @@

                memset(&stat, 0, sizeof(stat));

-               zabbix_log(LOG_LEVEL_DEBUG, "%s() use step \"%s\"", __function_name, db_httpstep.name);
-               zabbix_log(LOG_LEVEL_DEBUG, "%s() use post \"%s\"", __function_name, ZBX_NULL2EMPTY_STR(httpstep.posts));
+               if (CONFIG_LOG_WEB == 0) {
+                       zabbix_log(LOG_LEVEL_DEBUG, "%s() use step \"%s\"", __function_name, db_httpstep.name);
+                       zabbix_log(LOG_LEVEL_DEBUG, "%s() use post \"%s\"", __function_name, ZBX_NULL2EMPTY_STR(httpstep.posts));
+               } else {
+                       zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG: %s() use step \"%s\"", __function_name, db_httpstep.name);
+                       zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG: %s() use post \"%s\"", __function_name, ZBX_NULL2EMPTY_STR(httpstep.posts));
+               }

                if (CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, httpstep.posts)))
                {
@@ -804,7 +838,11 @@
                        goto httpstep_error;
                }

-               zabbix_log(LOG_LEVEL_DEBUG, "%s() go to URL \"%s\"", __function_name, httpstep.url);
+                if (CONFIG_LOG_WEB == 0) {
+                        zabbix_log(LOG_LEVEL_DEBUG, "%s() go to URL \"%s\"", __function_name, httpstep.url);
+                } else {
+                        zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: %s() go to URL \"%s\"", __function_name, httpstep.url);
+                }

                if (CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_TIMEOUT, (long)db_httpstep.timeout)) ||
                                CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_URL, httpstep.url)))
@@ -829,8 +867,14 @@

                if (CURLE_OK == err)
                {
-                       zabbix_log(LOG_LEVEL_TRACE, "%s() page.data from %s:'%s'", __function_name, httpstep.url,
-                                       page.data);
+                       if (CONFIG_LOG_WEB == 0) {
+                               zabbix_log(LOG_LEVEL_TRACE, "%s() page.data from %s:'%s'", __function_name, httpstep.url,
+                                               page.data);
+                       } else {
+                               zabbix_log(LOG_LEVEL_WARNING, "%s() page.data from %s:'%s'", __function_name, httpstep.url,
+                                               page.data);
+                       }
+

                        /* first get the data that is needed even if step fails */
                        if (CURLE_OK != (err = curl_easy_getinfo(easyhandle, CURLINFO_RESPONSE_CODE, &stat.rspcode)))
@@ -981,8 +1025,13 @@

                if (NULL != db_httpstep.name)
                {
-                       zabbix_log(LOG_LEVEL_DEBUG, "cannot process step \"%s\" of web scenario \"%s\" on host \"%s\": "
-                                       "%s", db_httpstep.name, httptest->httptest.name, host->name, err_str);
+                        if (CONFIG_LOG_WEB == 0) {
+                                zabbix_log(LOG_LEVEL_DEBUG, "cannot process step \"%s\" of web scenario \"%s\" on host \"%s\": "
+                                                "%s", db_httpstep.name, httptest->httptest.name, host->name, err_str);
+                        } else {
+                                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: cannot process step \"%s\" of web scenario \"%s\" on host \"%s\": "
+                                                "%s", db_httpstep.name, httptest->httptest.name, host->name, err_str);
+                        }
                }
        }
        DBfree_result(result);
@@ -996,7 +1045,12 @@
        zbx_free(err_str);
        zbx_preprocessor_flush();

-       zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: End of %s()", __function_name);
+        }
+
 }

 /******************************************************************************
@@ -1024,7 +1078,11 @@
        DC_HOST         host;
        int             httptests_count = 0;

-       zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: In %s()", __function_name);
+        }

        /* create macro cache to use in http tests */
        zbx_vector_ptr_pair_create(&httptest.macros);
@@ -1136,7 +1194,11 @@

        DBfree_result(result);

-       zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        if (CONFIG_LOG_WEB == 0) {
+                zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
+        } else {
+                zabbix_log(LOG_LEVEL_WARNING, "WEB_DEBUG:: End of %s()", __function_name);
+        }

        return httptests_count;
 }
diff -Naur zabbix-4.0.3/src/zabbix_server/server.c zabbix-4.0.3-sentia/src/zabbix_server/server.c
--- zabbix-4.0.3/src/zabbix_server/server.c     2018-12-20 12:24:26.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_server/server.c      2019-01-10 16:07:37.142678163 +0100
@@ -216,6 +216,7 @@
 int    CONFIG_UNREACHABLE_DELAY        = 15;
 int    CONFIG_UNAVAILABLE_DELAY        = 60;
 int    CONFIG_LOG_LEVEL                = LOG_LEVEL_WARNING;
+int    CONFIG_LOG_WEB                  = 0;
 char   *CONFIG_ALERT_SCRIPTS_PATH      = NULL;
 char   *CONFIG_EXTERNALSCRIPTS         = NULL;
 char   *CONFIG_TMPDIR                  = NULL;
 @@ -647,6 +650,8 @@
                        PARM_OPT,       0,                      0},
                {"DebugLevel",                  &CONFIG_LOG_LEVEL,                      TYPE_INT,
                        PARM_OPT,       0,                      5},
+               {"DebugWebCheck",               &CONFIG_LOG_LEVEL,                      TYPE_INT,
+                       PARM_OPT,       0,                      0},
                {"PidFile",                     &CONFIG_PID_FILE,                       TYPE_STRING,
                        PARM_OPT,       0,                      0},
                {"LogType",                     &CONFIG_LOG_TYPE_STR,                   TYPE_STRING,
diff -Naur zabbix-4.0.3/src/zabbix_proxy/proxy.c zabbix-4.0.3-sentia/src/zabbix_proxy/proxy.c
--- zabbix-4.0.3/src/zabbix_proxy/proxy.c       2018-12-20 12:24:26.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_proxy/proxy.c        2019-01-10 17:12:19.482271578 +0100
@@ -205,6 +205,7 @@
 int    CONFIG_UNREACHABLE_DELAY        = 15;
 int    CONFIG_UNAVAILABLE_DELAY        = 60;
 int    CONFIG_LOG_LEVEL                = LOG_LEVEL_WARNING;
+int    CONFIG_LOG_WEB                  = 0;
 char   *CONFIG_ALERT_SCRIPTS_PATH      = NULL;
 char   *CONFIG_EXTERNALSCRIPTS         = NULL;
 char   *CONFIG_TMPDIR                  = NULL;
 @@ -664,6 +666,8 @@
                        PARM_OPT,       0,                      0},
                {"DebugLevel",                  &CONFIG_LOG_LEVEL,                      TYPE_INT,
                        PARM_OPT,       0,                      5},
+                {"DebugWebCheck",               &CONFIG_LOG_WEB,                        TYPE_INT,
+                        PARM_OPT,       0,                      0},
                {"PidFile",                     &CONFIG_PID_FILE,                       TYPE_STRING,
                        PARM_OPT,       0,                      0},
                {"LogType",                     &CONFIG_LOG_TYPE_STR,                   TYPE_STRING,

Remember to use this patch, you will need to enable the configuration option described above and also restart the zabbix binary (server or proxy)...

Elastisearch Indices Prefix

Problem: I got a project that will require to run two zabbix servers at once, looking into different hosts and objects. Well, I can simply say on the configuration to use different database names on the MySQL, although, wanting to use Elasticsearch as a history storage, will not allow me to do the same. I cannot give custom names to the indices that zabbix will use... until now.

Now I have created a patch that allow me to include a "prefix" in front of the indices that zabbix will use, same for the ingest pipelines.

The configuration file will look like:

### Option: HistoryIndicePrefix
#      Add prefix to differentiate groups of history indices on elastisearch
#
# Mandatory: no
# Default:
HistoryIndicePrefix=infra

Then you should create a Pipeline like:

put _ingest/pipeline/infra-dbl-pipeline  
{
    "description": "zabbix dbl index pipeline",
    "processors": [
      {
        "date_index_name": {
          "field": "clock",
          "date_formats": [
            "UNIX"
          ],
          "index_name_prefix": "infra-dbl-",
          "date_rounding": "d"
        }
      }
    ]
}

put _template/infra-dbl_template
{
   "index_patterns": ["infra-dbl-*"],
   "settings" : {
      "index" : {
         "number_of_replicas" : 0,
         "number_of_shards" : 1
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "ns": {
          "type": "long"
            },
            "ttl": {
          "type": "long"
            },
            "value" : {
               "type" : "long"
            }
         }
      }
   }
}

Then Zabbix will properly create the indices with your prefix and you will be able to use multiple servers against the same elasticsearch cluster.

Here is the patch that allow the magic happens:

diff -Naur zabbix-4.0.3/src/libs/zbxhistory/history_elastic.c zabbix-4.0.3-sentia/src/libs/zbxhistory/history_elastic.c
--- zabbix-4.0.3/src/libs/zbxhistory/history_elastic.c  2018-12-20 12:24:27.000000000 +0100
+++ zabbix-4.0.3-sentia/src/libs/zbxhistory/history_elastic.c   2019-01-10 16:16:33.799110713 +0100
@@ -38,11 +38,13 @@
 const char     *value_type_str[] = {"dbl", "str", "log", "uint", "text"};

 extern char    *CONFIG_HISTORY_STORAGE_URL;
+extern char    *CONFIG_HISTORY_INDICE_PREFIX;
 extern int     CONFIG_HISTORY_STORAGE_PIPELINES;

 typedef struct
 {
        char    *base_url;
+       char    *idx_prefix;
        char    *post_url;
        char    *buf;
        CURL    *handle;
@@ -590,6 +592,7 @@
        elastic_close(hist);

        zbx_free(data->base_url);
+       zbx_free(data->idx_prefix);
        zbx_free(data);
 }

@@ -625,9 +628,11 @@
        struct zbx_json         query;
        struct curl_slist       *curl_headers = NULL;
        char                    *scroll_id = NULL, *scroll_query = NULL, errbuf[CURL_ERROR_SIZE];
+       char                    *index_name = NULL;

        zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

+
        ret = FAIL;

        if (NULL == (data->handle = curl_easy_init()))
@@ -637,8 +642,15 @@
                return FAIL;
        }

+       if ((data->idx_prefix != NULL) && (data->idx_prefix[0] == '\0')) {
+               index_name = zbx_strdup(NULL, value_type_str[hist->value_type]);
+       } else {
+               index_name = zbx_strdup(NULL, data->idx_prefix);
+               index_name = zbx_strdcatf(index_name, "-%s", value_type_str[hist->value_type]);
+       }
+
        zbx_snprintf_alloc(&data->post_url, &url_alloc, &url_offset, "%s/%s*/values/_search?scroll=10s", data->base_url,
-                       value_type_str[hist->value_type]);
+                       index_name);

        /* prepare the json query for elasticsearch, apply ranges if needed */
        zbx_json_init(&query, ZBX_JSON_ALLOCATE);
@@ -839,19 +851,27 @@
        ZBX_DC_HISTORY          *h;
        struct zbx_json         json_idx, json;
        size_t                  buf_alloc = 0, buf_offset = 0;
-       char                    pipeline[14]; /* index name length + suffix "-pipeline" */
+       char                    pipeline[20]; /* index name length + suffix "-pipeline" also more 5 chars for index prefix */
+       char                    *index_name = NULL;

        zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

        zbx_json_init(&json_idx, ZBX_IDX_JSON_ALLOCATE);

+       if ((data->idx_prefix != NULL) && (data->idx_prefix[0] == '\0')) {
+               index_name = zbx_strdup(NULL, value_type_str[hist->value_type]);
+       } else {
+               index_name = zbx_strdup(NULL, data->idx_prefix);
+               index_name = zbx_strdcatf(index_name, "-%s", value_type_str[hist->value_type]);
+       }
+
        zbx_json_addobject(&json_idx, "index");
-       zbx_json_addstring(&json_idx, "_index", value_type_str[hist->value_type], ZBX_JSON_TYPE_STRING);
+       zbx_json_addstring(&json_idx, "_index", index_name, ZBX_JSON_TYPE_STRING);
        zbx_json_addstring(&json_idx, "_type", "values", ZBX_JSON_TYPE_STRING);

        if (1 == CONFIG_HISTORY_STORAGE_PIPELINES)
        {
-               zbx_snprintf(pipeline, sizeof(pipeline), "%s-pipeline", value_type_str[hist->value_type]);
+               zbx_snprintf(pipeline, sizeof(pipeline), "%s-pipeline", index_name);
                zbx_json_addstring(&json_idx, "pipeline", pipeline, ZBX_JSON_TYPE_STRING);
        }

@@ -955,6 +975,12 @@
        data = (zbx_elastic_data_t *)zbx_malloc(NULL, sizeof(zbx_elastic_data_t));
        memset(data, 0, sizeof(zbx_elastic_data_t));
        data->base_url = zbx_strdup(NULL, CONFIG_HISTORY_STORAGE_URL);
+       if (NULL != CONFIG_HISTORY_INDICE_PREFIX) {
+               data->idx_prefix = zbx_strdup(NULL, CONFIG_HISTORY_INDICE_PREFIX);
+       } else { 
+               data->idx_prefix = "";
+       }
+
        zbx_rtrim(data->base_url, "/");
        data->buf = NULL;
        data->post_url = NULL;
diff -Naur zabbix-4.0.3/src/zabbix_proxy/proxy.c zabbix-4.0.3-sentia/src/zabbix_proxy/proxy.c
--- zabbix-4.0.3/src/zabbix_proxy/proxy.c       2018-12-20 12:24:26.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_proxy/proxy.c        2019-01-10 17:12:19.482271578 +0100
@@ -267,6 +268,7 @@
 static char    *CONFIG_SOCKET_PATH     = NULL;

 char   *CONFIG_HISTORY_STORAGE_URL             = NULL;
+char   *CONFIG_HISTORY_INDICE_PREFIX           = NULL;
 char   *CONFIG_HISTORY_STORAGE_OPTS            = NULL;
 int    CONFIG_HISTORY_STORAGE_PIPELINES        = 0;

diff -Naur zabbix-4.0.3/src/zabbix_server/server.c zabbix-4.0.3-sentia/src/zabbix_server/server.c
--- zabbix-4.0.3/src/zabbix_server/server.c     2018-12-20 12:24:26.000000000 +0100
+++ zabbix-4.0.3-sentia/src/zabbix_server/server.c      2019-01-10 16:07:37.142678163 +0100
@@ -282,6 +283,7 @@
 static char    *CONFIG_SOCKET_PATH     = NULL;

 char   *CONFIG_HISTORY_STORAGE_URL             = NULL;
+char   *CONFIG_HISTORY_INDICE_PREFIX           = NULL;
 char   *CONFIG_HISTORY_STORAGE_OPTS            = NULL;
 int    CONFIG_HISTORY_STORAGE_PIPELINES        = 0;

@@ -527,6 +529,7 @@
        err |= (FAIL == check_cfg_feature_str("SSLCertLocation", CONFIG_SSL_CERT_LOCATION, "cURL library"));
        err |= (FAIL == check_cfg_feature_str("SSLKeyLocation", CONFIG_SSL_KEY_LOCATION, "cURL library"));
        err |= (FAIL == check_cfg_feature_str("HistoryStorageURL", CONFIG_HISTORY_STORAGE_URL, "cURL library"));
+       err |= (FAIL == check_cfg_feature_str("HistoryIndicePrefix", CONFIG_HISTORY_INDICE_PREFIX, "cURL library"));
        err |= (FAIL == check_cfg_feature_str("HistoryStorageTypes", CONFIG_HISTORY_STORAGE_OPTS, "cURL library"));
        err |= (FAIL == check_cfg_feature_int("HistoryStorageDateIndex", CONFIG_HISTORY_STORAGE_PIPELINES,
                        "cURL library"));
@@ -723,6 +728,8 @@
                        PARM_OPT,       1,                      1000},
                {"HistoryStorageURL",           &CONFIG_HISTORY_STORAGE_URL,            TYPE_STRING,
                        PARM_OPT,       0,                      0},
+               {"HistoryIndicePrefix",         &CONFIG_HISTORY_INDICE_PREFIX,          TYPE_STRING,
+                       PARM_OPT,       0,                      0},
                {"HistoryStorageTypes",         &CONFIG_HISTORY_STORAGE_OPTS,           TYPE_STRING_LIST,
                        PARM_OPT,       0,                      0},
                {"HistoryStorageDateIndex",     &CONFIG_HISTORY_STORAGE_PIPELINES,      TYPE_INT,

Something worth noting: This patch will only gives the possibility of adding a prefix with 5 characters maximum. Bigger than 5 chars will break the pipeline variable and Zabbix will not be able to write on elasticsearch. The reason for that, right now, is that I didn't want to fiddle more than I really needed, I am hoping that Zabbix SIA gets this patch as a feature in some coming version, then they can do in the way and style they deem necessary.

Although this patch works and is not dangerous or anything, it is just straight to the point.

Next to the patch above, you will need to patch also the frontend, in order to teach the PHP to fetch from the right indices. Then the following patch:

diff -Naur zabbix-4.0.3/frontends/php/conf/zabbix.conf.php.example zabbix-4.0.3-sentia/frontends/php/conf/zabbix.conf.php.example
--- zabbix-4.0.3/frontends/php/conf/zabbix.conf.php.example     2018-12-20 12:24:28.000000000 +0100
+++ zabbix-4.0.3-sentia/frontends/php/conf/zabbix.conf.php.example      2019-01-10 16:17:24.540031562 +0100
@@ -1,6 +1,6 @@
 <?php
 // Zabbix GUI configuration file.
-global $DB, $HISTORY;
+global $DB, $HISTORY, $HISTORY_PREFIX;

 $DB['TYPE']                            = 'MYSQL';
 $DB['SERVER']                  = 'localhost';
@@ -25,3 +25,4 @@
 //];
 // Value types stored in Elasticsearch.
 //$HISTORY['types'] = ['uint', 'text'];
+//$HISTORY_PREFIX='';
\ No newline at end of file
diff -Naur zabbix-4.0.3/frontends/php/include/classes/api/managers/CHistoryManager.php zabbix-4.0.3-sentia/frontends/php/include/classes/api/managers/CHistoryManager.php
--- zabbix-4.0.3/frontends/php/include/classes/api/managers/CHistoryManager.php 2018-12-20 12:24:28.000000000 +0100
+++ zabbix-4.0.3-sentia/frontends/php/include/classes/api/managers/CHistoryManager.php  2019-01-10 16:09:44.878341839 +0100
@@ -684,6 +684,8 @@
         * @return array    Elasticsearch query endpoints
         */
        public static function getElasticsearchEndpoints($value_types, $action = '_search') {
+               global $HISTORY_PREFIX;
+
                if (!is_array($value_types)) {
                        $value_types = [$value_types];
                }
@@ -697,9 +699,13 @@
                        }
                }

+               if (isset($HISTORY_PREFIX) && !empty($HISTORY_PREFIX)) {
+                 $HISTORY_PREFIX = $HISTORY_PREFIX . "-";
+               }
+
                foreach ($indices as $type => $index) {
                        if (($url = self::getElasticsearchUrl($index)) !== null) {
-                               $endponts[$type] = $url.$index.'*/values/'.$action;
+                               $endponts[$type] = $url.$HISTORY_PREFIX.$index.'*/values/'.$action;
                        }
                }


Make sure to use the sentia-custom-zabbix-4.0.3.patch.gz, instead of copy pasting from the code blocks!


0 Comments: