[ZBX-5656] API in Zabbix v2 fails to add maintenance period via API (SQL error) Created: 2012 Oct 04  Updated: 2017 May 30  Resolved: 2015 Mar 23

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 2.0.0
Fix Version/s: 2.0.4rc1, 2.0.15rc1, 2.1.0, 2.2.10rc1, 2.4.5rc1, 2.5.0

Type: Incident report Priority: Trivial
Reporter: NFOrce Entertainment Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: api, maintenance
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Im trying to create a maintenance period here. Ive got the correct array, but zabbix gives me this error:

string(92) "API error -32500: SQL statement execution has failed "INSERT INTO timeperiods () VALUES ()"."

Small piece of code:

<?php
	public function createMaintenance($params = null, $name, $description, $from, $till){
		try{
			$params['groupids'] = array('23');
			$params['name'] = $name;
			$params['description'] = $description;
			$params['active_since'] = $from;
			$params['active_till'] = $till;
			$params['maintenance_type'] = 0;
			$params['timeperiods'] = array('timeperiod_type' => 0, 'start_date' => $from, 'period' => 36000);

			$response = $this->api->maintenanceCreate($params);
		}catch(Exception $e){
			return $e->getMessage();
		}
		
		return $response;
	}
?>


 Comments   
Comment by NFOrce Entertainment [ 2012 Oct 05 ]

The actual version is 2.0.0 (checked it wrong) but i cant seem to change it, maybe an admin can?

Comment by richlv [ 2012 Oct 05 ]

can you please show exact json that you are sending as well ?

Comment by NFOrce Entertainment [ 2012 Oct 05 ]
{"jsonrpc":"2.0",
 "method":"maintenance.create",
 "params":{
     "groupids":[23],
     "name":"Test api",
     "description":"description",
     "active_since":1349428991,
     "active_till":1349511791,
     "maintenance_type":0,
     "timeperiods":{
          "timeperiod_type":0,
          "start_date":1349428991,
          "period":36000}
     },
 "auth":"b8733f94ece438b9026a12f6788120e7",
 "id":"13494253912288"}

Im using this library btw:

http://zabbixapi.confirm.ch/

The JSON seems correct to me as Zabbix is returning an SQL error.

Comment by Eduards Samersovs (Inactive) [ 2012 Oct 05 ]

Eduards Try to replace in your code line:

$params['timeperiods'] = array('timeperiod_type' => 0, 'start_date' => $from, 'period' => 36000);

to

$params['timeperiods'] = array(array('timeperiod_type' => 0, 'start_date' => $from, 'period' => 36000));

because 'timeperiods' is array of timeperiod objects.

Addition info can be found in > Maintenance object

Comment by NFOrce Entertainment [ 2012 Oct 05 ]

Thank you very much Eduards. That did the trick. Maybe a more graceful error in future releases would avoid these kind of misunderstandings. As an SQL error should not be returned in my opinion.

Comment by richlv [ 2012 Oct 05 ]

indeed, if we still return sql error in 2.0 svn head, that's a bug

Comment by Eduards Samersovs (Inactive) [ 2012 Oct 05 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-5656

Comment by Eduards Samersovs (Inactive) [ 2012 Oct 10 ]

Fixed in versions pre-2.1.0 (beta) r30778, pre-2.0.3 r30777

Comment by Pavels Jelisejevs (Inactive) [ 2012 Oct 10 ]

(1) Please document this fix in the 2.0 API changelog

http://www.zabbix.com/documentation/2.0/manual/appendix/api/changes_2.0

Eduards RESOLVED

sasha CLOSED

Comment by Ivo Kurzemnieks [ 2015 Mar 06 ]

"timeperiods" should now be always an array of arrays.

RESOLVED in svn://svn.zabbix.com/branches/dev/ZBX-5656 r52588

Comment by Ivo Kurzemnieks [ 2015 Mar 12 ]

Fixed in:

  • pre-2.0.15rc1 r52701
  • pre-2.2.10rc1 r52702
  • pre-2.4.5rc1 r52703
  • pre-2.5.0 (trunk) r52704
Comment by Alexander Vladishev [ 2015 Mar 23 ]

(5) Documentation:

sasha RESOLVED

iivs Thanks! CLOSED.

Generated at Fri Mar 29 02:44:21 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.