ZABBIX BUGS AND ISSUES

API in Zabbix v2 fails to add maintenance period via API (SQL error)

Details

  • Type: Bug Bug
  • Status: Reopened Reopened
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: 2.0.0
  • Fix Version/s: 2.0.4rc1, 2.1.0
  • Component/s: API (A)
  • Labels:
  • Environment:
    API
  • Zabbix ID:
    RTF

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;
}
?>

Activity

Hide
NFOrce Entertainment added a comment -

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

Show
NFOrce Entertainment added a comment - The actual version is 2.0.0 (checked it wrong) but i cant seem to change it, maybe an admin can?
Hide
richlv added a comment -

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

Show
richlv added a comment - can you please show exact json that you are sending as well ?
Hide
NFOrce Entertainment added a comment - - edited

{"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.

Show
NFOrce Entertainment added a comment - - edited {"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.
Hide
Eduards Samersovs added a comment -

Eduards Samersovs 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 http://www.zabbix.com/documentation/2.0/manual/appendix/api/maintenance/definitions

Show
Eduards Samersovs added a comment - Eduards Samersovs 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 http://www.zabbix.com/documentation/2.0/manual/appendix/api/maintenance/definitions
Hide
NFOrce Entertainment added a comment -

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.

Show
NFOrce Entertainment added a comment - 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.
Hide
richlv added a comment -

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

Show
richlv added a comment - indeed, if we still return sql error in 2.0 svn head, that's a bug
Hide
Eduards Samersovs added a comment -

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

Show
Eduards Samersovs added a comment - Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-5656
Hide
Eduards Samersovs added a comment -

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

Show
Eduards Samersovs added a comment - Fixed in versions pre-2.1.0 (beta) r30778, pre-2.0.3 r30777
Hide
Pavels Jelisejevs added a comment - - edited

(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 Samersovs RESOLVED

Show
Pavels Jelisejevs added a comment - - edited (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 Samersovs RESOLVED

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: