ZABBIX BUGS AND ISSUES
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-5656

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

    Details

      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 - - edited

        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 > Maintenance object

        Show
        Eduards Samersovs added a comment - - edited 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 > Maintenance object
        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

        Alexander Vladishev CLOSED

        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 Alexander Vladishev CLOSED
        Hide
        Ivo Kurzemnieks added a comment -

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

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

        Show
        Ivo Kurzemnieks added a comment - "timeperiods" should now be always an array of arrays. RESOLVED in svn://svn.zabbix.com/branches/dev/ZBX-5656 r52588
        Hide
        Ivo Kurzemnieks added a comment -

        Fixed in:

        • pre-2.0.15rc1 r52701
        • pre-2.2.10rc1 r52702
        • pre-2.4.5rc1 r52703
        • pre-2.5.0 (trunk) r52704
        Show
        Ivo Kurzemnieks added a comment - Fixed in: pre-2.0.15rc1 r52701 pre-2.2.10rc1 r52702 pre-2.4.5rc1 r52703 pre-2.5.0 (trunk) r52704
        Show
        Alexander Vladishev added a comment - - edited (5) Documentation: https://www.zabbix.com/documentation/2.0/manual/appendix/api/changes_2.0 https://www.zabbix.com/documentation/2.2/manual/api/changes_2.2 https://www.zabbix.com/documentation/2.4/manual/api/changes_2.4 Alexander Vladishev RESOLVED Ivo Kurzemnieks Thanks! CLOSED.

          People

          • Assignee:
            Unassigned
            Reporter:
            NFOrce Entertainment
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: