From Request Tracker Wiki
Revision as of 16:15, 6 April 2016 by Admin (talk | contribs) (2 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Purpose: Our company's helpdesk uses a different email system and need to assign tickets to us but we use RT. The other system will send an email to our RT system but we need to know if it is OFF Hours so we can get paged. This script tests to see if a ticket is created (sent in by) the external system and if it's OFF hours it will send an email to our pager.

Author: macnlos AT gmail DOT com - I'm on the RT Users List

Requirement: This scrip uses the SendEmailAction script which allows us to send to any external email address. Our template is based on the example in this scrip.

Description: Helpdesk Off Hours Pager

Condition: User Defined

Action: Send Email <--- this is the SendEmailAction scrip

Template: Global template: Notifypager

State: TransactionCreate

Custom Condition:

# These first 4 variables correspond to the start and stop of
 # business days and hours. The 5th variable is the email
 # address of the other system that is forwarding messages.
 my $start_hr = 6;
 my $end_hr = 17;
 my $start_day = 1;
 my $end_day = 5;
 my $from_address = 'email@othersystem.com';
 # Bypass if this is not being created
 if ($self->TransactionObj->Type ne "Create") {
   return 0; # This is an update transaction
 # Get who created this ticket and exit if it doesn't
 # match the system address from above
 my $requestor_address = lc($self->TicketObj->RequestorAddresses);
 if ($requestor_address ne $from_address) {
   return 0; ## Not from Unicenter
 # Parse out the current time the check if it is on or off hours.
 my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime time();
 if (($wday < $start_day) || ($wday > $end_day)) {
   return 1; ## It's not in the work week and is OFF Hours
 if (($hour >= $start_hr) && ($hour <= $end_hr)) {
   return 0; ## It's with business hours (ON Hours)
 return 1; ## It's OFF Hours during the work week

Code Explanation: The first 5 variables allow you to define the time periods that is considered ON hours. It allows you to define what days are considered business days. Lastly it lets define from what email address the other system is sending requests.

The parsing of current time is standard Perl. The important part is that $hour and $wday will have the current hour and day of the week. You need these to compare against your defined ON / OFF hours.

The first IF block checks to see if it is from the external system. If it not then it exits out with a 0 and no page is sent.

The second IF block checks to see if it during your business week. If it is not then it exits out with a 1 and a page is sent because it is OFF hours.

The last IF block checks to see if it is during business hours. We already know that it's within business days. If it is within business hours then it exits with a 0 and no page is sent.

If it makes it to the last return statement you know it's on a business day but off hours. So it exits out with a 1 and a page is sent.