Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Created August 3, 2016 15:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Sam-Martin/43c78a9efc4916f35971e21843ffd37b to your computer and use it in GitHub Desktop.
Save Sam-Martin/43c78a9efc4916f35971e21843ffd37b to your computer and use it in GitHub Desktop.
PowerShell Zabbix API Example
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