Created
August 3, 2016 15:53
-
-
Save Sam-Martin/43c78a9efc4916f35971e21843ffd37b to your computer and use it in GitHub Desktop.
PowerShell Zabbix API Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!$credential){ | |
$credential = Get-Credential | |
} | |
$baseurl = 'http://zabbix.global.root' | |
$params = @{ | |
body = @{ | |
"jsonrpc"= "2.0" | |
"method"= "user.login" | |
"params"= @{ | |
"user"= $credential.UserName | |
"password"= $credential.GetNetworkCredential().Password | |
} | |
"id"= 1 | |
"auth"= $null | |
} | ConvertTo-Json | |
uri = "$baseurl/api_jsonrpc.php" | |
headers = @{"Content-Type" = "application/json"} | |
method = "Post" | |
} | |
$result = Invoke-WebRequest @params | |
$params.body = @{ | |
"jsonrpc"= "2.0" | |
"method"= "host.get" | |
"params"= @{ | |
output = "extend" | |
selectFunctions = "extend" | |
selectLastEvent = "extend" | |
selectGroups = "extend" | |
selectHosts = "extend" | |
} | |
auth = ($result.Content | ConvertFrom-Json).result | |
id = 2 | |
} | ConvertTo-Json | |
$result = Invoke-WebRequest @params | |
$result = $result.Content | ConvertFrom-Json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment