diff options
author | Vladislavs Sokurenko <vladislavs.sokurenko@zabbix.com> | 2022-06-16 09:55:57 +0300 |
---|---|---|
committer | Andris Zeila <andris.zeila@zabbix.com> | 2022-06-16 09:55:57 +0300 |
commit | a30355a659273969ee48c4a33ebaa725d580af5d (patch) | |
tree | ae33347cfc839b442a97dd05a8364af4ef1a3525 | |
parent | ac59c7acbf54e4134e3c252fd4d97c550b11f2e4 (diff) | |
parent | 451df6af8bb3f9e73483a407407347680d75cccb (diff) |
....I..... [ZBX-20861] fixed incorrect naming of web scenario items after upgrade
Merge in ZBX/zabbix from feature/ZBX-20861-6.0-2 to release/6.0
* commit '451df6af8bb3f9e73483a407407347680d75cccb':
........S. [ZBX-20861] removed useless includes
....I..... [ZBX-20861] fixed incorrect naming of web scenario items after upgrade
-rw-r--r-- | ChangeLog.d/bugfix/ZBX-20861 | 1 | ||||
-rw-r--r-- | create/src/schema.tmpl | 2 | ||||
-rw-r--r-- | src/libs/zbxdbupgrade/dbupgrade_6000.c | 150 |
3 files changed, 152 insertions, 1 deletions
diff --git a/ChangeLog.d/bugfix/ZBX-20861 b/ChangeLog.d/bugfix/ZBX-20861 new file mode 100644 index 00000000000..110a36300d4 --- /dev/null +++ b/ChangeLog.d/bugfix/ZBX-20861 @@ -0,0 +1 @@ +....I..... [ZBX-20861] fixed incorrect naming of web scenario items after upgrade (vso) diff --git a/create/src/schema.tmpl b/create/src/schema.tmpl index 3877a92200f..5f1760bb4eb 100644 --- a/create/src/schema.tmpl +++ b/create/src/schema.tmpl @@ -1936,4 +1936,4 @@ TABLE|dbversion|dbversionid| FIELD |dbversionid |t_id | |NOT NULL |0 FIELD |mandatory |t_integer |'0' |NOT NULL | FIELD |optional |t_integer |'0' |NOT NULL | -ROW |1 |6000000 |6000002 +ROW |1 |6000000 |6000004 diff --git a/src/libs/zbxdbupgrade/dbupgrade_6000.c b/src/libs/zbxdbupgrade/dbupgrade_6000.c index 8888decca6e..d87cda598ed 100644 --- a/src/libs/zbxdbupgrade/dbupgrade_6000.c +++ b/src/libs/zbxdbupgrade/dbupgrade_6000.c @@ -59,6 +59,154 @@ static int DBpatch_6000002(void) return SUCCEED; } +#define HTTPSTEP_ITEM_TYPE_RSPCODE 0 +#define HTTPSTEP_ITEM_TYPE_TIME 1 +#define HTTPSTEP_ITEM_TYPE_IN 2 +#define HTTPSTEP_ITEM_TYPE_LASTSTEP 3 +#define HTTPSTEP_ITEM_TYPE_LASTERROR 4 + +static int DBpatch_6000003(void) +{ + DB_ROW row; + DB_RESULT result; + int ret = SUCCEED; + char *sql = NULL; + size_t sql_alloc = 0, sql_offset = 0, out_alloc = 0; + char *out = NULL; + + if (ZBX_PROGRAM_TYPE_SERVER != program_type) + return SUCCEED; + + DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset); + + result = DBselect( + "select hi.itemid,hi.type,ht.name" + " from httptestitem hi,httptest ht" + " where hi.httptestid=ht.httptestid"); + + while (SUCCEED == ret && NULL != (row = DBfetch(result))) + { + zbx_uint64_t itemid; + char *esc; + size_t out_offset = 0; + unsigned char type; + + ZBX_STR2UINT64(itemid, row[0]); + ZBX_STR2UCHAR(type, row[1]); + + switch (type) + { + case HTTPSTEP_ITEM_TYPE_IN: + zbx_snprintf_alloc(&out, &out_alloc, &out_offset, + "Download speed for scenario \"%s\".", row[2]); + break; + case HTTPSTEP_ITEM_TYPE_LASTSTEP: + zbx_snprintf_alloc(&out, &out_alloc, &out_offset, + "Failed step of scenario \"%s\".", row[2]); + break; + case HTTPSTEP_ITEM_TYPE_LASTERROR: + zbx_snprintf_alloc(&out, &out_alloc, &out_offset, + "Last error message of scenario \"%s\".", row[2]); + break; + } + esc = DBdyn_escape_field("items", "name", out); + zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update items set name='%s' where itemid=" + ZBX_FS_UI64 ";\n", esc, itemid); + zbx_free(esc); + + ret = DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset); + } + DBfree_result(result); + + DBend_multiple_update(&sql, &sql_alloc, &sql_offset); + + if (SUCCEED == ret && 16 < sql_offset) + { + if (ZBX_DB_OK > DBexecute("%s", sql)) + ret = FAIL; + } + + zbx_free(sql); + zbx_free(out); + + return ret; +} + +static int DBpatch_6000004(void) +{ + DB_ROW row; + DB_RESULT result; + int ret = SUCCEED; + char *sql = NULL; + size_t sql_alloc = 0, sql_offset = 0, out_alloc = 0; + char *out = NULL; + + if (ZBX_PROGRAM_TYPE_SERVER != program_type) + return SUCCEED; + + DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset); + + result = DBselect( + "select hi.itemid,hi.type,hs.name,ht.name" + " from httpstepitem hi,httpstep hs,httptest ht" + " where hi.httpstepid=hs.httpstepid" + " and hs.httptestid=ht.httptestid"); + + while (SUCCEED == ret && NULL != (row = DBfetch(result))) + { + zbx_uint64_t itemid; + char *esc; + size_t out_offset = 0; + unsigned char type; + + ZBX_STR2UINT64(itemid, row[0]); + ZBX_STR2UCHAR(type, row[1]); + + switch (type) + { + case HTTPSTEP_ITEM_TYPE_IN: + zbx_snprintf_alloc(&out, &out_alloc, &out_offset, + "Download speed for step \"%s\" of scenario \"%s\".", row[2], row[3]); + break; + case HTTPSTEP_ITEM_TYPE_TIME: + zbx_snprintf_alloc(&out, &out_alloc, &out_offset, + "Response time for step \"%s\" of scenario \"%s\".", row[2], row[3]); + break; + case HTTPSTEP_ITEM_TYPE_RSPCODE: + zbx_snprintf_alloc(&out, &out_alloc, &out_offset, + "Response code for step \"%s\" of scenario \"%s\".", row[2], row[3]); + break; + } + + esc = DBdyn_escape_field("items", "name", out); + zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update items set name='%s' where itemid=" + ZBX_FS_UI64 ";\n", esc, itemid); + zbx_free(esc); + + ret = DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset); + } + DBfree_result(result); + + DBend_multiple_update(&sql, &sql_alloc, &sql_offset); + + if (SUCCEED == ret && 16 < sql_offset) + { + if (ZBX_DB_OK > DBexecute("%s", sql)) + ret = FAIL; + } + + zbx_free(sql); + zbx_free(out); + + return ret; +} + +#undef HTTPSTEP_ITEM_TYPE_RSPCODE +#undef HTTPSTEP_ITEM_TYPE_TIME +#undef HTTPSTEP_ITEM_TYPE_IN +#undef HTTPSTEP_ITEM_TYPE_LASTSTEP +#undef HTTPSTEP_ITEM_TYPE_LASTERROR + #endif DBPATCH_START(6000) @@ -68,5 +216,7 @@ DBPATCH_START(6000) DBPATCH_ADD(6000000, 0, 1) DBPATCH_ADD(6000001, 0, 0) DBPATCH_ADD(6000002, 0, 0) +DBPATCH_ADD(6000003, 0, 0) +DBPATCH_ADD(6000004, 0, 0) DBPATCH_END() |