PowerShell Script to close all open tickets using PRTG API URL

# How to get rid of all PRTG tickets if you don't use them
#
# 1. Setup retention for closed tickers to one day 
#    Setup > System Administration > Core & Probes > Historic Data Purging > Closed Tickets
#
# 2. Save this PowerShell script to a file and schedule it to run daily
# 


#
# PowerShell Script to close all open tickets using PRTG API URL 
# R7G5 / 2019-11-14

# Ensuring TLS/SSL connection to our host
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

# return codes
$http_code = @{ 200 = "OK"; 302 = "Found"; 400 = "Bad Request"; 401 = "Unauthorized"}

# credentials
$username  = ""
$passhash  = ""
$creds_str = "&username=$($username)&passhash=$($passhash)"

# PRTG API URL to download CSV file with the list of open tickets 
$Cmd_GetAllOpenTicketsCSV = "https://monitor.atisolutions.com/api/table.csv?content=tickets&columns=datetime,parentid,status&filter_status=1" + $creds_str

# Execute URL above to get list of open tickets into the object
$AllOpenTickets = Invoke-WebRequest -Uri $Cmd_GetAllOpenTicketsCSV | ConvertFrom-Csv

# Iterate through each open ticket and execute PRTG API URL to close it
$AllOpenTickets | % { 
                        $t_id = $_."Ticket ID"
                        $res = Invoke-WebRequest -Uri "https://monitor.atisolutions.com/api/closeticket.htm?id=$($t_id)&content=close$($creds_str)"
                        Write-Host "Closing ticket $($t_id) - $($http_code.($res.StatusCode))"
                    } 

Comments

Popular posts from this blog

When users is trying to open PDF file from the internet using browser he gets following error message - Problem (1:1)

How to loop "ipconfig /renew" until it gets IP address on remote PC to test DHCP using PowerShell