Ad Widget

Collapse

host.create fails

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hfk
    Junior Member
    • Nov 2020
    • 3

    #1

    host.create fails

    I am trying to create a new host using the API. I am able to get information about an existing host, about maintenance groups, periods and more, but I get an error when I try to create the host.



    $API_Host_Create = @{

    jsonrpc = "2.0"

    method = "host.create"

    params = @{

    host = "presaprsa2002v"

    interfaces = @{

    type = "1"

    main = "1"

    useip = "1"

    ip = "10.163.121.92"

    dns = "presaprsa2002v.xyz.com"

    port = "10050"

    }

    groups = @{

    groupid = "1085"

    }

    templates = @{

    templateid = "24774"

    }

    }

    auth = "$($auth_session)"

    id = 1

    }

    function ESA_ZBX_HostCreate($hg_id, [boolean]$action, $ZAPI_Site)

    {
    $auth = zabbix_api($API_Login)
    $auth_session = ($auth.result)
    $API_Host_Create.auth = $auth_session

    if ($auth.result)

    {

    #$($API_Host_Create | ConvertTo-Json) | out-file hanscreate.json
    $zhostcreate = zabbix_api($API_Host_Create)
    $hostcreate_error = $zhostcreate.error
    $hostcreate_result = $zhostcreate.result


    return $hostcreate_result.result

    }

    }

    $Test = ESA_ZBX_HostCreate $DCE_SVS_id $true $DCE_A

    NB! The parameters are not used at this moment.

    Create result: @{code=-32500; message=Application error.; data=No permissions to referred object or it does not exist!}

    I would very much appreciate suggestions on how to solve the problem. I am using Zabbix 4.4.

    Thank you very much
    Last edited by hfk; 19-12-2020, 13:59.
  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #2
    Maybe the account used to login to the API doesn't have enough permission to create a host.

    Comment


    • hfk
      hfk commented
      Editing a comment
      If I use my "admin-account" I can create a host from the normal Zabbix-GUI. If I use the "admin-account" in the script it fails. My "Zabbix-Admin" tells me I have the necessary rights, but I agree with you that it sure looks "fishy".
  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #3
    I use https://github.com/lukecyca/pyzabbix so I don't have to mess with the lower level API stuff, but since we auto register hosts, I have never scripted a host.create. Our network team does, they used Perl in the past, not sure what they use not, but I don't ever see their code.

    Comment

    • hfk
      Junior Member
      • Nov 2020
      • 3

      #4
      Problem solved. I use PowerShell and the json-object had to be rewritten in a way PowerShell could understand.
      eg.
      groups = @(@{

      groupid = "1085"

      })

      When I corrected this in the definition of the object everything began working.

      In the function Zabbix_api($body) I put in a line "write-host $bodyJson" to see what the object transferred really looked like. This gave a good clue.

      Thank you for answering and helping me here.

      Comment

      Working...