Ad Widget

Collapse

Add graph items via API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jauge
    Junior Member
    • Feb 2014
    • 2

    #1

    Add graph items via API

    Hi,

    I need to programatically add graph items to an existing graph.

    If I understand the documentation right, I need to call the graph.update method, with an array of gitems, each of which has to have one of the following parameters:
    gitemid, for the existing gitems which I don't want to modify
    itemid, for the new ones I want to create

    The calls I'm using look like the following one:
    {"jsonrpc":"2.0","id":2,"auth":"xxxx","method":"gr aph.update","params":{"graphid": "990","gitems":[{"graphid": "990","gitemid": "3075"},{"graphid": "990","itemid": "4281"}]}}

    Which gives me this answer:
    {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"No permissions to referred object or it does not exist!"},"id":2}

    Adding new items by not setting gitemid, and setting itemid works fine. However, old items get deleted.

    What am I doing wrong? Is this the correct way to add new items to a graph?

    Thanks!
    Jordi
  • DRVTiny
    Senior Member
    • Sep 2011
    • 162

    #2
    I have the same problem and get the same error messsage.
    Could anybody help us?

    Comment

    • jauge
      Junior Member
      • Feb 2014
      • 2

      #3
      Hello DRVTiny.

      I fixed this by modifying the /usr/share/zabbix/api/classes/CGraphGeneral.php file.

      This is a patch you should apply:

      --- CGraphGeneral.php.old 2014-08-08 13:27:02.310078002 +0000
      +++ CGraphGeneral.php 2014-08-08 13:28:17.886078003 +0000
      @@ -618,6 +618,11 @@

      // assigning with key preserves unique itemids
      $itemIds[$gitem['itemid']] = $gitem['itemid'];
      + if (isset($gitem['gitemid'])){
      + $itemIds[$gitem['gitemid']] = $gitem['gitemid'];
      + } else {
      + $itemIds[$gitem['itemid']] = $gitem['itemid'];
      + }
      }
      }

      Good luck!
      Attached Files

      Comment

      Working...