Closed crawc closed 1 year ago
PrtgAPI does not support interfacing with tickets, as this is a rather niche area of PRTG (most companies use a real ticketing system)
After I posted this I went down that rabbit hole and discovered their API is missing the function to close/resolve tickets, but you can pull them using their API.
Works: /api/table.json?content=tickets&columns=datetime,parentid,message,status,name&filter_drel=&username=apiuser&passhash=12345
Does NOT work (doesn't evaluate username/passhash: /api/closeticket.htm&username=apiuser&passhash=12345&id=$id&content=auto-close
This is why I want to use an API to close them since the ticking is worthless, especially the Autodiscovery Tickets. I did make a request for them to add the close option but as with many requests they probably won't implement them in a timely many or at all.
Thanks for the great work you have done @lordmilko.
@crawc Try: /api/closeticket.htm?username=apiuser&passhash=12345&id=$id&content=close
We have the same problem and that's what I use to close them out.
@squintfox Thank you for posting this. I totally missed the ?
before the query strings in the URL.
Get:
/api/table.json?content=tickets&columns=datetime,parentid,message,status,name&filter_drel=&username=apiuser&passhash=12345
Close:
/api/closeticket.htm?username=apiuser&passhash=12345&id=$id&content=auto-close
Since these methods work could this be added to the PrtgAPI? @lordmilko
There is a lot more that goes into an API than just invoking the underlying API request to get it to an appropriate level of robustness that you would expect to find in a reliable third party library such as PrtgAPI; a variety of PrtgClient
methods need to be designed to support any forms of input parameters that you may be able to specify to each of the methods required to interact with tickets, an object model has to be designed that supports all of the properties that can be returned from the object, cmdlets need to be written for each type of operation you can perform, those cmdlets may take input in the form of a number of parameters sets, unit tests (and their associated mocks) need to be written - in both C# and PowerShell, as well as integration tests that test this against a live PRTG server, and then finally complete XmlDoc documentation needs to be written and then C#/PowerShell docs for the wiki
Also, there's actually two content types pertaining to tickets: tickets
and ticketdata
, the latter of which provides information about a ticket's historical data; if tickets
were supported it wouldn't make sense to not also support ticketdata
(otherwise PrtgAPI's ticketing implementation would be essentially incomplete), so it would be all of the above x2
...all this, for a niche feature, targeting deprecated PRTG v1 API!
As such this is not something I plan to add to PrtgAPI
Understood.
For anyone that would also like to script closing the Auto-Discovery Tickets, I created this PowerShell script to do so.
https://gist.github.com/crawc/588e5564eebbc7752943cc91a64c9467
$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"
}
This will output the ID of the ticket and the close status which is normally not show to the user in the GUI, but this can be commented out.
13097 - OK
13098 - OK
13099 - OK
What's going on?
How do I get all tickets matching a certain name or type (Auto-Discovery in this case) and then updating or closing them? I see references to tickets in the code but I don't see how to work with them.
I think something like this, but it does seem to find the ticket by the ID, nothing is returned:
Get-Object 'Auto-Discovery *'
orGet-Object 'ToDo (Auto-Discovery: *'
orGet-Object -Id XX
but this would be nice to add too:
Get-Ticket 'Auto-Discovery finished for *' | Set-ObjectProperty Status 'Closed'
UPDATE: I dumped all objects and I don't see the Tickets (or ToDos) listed.
Due Dilligance