Ad Widget

Collapse

Error in API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SoftDed
    Junior Member
    • May 2013
    • 1

    #1

    Error in API

    Hello!

    I am making script for automation adding new host to zabbix, but I find error in API.

    My script:
    Code:
      zapi.action.create( 
        {
          'name': template + ' ' + zone,
          'eventsource': 1,
          'evaltype': 2,
          'esc_period': 0,
          'conditions': dchecks2,
          'operations': [
            {
              'operationtype': 2
            },
            {
              'operationtype': 4,
              'opgroup': [{
                'groupid': groupId
              }]
            },
            {
              'operationtype': 6,
              'optemplate': [{
                'templateid': templateId
              }]
            },
            {
              'operationtype': 1,                  
              'opcommand': {
                'type': 0,
                'command': 'discovery.eltek.hostname.py[{DISCOVERY.DEVICE.IPADDRESS}, "123456"]',
                'execute_on': 1,
                'opcommand_hst': [{
                  'hostid': 0
                }]
              }
            }
          ]
        }
      )
    And I see error:
    zabbix_api.ZabbixAPIException: (u'Error -32602: Invalid params., You did not specify targets for action operation command "discovery.eltek.hostname.py[{DISCOVERY.DEVICE.IPADDRESS},

    I open file api/classes/CAction.php and see, that on strings 1560-1580:

    Code:
                                            $groupids = array();
                                            if (isset($operation['opcommand_grp'])) {
                                                    $groupids = zbx_objectValues($operation['opcommand_grp'], 'groupid');
                                            }
    
                                            $hostids = array();
                                            $withoutCurrent = true;
                                            if (isset($operation['opcommand_hst'])) {
                                                    foreach ($operation['opcommand_hst'] as $hstCommand) {
                                                            if ($hstCommand['hostid'] == 0) {
                                                                    $withoutCurrent = false;
                                                            }
                                                            else {
                                                                    $hostids[$hstCommand['hostid']] = $hstCommand['hostid'];
                                                            }
                                                    }
                                            }
    It have mistake in variable $operation missing ['opcommand']. Because always write:

    if (empty($groupids) && empty($hostids) && $withoutCurrent) {
    if ($operation['opcommand']['type'] == ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT) {
    self::exception(ZBX_API_ERROR_PARAMETERS, _s('You did not specify targets for action operation global script "%s".', $scripts[$operation['opcommand']['scriptid']]['name']));
    }
    else {
    self::exception(ZBX_API_ERROR_PARAMETERS, _s('You did not specify targets for action operation command "%s".', $operation['opcommand']['command']));
    }
Working...