Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2022-06-17 20:38:40 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2022-06-17 20:38:40 +0300
commit2760a1fc3158712ba10aeb071ff7a82212f90e9b (patch)
tree5bc0fc1c21b5844563af6e08705c520cc5647647
parentfe77b46e190466612470fa92e6a8ccda501b98c0 (diff)
........S. [ZBX-21145] backported tag merging/validation
-rw-r--r--include/db.h3
-rw-r--r--src/libs/zbxdbhigh/host.c2
-rw-r--r--src/libs/zbxdbhigh/tag.c244
-rw-r--r--src/libs/zbxdbhigh/template_item.c2
-rw-r--r--src/libs/zbxdbhigh/trigger_linking.c2
-rw-r--r--src/zabbix_server/lld/lld_host.c35
-rw-r--r--src/zabbix_server/lld/lld_item.c31
-rw-r--r--src/zabbix_server/lld/lld_trigger.c42
8 files changed, 155 insertions, 206 deletions
diff --git a/include/db.h b/include/db.h
index 35a74936428..8cda2c83ac2 100644
--- a/include/db.h
+++ b/include/db.h
@@ -901,8 +901,7 @@ void zbx_db_tag_free(zbx_db_tag_t *tag);
int zbx_db_tag_compare_func(const void *d1, const void *d2);
int zbx_db_tag_compare_func_template(const void *d1, const void *d2);
-void zbx_merge_tags(zbx_vector_db_tag_ptr_t *dst, zbx_vector_db_tag_ptr_t *src);
-int zbx_validate_tags(zbx_vector_db_tag_ptr_t *tags, const char *owner, char **error);
+int zbx_merge_tags(zbx_vector_db_tag_ptr_t *dst, zbx_vector_db_tag_ptr_t *src, const char *owner, char **error);
typedef enum
{
diff --git a/src/libs/zbxdbhigh/host.c b/src/libs/zbxdbhigh/host.c
index 452f83a4bc6..3a934e750d1 100644
--- a/src/libs/zbxdbhigh/host.c
+++ b/src/libs/zbxdbhigh/host.c
@@ -3074,7 +3074,7 @@ static void DBhost_prototypes_tags_make(zbx_vector_ptr_t *host_prototypes)
for (i = 0; i < host_prototypes->values_num; i++)
{
host_prototype = (zbx_host_prototype_t *)host_prototypes->values[i];
- zbx_merge_tags(&host_prototype->tags, &host_prototype->new_tags);
+ (void)zbx_merge_tags(&host_prototype->tags, &host_prototype->new_tags, NULL, NULL);
}
zbx_vector_uint64_destroy(&hostids);
diff --git a/src/libs/zbxdbhigh/tag.c b/src/libs/zbxdbhigh/tag.c
index 5f08bd6069b..f8f16ff0f09 100644
--- a/src/libs/zbxdbhigh/tag.c
+++ b/src/libs/zbxdbhigh/tag.c
@@ -18,8 +18,8 @@
**/
#include "common.h"
-#include "../zbxalgo/vectorimpl.h"
+#include "../zbxalgo/vectorimpl.h"
#include "db.h"
ZBX_PTR_VECTOR_IMPL(db_tag_ptr, zbx_db_tag_t *)
@@ -76,105 +76,6 @@ int zbx_db_tag_compare_func_template(const void *d1, const void *d2)
/******************************************************************************
* *
- * Purpose: merge new tags into existing *
- * *
- * Parameters: dst - [IN/OUT] vector of existing tags *
- * src - [IN/OUT] vector or new tags *
- * *
- * Comments: The tags are merged using the following logic: *
- * 1) tags with matching name+value are left as it is *
- * 2) tags with matching names will have their values updated *
- * 3) tags without matches will have: *
- * a) their name and value updated if there are new tags left *
- * b) flagged to be removed otherwise *
- * 4) all leftover new tags will be created *
- * *
- ******************************************************************************/
-void zbx_merge_tags(zbx_vector_db_tag_ptr_t *dst, zbx_vector_db_tag_ptr_t *src)
-{
- int i, j;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In %s() old_tags:%d new_tags:%d", __func__, dst->values_num, src->values_num);
-
- /* perform exact tag + value match */
- for (i = 0; i < dst->values_num; i++)
- {
- for (j = 0; j < src->values_num; j++)
- {
- if (0 == strcmp(dst->values[i]->tag, src->values[j]->tag) &&
- 0 == strcmp(dst->values[i]->value, src->values[j]->value))
- {
- break;
- }
- }
-
- if (j != src->values_num)
- {
- zbx_db_tag_free(src->values[j]);
- zbx_vector_db_tag_ptr_remove_noorder(src, j);
- continue;
- }
-
- dst->values[i]->flags = ZBX_FLAG_DB_TAG_REMOVE;
- }
-
- if (0 == src->values_num)
- return;
-
- /* perform tag match */
- for (i = 0; i < dst->values_num; i++)
- {
- if (ZBX_FLAG_DB_TAG_REMOVE != dst->values[i]->flags)
- continue;
-
- for (j = 0; j < src->values_num; j++)
- {
- if (0 == strcmp(dst->values[i]->tag, src->values[j]->tag))
- break;
- }
-
- if (j != src->values_num)
- {
- dst->values[i]->value_orig = dst->values[i]->value;
- dst->values[i]->value = src->values[j]->value;
- dst->values[i]->flags = ZBX_FLAG_DB_TAG_UPDATE_VALUE;
- src->values[j]->value = NULL;
- zbx_db_tag_free(src->values[j]);
- zbx_vector_db_tag_ptr_remove_noorder(src, j);
- continue;
- }
- }
-
- if (0 == src->values_num)
- return;
-
- /* update rest of the tags */
- for (i = 0; i < dst->values_num && 0 < src->values_num; i++)
- {
- if (ZBX_FLAG_DB_TAG_REMOVE != dst->values[i]->flags)
- continue;
-
- dst->values[i]->tag_orig = dst->values[i]->tag;
- dst->values[i]->value_orig = dst->values[i]->value;
- dst->values[i]->tag = src->values[0]->tag;
- dst->values[i]->value = src->values[0]->value;
- dst->values[i]->flags = ZBX_FLAG_DB_TAG_UPDATE_TAG | ZBX_FLAG_DB_TAG_UPDATE_VALUE;
- src->values[0]->tag = NULL;
- src->values[0]->value = NULL;
- zbx_db_tag_free(src->values[0]);
- zbx_vector_db_tag_ptr_remove_noorder(src, 0);
- continue;
- }
-
- /* add leftover new tags */
- zbx_vector_db_tag_ptr_append_array(dst, src->values, src->values_num);
- zbx_vector_db_tag_ptr_clear(src);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End of %s() tags:%d", __func__, dst->values_num);
-}
-
-/******************************************************************************
- * *
* Purpose: roll back tag updates done during merge process *
* *
* Return value: SUCCEED - updates were rolled back *
@@ -331,11 +232,18 @@ static int check_tag_fields(zbx_vector_db_tag_ptr_t *tags, const char *owner, ch
/******************************************************************************
* *
- * Purpose: check tags for duplicate tag+value combinations *
+ * Purpose: check new tags for duplicate tag+value combinations *
+ * *
+ * Parameters: tags - [IN/OUT] the tags to check *
+ * owner - [IN] the owned object (host, item, trigger) *
+ * error - [OUT] the error message *
* *
* Return value: SUCCEED - tags have no duplicates *
* FAIL - otherwise *
* *
+ * Comments: Existing tags are rolled back to their original values, while *
+ * new tags are removed. *
+ * *
******************************************************************************/
static int check_duplicate_tags(zbx_vector_db_tag_ptr_t *tags, const char *owner, char **error)
{
@@ -345,26 +253,21 @@ static int check_duplicate_tags(zbx_vector_db_tag_ptr_t *tags, const char *owner
{
zbx_db_tag_t *left = tags->values[i];
- if (0 != (left->flags & ZBX_FLAG_DB_TAG_REMOVE))
- continue;
-
for (j = 0; j < i; j++)
{
zbx_db_tag_t *right = tags->values[j];
- if (0 != (right->flags & ZBX_FLAG_DB_TAG_REMOVE))
- continue;
-
if (0 == strcmp(left->tag, right->tag) && 0 == strcmp(left->value, right->value))
{
- *error = zbx_strdcatf(*error, "Cannot %s %s tag: \"%s: %s\" already exists.\n",
- ZBX_TAG_OP(left), owner, left->tag, right->value);
-
- if (SUCCEED != db_tag_rollback(left))
+ if (NULL != error)
{
- zbx_db_tag_free(left);
- zbx_vector_db_tag_ptr_remove_noorder(tags, i--);
+ *error = zbx_strdcatf(*error, "Cannot %s %s tag: \"%s: %s\" already exists.\n",
+ ZBX_TAG_OP(left), owner, left->tag, right->value);
}
+
+ zbx_db_tag_free(left);
+ zbx_vector_db_tag_ptr_remove_noorder(tags, i--);
+
ret = FAIL;
break;
}
@@ -376,33 +279,116 @@ static int check_duplicate_tags(zbx_vector_db_tag_ptr_t *tags, const char *owner
/******************************************************************************
* *
- * Purpose: check validness of the tags *
+ * Purpose: merge new tags into existing *
* *
- * Parameters: tags - [IN/OUT] the tags to check *
- * object - [IN] the tag owner (host, item, trigger), *
+ * Parameters: dst - [IN/OUT] vector of existing tags *
+ * src - [IN/OUT] vector or new tags *
+ * owner - [IN] the tag owner (host, item, trigger), *
* optional - must be specified if error parameter *
* is not null *
* error - [IN,OUT] the error message (appended to existing), *
* optional *
* *
- * Return value: SUCCEED - tags are valid *
- * FAIL - otherwise *
+ * Comments: The tags are merged using the following logic: *
+ * 1) tags with matching name+value are left as it is *
+ * 2) tags with matching names will have their values updated *
+ * 3) tags without matches will have: *
+ * a) their name and value updated if there are new tags left *
+ * b) flagged to be removed otherwise *
+ * 4) all leftover new tags will be created *
* *
- * Comments: When invalid tag is found it is either removed (new tags) or *
- * it's fields are rolled back to original values and update flags *
- * reset. *
+ * Return value: SUCCEED - tags were merged without issues *
+ * FAIL - tags were merged with errors *
* *
******************************************************************************/
-int zbx_validate_tags(zbx_vector_db_tag_ptr_t *tags, const char *owner, char **error)
+int zbx_merge_tags(zbx_vector_db_tag_ptr_t *dst, zbx_vector_db_tag_ptr_t *src, const char *owner, char **error)
{
- int errors = 0;
+ int i, j, ret;
- errors += check_tag_fields(tags, owner, error);
- errors += check_duplicate_tags(tags, owner, error);
+ zabbix_log(LOG_LEVEL_DEBUG, "In %s() old_tags:%d new_tags:%d", __func__, dst->values_num, src->values_num);
- if (0 > errors)
- return FAIL;
+ ret = check_duplicate_tags(src, owner, error);
- return SUCCEED;
-}
+ /* perform exact tag + value match */
+ for (i = 0; i < dst->values_num; i++)
+ {
+ for (j = 0; j < src->values_num; j++)
+ {
+ if (0 == strcmp(dst->values[i]->tag, src->values[j]->tag) &&
+ 0 == strcmp(dst->values[i]->value, src->values[j]->value))
+ {
+ break;
+ }
+ }
+
+ if (j != src->values_num)
+ {
+ zbx_db_tag_free(src->values[j]);
+ zbx_vector_db_tag_ptr_remove_noorder(src, j);
+ continue;
+ }
+
+ dst->values[i]->flags = ZBX_FLAG_DB_TAG_REMOVE;
+ }
+
+ if (0 == src->values_num)
+ goto out;
+
+ /* perform tag match */
+ for (i = 0; i < dst->values_num; i++)
+ {
+ if (ZBX_FLAG_DB_TAG_REMOVE != dst->values[i]->flags)
+ continue;
+ for (j = 0; j < src->values_num; j++)
+ {
+ if (0 == strcmp(dst->values[i]->tag, src->values[j]->tag))
+ break;
+ }
+
+ if (j != src->values_num)
+ {
+ dst->values[i]->value_orig = dst->values[i]->value;
+ dst->values[i]->value = src->values[j]->value;
+ dst->values[i]->flags = ZBX_FLAG_DB_TAG_UPDATE_VALUE;
+ src->values[j]->value = NULL;
+ zbx_db_tag_free(src->values[j]);
+ zbx_vector_db_tag_ptr_remove_noorder(src, j);
+ continue;
+ }
+ }
+
+ if (0 == src->values_num)
+ goto out;
+
+ /* update rest of the tags */
+ for (i = 0; i < dst->values_num && 0 < src->values_num; i++)
+ {
+ if (ZBX_FLAG_DB_TAG_REMOVE != dst->values[i]->flags)
+ continue;
+
+ dst->values[i]->tag_orig = dst->values[i]->tag;
+ dst->values[i]->value_orig = dst->values[i]->value;
+ dst->values[i]->tag = src->values[0]->tag;
+ dst->values[i]->value = src->values[0]->value;
+ dst->values[i]->flags = ZBX_FLAG_DB_TAG_UPDATE_TAG | ZBX_FLAG_DB_TAG_UPDATE_VALUE;
+ src->values[0]->tag = NULL;
+ src->values[0]->value = NULL;
+ zbx_db_tag_free(src->values[0]);
+ zbx_vector_db_tag_ptr_remove_noorder(src, 0);
+ continue;
+ }
+
+ /* add leftover new tags */
+ zbx_vector_db_tag_ptr_append_array(dst, src->values, src->values_num);
+ zbx_vector_db_tag_ptr_clear(src);
+out:
+ if (SUCCEED != (ret = check_tag_fields(dst, owner, error)))
+ ret = FAIL;
+
+ zbx_vector_db_tag_ptr_sort(dst, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End of %s() tags:%d", __func__, dst->values_num);
+
+ return ret;
+}
diff --git a/src/libs/zbxdbhigh/template_item.c b/src/libs/zbxdbhigh/template_item.c
index 997b4978d52..cd095ef3834 100644
--- a/src/libs/zbxdbhigh/template_item.c
+++ b/src/libs/zbxdbhigh/template_item.c
@@ -2967,7 +2967,7 @@ static void link_template_items_tag(const zbx_vector_uint64_t *templateids, zbx_
for (i = 0; i < items->values_num; i++)
{
item = (zbx_template_item_t *)items->values[i];
- zbx_merge_tags(&item->item_tags, &item->template_tags);
+ (void)zbx_merge_tags(&item->item_tags, &item->template_tags, NULL, NULL);
}
zbx_hashset_destroy(&items_t);
zbx_vector_uint64_destroy(&itemids);
diff --git a/src/libs/zbxdbhigh/trigger_linking.c b/src/libs/zbxdbhigh/trigger_linking.c
index f892d31fb0e..45e5bc2ea6d 100644
--- a/src/libs/zbxdbhigh/trigger_linking.c
+++ b/src/libs/zbxdbhigh/trigger_linking.c
@@ -426,7 +426,7 @@ static int DBcopy_template_trigger_tags(const zbx_vector_uint64_t *new_triggerid
for (i = 0; i < triggers_tags.values_num; i++)
{
trigger_tags = triggers_tags.values[i];
- zbx_merge_tags(&trigger_tags->tags, &trigger_tags->new_tags);
+ (void)zbx_merge_tags(&trigger_tags->tags, &trigger_tags->new_tags, NULL, NULL);
for (j = 0; j < trigger_tags->tags.values_num; j++)
{
diff --git a/src/zabbix_server/lld/lld_host.c b/src/zabbix_server/lld/lld_host.c
index c94b1021683..fbec72bd1d3 100644
--- a/src/zabbix_server/lld/lld_host.c
+++ b/src/zabbix_server/lld/lld_host.c
@@ -302,7 +302,7 @@ typedef struct
zbx_lld_group_rights_t;
static void lld_host_update_tags(zbx_lld_host_t *host, const zbx_vector_db_tag_ptr_t *tags,
- const zbx_vector_ptr_t *lld_macros);
+ const zbx_vector_ptr_t *lld_macros, char **error);
typedef struct
{
@@ -629,21 +629,6 @@ static void lld_hosts_validate(zbx_vector_ptr_t *hosts, char **error)
host->flags &= ~ZBX_FLAG_LLD_HOST_DISCOVERED;
}
- /* check host tag validness */
- for (i = 0; i < hosts->values_num; i++)
- {
- host = (zbx_lld_host_t *)hosts->values[i];
-
- if (0 == (host->flags & ZBX_FLAG_LLD_HOST_DISCOVERED))
- continue;
-
- if (SUCCEED != zbx_validate_tags(&host->tags, "host", error) && 0 == host->hostid)
- {
- host->flags &= ~ZBX_FLAG_LLD_HOST_DISCOVERED;
- *error = zbx_strdcatf(*error, "Cannot create host: tag validation failed.\n");
- }
- }
-
/* checking duplicated host names */
for (i = 0; i < hosts->values_num; i++)
{
@@ -835,7 +820,7 @@ static void lld_hosts_validate(zbx_vector_ptr_t *hosts, char **error)
static zbx_lld_host_t *lld_host_make(zbx_vector_ptr_t *hosts, const char *host_proto, const char *name_proto,
signed char inventory_mode_proto, unsigned char status_proto, unsigned char discover_proto,
zbx_vector_db_tag_ptr_t *tags, const zbx_lld_row_t *lld_row, const zbx_vector_ptr_t *lld_macros,
- unsigned char custom_iface)
+ unsigned char custom_iface, char **error)
{
char *buffer = NULL;
int i, host_found = 0;
@@ -983,7 +968,7 @@ static zbx_lld_host_t *lld_host_make(zbx_vector_ptr_t *hosts, const char *host_p
if (0 != (host->flags & ZBX_FLAG_LLD_HOST_DISCOVERED))
{
zbx_vector_db_tag_ptr_append_array(&tmp_tags, tags->values, tags->values_num);
- lld_host_update_tags(host, &tmp_tags, lld_macros);
+ lld_host_update_tags(host, &tmp_tags, lld_macros, error);
if (0 != lnk_templateids.values_num)
{
@@ -2242,7 +2227,7 @@ static void lld_proto_tags_get(zbx_uint64_t parent_hostid, zbx_vector_db_tag_ptr
* *
******************************************************************************/
static void lld_host_update_tags(zbx_lld_host_t *host, const zbx_vector_db_tag_ptr_t *tags,
- const zbx_vector_ptr_t *lld_macros)
+ const zbx_vector_ptr_t *lld_macros, char **error)
{
int i;
zbx_db_tag_t *proto_tag;
@@ -2268,7 +2253,14 @@ static void lld_host_update_tags(zbx_lld_host_t *host, const zbx_vector_db_tag_p
zbx_free(value);
}
- zbx_merge_tags(&host->tags, &new_tags);
+ if (SUCCEED != zbx_merge_tags(&host->tags, &new_tags, "host", error))
+ {
+ if (0 == host->hostid)
+ {
+ host->flags &= ~ZBX_FLAG_LLD_HOST_DISCOVERED;
+ *error = zbx_strdcatf(*error, "Cannot create host: tag validation failed.\n");
+ }
+ }
zbx_free(tag);
zbx_free(value);
@@ -4434,7 +4426,8 @@ void lld_update_hosts(zbx_uint64_t lld_ruleid, const zbx_vector_ptr_t *lld_rows,
const zbx_lld_row_t *lld_row = (zbx_lld_row_t *)lld_rows->values[i];
if (NULL == (host = lld_host_make(&hosts, host_proto, name_proto, inventory_mode_proto,
- status, discover, &tags, lld_row, lld_macro_paths, use_custom_interfaces)))
+ status, discover, &tags, lld_row, lld_macro_paths, use_custom_interfaces,
+ error)))
{
continue;
}
diff --git a/src/zabbix_server/lld/lld_item.c b/src/zabbix_server/lld/lld_item.c
index 9b33dbbdf58..1d78fe86c5c 100644
--- a/src/zabbix_server/lld/lld_item.c
+++ b/src/zabbix_server/lld/lld_item.c
@@ -1564,23 +1564,6 @@ static void lld_items_validate(zbx_uint64_t hostid, zbx_vector_ptr_t *items, zbx
}
}
- /* check item tags for new and updated discovered items */
- for (i = 0; i < items->values_num; i++)
- {
- item = (zbx_lld_item_t *)items->values[i];
-
- if (0 == (item->flags & ZBX_FLAG_LLD_ITEM_DISCOVERED))
- continue;
-
- if (SUCCEED != zbx_validate_tags(&item->item_tags, "item", error) && 0 == item->itemid)
- {
- item->flags &= ~ZBX_FLAG_LLD_ITEM_DISCOVERED;
- *error = zbx_strdcatf(*error, "Cannot create item: tag validation failed.\n");
- }
-
- zbx_vector_db_tag_ptr_sort(&item->item_tags, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC);
- }
-
/* check preprocessing steps for new and updated discovered items */
for (i = 0; i < items->values_num; i++)
{
@@ -2764,10 +2747,11 @@ static void lld_items_param_make(const zbx_vector_ptr_t *item_prototypes,
* Parameters: item_prototypes - [IN] the item prototypes *
* lld_macro_paths - [IN] use json path to extract from jp_row *
* items - [IN/OUT] sorted list of items *
+ * error - [OUT] error message *
* *
******************************************************************************/
static void lld_items_tags_make(const zbx_vector_ptr_t *item_prototypes, const zbx_vector_ptr_t *lld_macro_paths,
- zbx_vector_ptr_t *items)
+ zbx_vector_ptr_t *items, char **error)
{
int i, j, index;
zbx_lld_item_t *item;
@@ -2815,7 +2799,14 @@ static void lld_items_tags_make(const zbx_vector_ptr_t *item_prototypes, const z
ZBX_MACRO_ANY, NULL, 0);
}
- zbx_merge_tags(&item->item_tags, &new_tags);
+ if (SUCCEED != zbx_merge_tags(&item->item_tags, &new_tags, "item", error))
+ {
+ if (0 == item->itemid)
+ {
+ item->flags &= ~ZBX_FLAG_LLD_ITEM_DISCOVERED;
+ *error = zbx_strdcatf(*error, "Cannot create item: tag validation failed.\n");
+ }
+ }
}
zbx_vector_db_tag_ptr_destroy(&new_tags);
@@ -4445,7 +4436,7 @@ int lld_update_items(zbx_uint64_t hostid, zbx_uint64_t lld_ruleid, zbx_vector_pt
lld_items_make(&item_prototypes, lld_rows, lld_macro_paths, &items, &items_index, error);
lld_items_preproc_make(&item_prototypes, lld_macro_paths, &items);
lld_items_param_make(&item_prototypes, lld_macro_paths, &items);
- lld_items_tags_make(&item_prototypes, lld_macro_paths, &items);
+ lld_items_tags_make(&item_prototypes, lld_macro_paths, &items, error);
lld_link_dependent_items(&items, &items_index);
diff --git a/src/zabbix_server/lld/lld_trigger.c b/src/zabbix_server/lld/lld_trigger.c
index 631b2da6766..63f351da5f0 100644
--- a/src/zabbix_server/lld/lld_trigger.c
+++ b/src/zabbix_server/lld/lld_trigger.c
@@ -1846,7 +1846,8 @@ static void lld_trigger_dependencies_make(const zbx_vector_ptr_t *trigger_protot
* *
******************************************************************************/
static void lld_trigger_tag_make(const zbx_lld_trigger_prototype_t *trigger_prototype,
- zbx_hashset_t *items_triggers, const zbx_lld_row_t *lld_row, const zbx_vector_ptr_t *lld_macro_paths)
+ zbx_hashset_t *items_triggers, const zbx_lld_row_t *lld_row, const zbx_vector_ptr_t *lld_macro_paths,
+ char **error)
{
zbx_lld_trigger_t *trigger;
int i;
@@ -1882,7 +1883,12 @@ static void lld_trigger_tag_make(const zbx_lld_trigger_prototype_t *trigger_pro
NULL, 0);
}
- zbx_merge_tags(&trigger->tags, &new_tags);
+ if (SUCCEED != zbx_merge_tags(&trigger->tags, &new_tags, "trigger", error) && 0 == trigger->triggerid)
+ {
+ trigger->flags &= ~ZBX_FLAG_LLD_TRIGGER_DISCOVERED;
+ *error = zbx_strdcatf(*error, "Cannot create trigger: tag validation failed.\n");
+ }
+
zbx_vector_db_tag_ptr_destroy(&new_tags);
out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__);
@@ -1894,7 +1900,7 @@ out:
* *
******************************************************************************/
static void lld_trigger_tags_make(const zbx_vector_ptr_t *trigger_prototypes, zbx_vector_ptr_t *triggers,
- const zbx_vector_ptr_t *lld_rows, const zbx_vector_ptr_t *lld_macro_paths)
+ const zbx_vector_ptr_t *lld_rows, const zbx_vector_ptr_t *lld_macro_paths, char **error)
{
zbx_lld_trigger_prototype_t *trigger_prototype;
int i, j;
@@ -1932,7 +1938,7 @@ static void lld_trigger_tags_make(const zbx_vector_ptr_t *trigger_prototypes, zb
{
zbx_lld_row_t *lld_row = (zbx_lld_row_t *)lld_rows->values[j];
- lld_trigger_tag_make(trigger_prototype, &items_triggers, lld_row, lld_macro_paths);
+ lld_trigger_tag_make(trigger_prototype, &items_triggers, lld_row, lld_macro_paths, error);
}
}
@@ -2242,31 +2248,6 @@ static void lld_triggers_validate(zbx_uint64_t hostid, zbx_vector_ptr_t *trigger
/******************************************************************************
* *
- * Purpose: validate created or updated trigger tags *
- * *
- ******************************************************************************/
-static void lld_triggers_tags_validate(zbx_vector_ptr_t *triggers, char **error)
-{
- int i;
- zbx_lld_trigger_t *trigger;
-
- for (i = 0; i < triggers->values_num; i++)
- {
- trigger = (zbx_lld_trigger_t *)triggers->values[i];
-
- if (0 == (trigger->flags & ZBX_FLAG_LLD_TRIGGER_DISCOVERED))
- continue;
-
- if (SUCCEED != zbx_validate_tags(&trigger->tags, "trigger", error) && 0 == trigger->triggerid)
- {
- trigger->flags &= ~ZBX_FLAG_LLD_TRIGGER_DISCOVERED;
- *error = zbx_strdcatf(*error, "Cannot create trigger: tag validation failed.\n");
- }
- }
-}
-
-/******************************************************************************
- * *
* Purpose: transforms the simple trigger expression to the DB format *
* *
* Example: *
@@ -3622,8 +3603,7 @@ int lld_update_triggers(zbx_uint64_t hostid, zbx_uint64_t lld_ruleid, const zbx_
lld_triggers_validate(hostid, &triggers, error);
lld_trigger_dependencies_make(&trigger_prototypes, &triggers, lld_rows, error);
lld_trigger_dependencies_validate(&triggers, error);
- lld_trigger_tags_make(&trigger_prototypes, &triggers, lld_rows, lld_macro_paths);
- lld_triggers_tags_validate(&triggers, error);
+ lld_trigger_tags_make(&trigger_prototypes, &triggers, lld_rows, lld_macro_paths, error);
ret = lld_triggers_save(hostid, &trigger_prototypes, &triggers);
lld_remove_lost_objects("trigger_discovery", "triggerid", &triggers, lifetime, lastcheck, DBdelete_triggers,
get_trigger_info);