Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Last active April 11, 2018 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sam-Martin/61b27880728371270be4915c445fa45f to your computer and use it in GitHub Desktop.
Save Sam-Martin/61b27880728371270be4915c445fa45f to your computer and use it in GitHub Desktop.
Update Triggers via Zabbix API using search example
if(!$creds){
$creds = get-credential
}
$url = "http://zabbix.example.com"
$payload = @{
jsonrpc = "2.0"
method = "user.login"
params = @{
user = $creds.UserName
password = $creds.GetNetworkCredential().Password
}
id = 1
auth = $null
} | convertto-json
$response = Invoke-WebRequest -Uri $url/api_jsonrpc.php -ContentType "application/json" -UseBasicParsing -Body $payload -method Post
$token = ($response.Content | convertfrom-json).result;
$payload = @{
jsonrpc = "2.0"
method = "trigger.get"
params = @{
output = @(
"triggerid",
"description",
"status"
)
search = @{
"description" = "Site Check*"
}
"searchWildcardsEnabled"= 1
}
id = 1
auth = $token
} | convertto-json
$response = Invoke-WebRequest -Uri $url/api_jsonrpc.php -ContentType "application/json" -UseBasicParsing -Body $payload -method Post
$result = ($response.Content | convertfrom-json).result
foreach($trigger in $result.triggerid){
# Enable the retrieved triggers
$payload = @{
jsonrpc = "2.0"
method = "trigger.update"
params = @{
"triggerid"=$trigger
"status"=0
}
id = 1
auth = $token
} | convertto-json
$payload
$response = Invoke-WebRequest -Uri $url/api_jsonrpc.php -ContentType "application/json" -UseBasicParsing -Body $payload -method Post
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment