Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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