2 Replies Latest reply on Apr 12, 2016 9:58 AM by simitpatel

    Send an email alert to multiple emails when a ticket remains unassigned for 1 hour

    simitpatel

      I would like to send an alert to a few specific email addresses whenever a new ticket remains unassigned for more than one hour, but I can't seem to figure out how to do that. I created an action rule, but that didn't seem to work. Is there any way to do this?

        • Re: Send an email alert to multiple emails when a ticket remains unassigned for 1 hour
          apap

          Action rules will not work for this because they are triggered when an update occurs on the ticket. 

           

          You can setup email alerts based on the status type and specify if they are unassigned after 1 hour.

          setup->tickets->priority types & alerts

           

          You are limited to who can be emailed,  just the group manager for unassigned tickets.

          • Re: Send an email alert to multiple emails when a ticket remains unassigned for 1 hour
            simitpatel

            Just in case anyone wants to be able to do this in the future, I wrote a powershell script that makes use of the WHD API to do this. Just create a schedule to run it every 5 minutes(or whatever you want). At the top of the script there are some parameters that you need to customize specifically for your site.

             

            #***************CONFIG PARAMETERS******************************************************

             

            $hostname = "helpdesk.domain.com"

            $apikey = "InsertYourAPIKeyHere"

            [string[]]$emails = "person1@domain.com", "person2@example.com"

            $from = "helpdesk@domain.com"

            $ticketAgeThreshold = 90 #the age of tickets, in minutes of when you want emails sent

            $emailSubject = "The following tickets have been unassigned for 90min+:"

            $emailBody=""

            $SmtpServer = "email.domain.com"

             

            #***************END CONFIG*************************************************************

             

             

            $hour = (Get-Date).hour

            $dayofWeek = (Get-Date).DayofWeek.value__

            #check if the hour is currently outisde of business hours, or if it's the weekend. Else

            if($hour -lt 9 -or $hour -gt 17 -or $dayofWeek -gt 5 ) {exit}

             

             

            else {

                #create the API url to get open tickets that are unassigned.

                $url = 'https://' + $hostname + '/helpdesk/WebObjects/Helpdesk.woa/ra/Tickets?qualifier=((clientTech=null) and (statustype.statusTypeName="Open"))&username=admin&apiKey=' + $apikey

                $sendEmail = 0

                #create 'alreadySent.txt' if it doesn't exist

                New-Item alreadySent.txt -type file -ErrorAction SilentlyContinue

             

                #Get the JSON file from the helpdesk server. The try/catch is in case there's an error connecting to the HD.

                #And in case of an error, it quits.

                try{

                    $tickets = Invoke-RestMethod -Uri $url

                }

                catch{

                    echo "Failure. Exiting Script."

                    exit

                }

             

                #process every unassigned ticket

                foreach($ticket in $tickets){  

                    #determine ticket age. I had to knock the last letter off the time, because HD was returning the time with a 'Z' at the end, which is supposed to mean GMT

                    #but the time was in EST. Getting rid of the Z makes it EST.

                    $time = $ticket.lastUpdated -replace ".$"

                    $ticketAge = ((get-date) - (get-date $time)) | select -exp totalminutes

             

                    #if the ticket is older than 90 minutes, and the ticket number doesn't exist in 'alreadySent.txt'

                    #then add the ticket to the subject and body of the email, and add it to 'alreadySent.txt

                    if(-Not(Select-String alreadySent.txt -pattern $ticket.id -Quiet) -and $ticketAge -gt $ticketAgeThreshold){

                        $sendEmail = 1

                        $emailSubject = $emailSubject + $ticket.id + ","

                        $emailBody = $emailBody + "Ticket#: " + $ticket.id + "`nSubject: " + $ticket.shortSubject + "`nTicket Created: " + $ticket.prettyLastUpdated + "`n`n"

                        Add-Content alreadySent.txt ($ticket.id + "`n")

                    }

                }

              

                #drop the last commana off the subject

                $emailSubject = $emailSubject -replace ".$"

              

                #send email

                if($sendEmail -eq 1){

                    Send-MailMessage -SmtpServer $SmtpServer -to $emails -from $from -Subject $emailSubject -Body $emailBody

                }

              

                #Clear out tickets from alreadysent.txt if they have now been assigned.

                foreach ($sentTicket in get-content alreadySent.txt) {

                    #if there's a line in alreadySent.txt that isn't in the tickets.id array, then delete that line.

                    if(-Not($tickets.id -contains $sentTicket)){

                        (get-content "alreadySent.txt") -notmatch $sentTicket | out-file "alreadySent.txt"

                    }

                }

            }