I’ve been a user of OSTicket for years and deployed it to several clients. One feature I’d like is to be able to automatically schedule reminder tickets for tasks like preventative maintenance. I experimented with a few solutions using web based schedulers to inject emails into OSTicket with limited success. While they worked, maintaining them was difficult.
One plausible approach that did work was using a Google Calendar with recurring events that emailed event reminders into the OSTicket deployment. It gave a nice calendar interface to edit events, but was a little clunky to maintain.
So I sought another approach which would be easier for ticketing system maintainers to manage. The solution detailed here lets a user maintain recurring events in a FAQ category. An external php script called via CRON then creates tickets via the OSTicket API. This is only applicable to self-hosted deployments of OSTicket, and was deployed against OSTicket 1.8
Setting up Automatic Ticket Scheduling
1 Category & FAQ Setup
Create a new FAQ category. In the example I’ve called it “Automated Tickets”. Note the Category ID in the address bar. We’ll need this later.
Within this category, I’ve created several FAQ’s. The names are arbitrary, but represent the period which the tickets should be created for. For example, “2 Weekly Tickets” are created on the 1st and 14th of each month. More on that later.
2 Ticket Setup
Edit one of the FAQs created above. Here we define the subject and messages of the tickets. In the example I’m editing “1 Monthly” tickets. These are tickets I want created on the 1st of each month. I’ve setup 3 test tickets.
3 OSTicket API Key
Next, create an API Key in OSTicket. I’m going to call the API from the same server that hosts OSTicket, so I have used 127.0.0.1 as the IP Addr.
4 Help Topic Setup
Each ticket that is automatically created needs to be assigned a “Help Topic”. You can use the id of an existing help topic. I’ve opted to create a new topic called “Automation” to assign to all automatically created tickets.
5 Script Setup
Check out or upload the createTicketPeriod.php script to your OSTicket server. Edit this script. At the top there is a $settings array. Fill in the details to match your deployment.
- categoryId is the id from Step 1.
- topicId is the id from Step 4.
- apiKey is from Step 3.
- subjectPrefix / subjectSuffix – The created ticket subject is wrapped in this text.
$settings = array( 'dbHost' => 'localhost', 'dbTable'=> 'ost.ost_faq', // Database.Table 'dbUser' => 'root', 'dbPass' => '', 'categoryId' => 16, // The Category ID where Automator ticket FAQs are kept 'topicId' => 8, // Created tickets are assigned to this topic. 'subjectPrefix' => '[', 'subjectSuffix' => ']', 'reporterEmail' => 'email@example.com', 'reporterName' => 'Automator', 'apiURL' => 'http://ost.domain.com/api/http.php/tickets.json', 'apiKey' => 'your-api-key' );
6 Testing Ticket Creation
Log in to your server and test out createTicketPeriod.php.
[wpfmb type=’info’ theme=1]Remember to make createTicketPeriod.php executable:
Eg, chmod u+x createTicketPeriod.php[/wpfmb][wpfmb type=’warning’ theme=1]You may need to update the interpreter at the head of createTicketPeriod.php to match your environment.
By default it is #!/usr/bin/php -q[/wpfmb]
./createTicketPeriod.php "1 Monthly" Ticket '[Subject 1]' created with id 3118 Ticket '[Subject 2]' created with id 3119 Ticket '[Other Subject]' created with id 3120
Note how the script parameter matches (well almost) the name of the FAQ (from Step 1). The script uses an LIKE UPPER(‘%period%’) to find the matching FAQ entry in the OSTicket database.
In OSTicket, our tickets now appear.
7 Making it Automatic – CRON Setup
The final step is to wire ticket creation up to CRON so tickets are created on schedule. Here is an example crontab.[wpfmb type=’info’ theme=1]Remember to update the variable CTK to point to your createTicketPeriod.php script.[/wpfmb]
# # Automatic tickets # CTK="/var/www/ost/automator/createTicketPeriod.php" # Daily Tickets (8AM) 0 8 * * MON-FRI $CTK daily > /dev/null # Weekly (Monday 8AM) 0 8 * * 1 $CTK "1 weekly" > /dev/null # Fortnightly (1st and 14th @ 8AM) 0 8 1,14 * * $CTK "2 weekly" > /dev/null # Monthly (1st @ 8AM) 0 8 1 * * $CTK "1 monthly" > /dev/null # 3 Monthly (Jan, Apr, Jul, Oct 1st @ 8AM) 0 8 1 1,4,7,10 * $CTK "3 monthly" > /dev/null # 6 Monthly (Jan, Jul 1st @ 8AM) 0 8 1 1,7 * $CTK "6 monthly" > /dev/null # Yearly (Jan 1 @ 8AM) 0 8 1 1 * $CTK "yearly" > /dev/null
One Last Script
Also included is the script createTicket.php
This script lets you create a ticket from the command line. Similarly to createTicketPeriod.php you need to update the $setting array, perhaps the #! interpreter line and make the script executable.
./createTicket.php subject [message]
See the GitHub page for troubleshooting information.
Parts of the scripts were inspired from jared@osTicket.com / ntozier@osTicket / tmib.net (http://tmib.net/using-osticket-1812-api)