Ad Widget

Collapse

Zabbix API + PowerShell + host.create

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dafus
    Junior Member
    • Feb 2016
    • 12

    #1

    Zabbix API + PowerShell + host.create

    Hi,

    I would like to create host by powershell. To do this i use something like this:

    $Body = @{ jsonrpc = $session.jsonrpc; method = "host.create"; params = @{ host = "MSDC02"; interfaces = @{type = 1;main=1;useip=1;ip="192.168.70.12";dns= "";port="10050"}; groups = @{"groupid" = 12};templates = @{templateid ="10081"} }; auth = $session.Session; id =$session.id }

    Next, i convert this array to BodyJSON by ConvertTo-Json

    Result:

    {
    "method": "host.create",
    "params": {
    "host": "MSDC02",
    "groups": {
    "groupid": 12
    },
    "templates": {
    "templateid": "10081"
    },
    "interfaces": {
    "port": "10050",
    "dns": "",
    "ip": "192.168.70.12",
    "useip": 1,
    "type": 1,
    "main": 1
    }
    },
    "id": 1,
    "jsonrpc": "2.0",
    "auth": "d757ebabab3f29ed4edbc60ff9b793e6"
    }

    And last thing:

    $a = Invoke-RestMethod "$URL/api_jsonrpc.php" -ContentType "application/json" -Body $BodyJSON -Method Post -Verbose

    It doesn't work:

    jsonrpc error id
    ------- ----- --
    2.0 @{code=-32500; message=Application error.; data=No permissions to referred object or it does not exist!} 1



    After research i know that it's something wrong with groups array. But I have no idea how could I different write this array. Thanks for any suggestions.
  • dafus
    Junior Member
    • Feb 2016
    • 12

    #2
    I should add another array to groups and use ConvertTo-Json with -Depth parameter. It works. Solved.

    Comment

    Working...