Skip to content

Instantly share code, notes, and snippets.

@crawc
Created February 1, 2023 19:37
Show Gist options
  • Save crawc/588e5564eebbc7752943cc91a64c9467 to your computer and use it in GitHub Desktop.
Save crawc/588e5564eebbc7752943cc91a64c9467 to your computer and use it in GitHub Desktop.
$prtguser = "apiuser"
$prtghash = "123456"
$match = "Auto-Discovery *"
$actiontype = "close" # "close" or "resolve"
$message = "auto close"
$hostname = "prtg.yourdomain.com"
$URI = "https://" + $hostname + "/api/table.json?content=tickets&columns=datetime,priority,parentid,message,user,status,name&filter_drel=&username=" + $prtguser + "&passhash=" + $prtghash
$response = Invoke-WebRequest $URI
$jsonObj = $([String]::new($response.Content)) | ConvertFrom-Json | select -expand tickets | select parentid,status_raw,message_raw | Where-Object {($_.message_raw -like $match) -and ($_.status_raw -EQ '1')}
foreach($id in $jsonObj.parentid) {
$actionURI = "https://" + $hostname + "/api/" + $actiontype + "ticket.htm?username=" + $prtguser + "&passhash=" + $prtghash + "&id=" + $id + "&content=" + $message
$result = Invoke-WebRequest $actionURI
$res = $result.Content -replace '<[^>]+>',''
Write-Output "$id - $res"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment