[ZBX-10842] httptest.update fails when updating steps without httpstepid Created: 2016 May 24  Updated: 2017 May 30  Resolved: 2016 Oct 17

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 3.0.3
Fix Version/s: 2.2.16rc1, 3.0.6rc1, 3.2.2rc1, 3.4.0alpha1

Type: Incident report Priority: Blocker
Reporter: Marián Černý Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: webmonitoring
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

FreeBSD


Attachments: File zabbix-CHttpTestManager.php.diff    
Issue Links:
Duplicate
is duplicated by ZBX-10967 httptest.update API has several probl... Closed

 Description   

When I create an http test using httptest.create and then try to update the test with exact same data using httptest.update, the update fails with the following DB error:

Zabbix error in request: '{"jsonrpc":"2.0","method":"httptest.update","params":{"httptestid":"5","hostid":"10149","applicationid":"973","name":"Sensor17: test.cz","agent":"Mozilla
/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) S","authentication":"0","delay":"300","http_password":"","http_user":"","macros":"","status":"0","steps":[

{"name":"step1","url":"http:\\/\\/test.cz","required":"","status_codes":"200","no":1}

]},"auth":"559aa0854bf2540f6656235401008f95","id":6}' Response: array ( 'code' => -32500, 'message' => 'Application error.', 'data' => 'SQL statement execution has failed "INSERT INTO items_applications (applicationid,itemid,itemappid) VALUES (\'973\',\'27679\',\'13296\')".', )

More precisely it fails on duplicate key 13296 for itemappid.

I have tried to track down the error and here is the top of the stack trace from the exception:

exception 'DBException' with message 'SQL statement execution has failed "INSERT INTO items_applications (applicationid,itemid,itemappid) VALUES ('973','27679','13296')".' in /usr/local/www/zabbix3/include/classes/db/DB.php:81
Stack trace:
#0 /usr/local/www/zabbix3/include/classes/db/DB.php(441): DB::exception(1, 'SQL statement e...')
#1 /usr/local/www/zabbix3/include/classes/api/managers/CHttpTestManager.php(874): DB::insert('items_applicati...', Array)
#2 /usr/local/www/zabbix3/include/classes/api/managers/CHttpTestManager.php(219): CHttpTestManager->createStepsReal(Array, Array)
#3 /usr/local/www/zabbix3/include/classes/api/managers/CHttpTestManager.php(603): CHttpTestManager->update(Array)
#4 /usr/local/www/zabbix3/include/classes/api/managers/CHttpTestManager.php(58): CHttpTestManager->save(Array)
#5 /usr/local/www/zabbix3/include/classes/api/services/CHttpTest.php(328): CHttpTestManager->persist(Array)
#6 [internal function]: CHttpTest->update(Array)

While playing around in CHttpTestManager.php I think I have found what the problem is. In update() function the $deleteStepItemIds is collected and deleted at the end of this function. But this is too late, because when createStepsReal() function is invoked, inside it searches current items and uses the ones that are going to be deleted.

I have solved the problem for me by moving the deletion code before invoking createStepsReal() as in the attached diff.



 Comments   
Comment by Kim Jongkwon [ 2016 Jul 13 ]

This SQL ERROR occurs when using the parameters below.

  • Duplicate step "name" already exists in the httptest (zabbix.httpstep)
  • Does not contain "httpstepid" in steps
  • httptest with a same "applicationid"
Comment by Kim Jongkwon [ 2016 Jul 13 ]

NOTE:
・If you use same data with different "applicationid" & repeat ...
1st time, return 'success' : But this call does not create a items. It means monitoring 'items' are disappeared. (zabbix.items)
2nd time, return 'success' : In this case, step items will be created. (It's okay.)
And then, SQL ERROR occurs. because all of the above parameters conditions are met. (+ same applicationid)

・If you use same data without "applicationid" & repeat...
Always return 'success' response. but items disappear and generated - just like toggle. and generated new steps does not connected own "applicationid" (zabbix.httptest)

Comment by vitalijs.cemeris (Inactive) [ 2016 Jul 15 ]

Main issue fixed in the development branch svn://svn.zabbix.com/branches/dev/ZBX-10842
r61016, r61094, r61097, r61218.

Comment by vitalijs.cemeris (Inactive) [ 2016 Jul 15 ]

(1) Second case described in ZBX-10967 "New step items was disappeared".
RESOLVED in r61257

oleg.egorov CLOSED

Comment by vitalijs.cemeris (Inactive) [ 2016 Jul 19 ]

(2) Third case described in ZBX-10967 "New steps do not connected own applicationid".

RESOLVED in r61094, r61097, r61218

oleg.egorov CLOSED

Comment by vitalijs.cemeris (Inactive) [ 2016 Jul 29 ]

(3) Strings deleted:

  • Item with key \"%1$s\" already exists.

oleg.egorov CLOSED

Comment by Oleg Egorov (Inactive) [ 2016 Sep 16 ]

(4) Undefined index

$httpTests = API::HttpTest()->update(array(
	'httptestid' => 80,
	'name' => 'test4',
	'hostid' => 10114,
	'status' => 0,
	'delay' => 60,
	'steps' => array(array(
		'name' => 'test',
		'url' => 'http://mycompany.com',
		'status_codes' => 200,
	    'no' => 1
	))
));

Undefined index: application [hosts.php:123 → CAPIObject->update() → CAPIObject->__call() → czbxrpc::call() → czbxrpc::callAPI() → call_user_func() → CHttpTest->update() → CHttpTestManager->persist() → CHttpTestManager->save() → CHttpTestManager->update() in C:\xampp\htdocs\ZBX-10842\frontends\php\api\classes\managers\CHttpTestManager.php:228]

vitalijs.cemeris RESOLVED in r62670

oleg.egorov CLOSED

Comment by Oleg Egorov (Inactive) [ 2016 Sep 16 ]

(5) Coding style
CHttpTestManager: 239 - isset

if (isset($httpTest['steps'])) { 

vitalijs.cemeris RESOLVED in r62674

oleg.egorov CLOSED

Comment by Oleg Egorov (Inactive) [ 2016 Sep 16 ]

(6) HttpTest with application

$httpTests = API::HttpTest()->create(array(
	'httptestid' => 80,
	'name' => 'test6',
	'hostid' => 10114,
	'status' => 0,
	'delay' => 60,
	'applicationid' => 543,
	'steps' => array(array(
		'name' => 'test',
		'url' => 'http://mycompany.com',
		'status_codes' => 200,
	    'no' => 1
	))
));

Missing argument 2 for CHttpTestManager::createItemsApplications(), called in C:\xampp\htdocs\ZBX-10842\frontends\php\api\classes\managers\CHttpTestManager.php on line 951 and defined [hosts.php:124 → CAPIObject->create() → CAPIObject->__call() → czbxrpc::call() → czbxrpc::callAPI() → call_user_func() → CHttpTest->create() → CHttpTestManager->persist() → CHttpTestManager->save() → CHttpTestManager->update() → CHttpTestManager::updateItemsApplications() → CHttpTestManager::createItemsApplications() in C:\xampp\htdocs\ZBX-10842\frontends\php\api\classes\managers\CHttpTestManager.php:960]
Undefined variable: applicationid [hosts.php:124 → CAPIObject->create() → CAPIObject->__call() → czbxrpc::call() → czbxrpc::callAPI() → call_user_func() → CHttpTest->create() → CHttpTestManager->persist() → CHttpTestManager->save() → CHttpTestManager->update() → CHttpTestManager::updateItemsApplications() → CHttpTestManager::createItemsApplications() in C:\xampp\htdocs\ZBX-10842\frontends\php\api\classes\managers\CHttpTestManager.php:961]

HttpTest create with 'httptestid'. In clean 2.2 this issue not exist

No SQL error, but issue still exist

vitalijs.cemeris RESOLVED in r62616, r62631, r62667

oleg.egorov CLOSED

Comment by Oleg Egorov (Inactive) [ 2016 Sep 23 ]

(7) [A] Please remove unnecessary comments.

vitalijs.cemeris RESOLVED in r62734

oleg.egorov CLOSED

Comment by Oleg Egorov (Inactive) [ 2016 Oct 05 ]

TESTED

Comment by vitalijs.cemeris (Inactive) [ 2016 Oct 13 ]

Fixed in:

  • pre-2.2.16rc1 r63134
  • pre-3.0.6rc1 r63144
  • pre-3.2.2rc1 r63145
  • pre-3.3.0 r63146
Comment by vitalijs.cemeris (Inactive) [ 2016 Oct 14 ]

(8) [D] API documentation:

  • fixed SQL error when updating httptest with applicationid and without httpstepid parameters
  • prevented disappearing of step items when updating httptest without applicationid, httpstepid parameters
  • fixed connecting web scenario applicationid to created steps when updating with API httptest.update mehtod

Changes in 2.2, Changes in 3.0, Changes in 3.2

RESOLVED

martins-v Moved to appropriate sections - 2.2.16, 3.0.6, 3.2.2. CLOSED

iivs "mehtod"

REOPENED

martins-v RESOLVED

iivs The name of the API method is before the sentence. Why need to repeat it in the end again?

martins-v Removed. RESOLVED

iivs Ok, looks better. CLOSED

Generated at Thu Mar 28 22:45:36 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.