Pages

Tuesday, November 8, 2011

Create a RT Ticket Using PHP and REST

We needed the ability to create tickets in RT using a PHP form. RT is a good support ticket system.

This is how I got it to work.

NOTE: This requires that you have a working install of RT.

Install HttpRequest (Ubuntu 11.10):
apt-get install php5-dev apt-get install libcurl3 apt-get install libmagic-dev pecl install pecl_http
NOTE: I had trouble with pecl_http on a 8.04 server. I had to complile it manually

Create a file (http.ini):
/etc/php5/conf.d/http.ini
Add this text to the http.ini file:
extension=http.so
Restart Apache
/etc/init.d/apache2 restart

Create the PHP file:

Create this file (I used this for a test):
/var/www/rt_test.php

Add this to the rt_test.php file:
 <?php  
   
 //RT Settings. Edit these values to suit your needs  
 $username = "username"; //RT User Login (User login for RT web interface)  
 $password = "password"; //RT User Password (User Password for RT web interface)  
 $requester_email = "user-email@example.com"; //RT User email  
 $ticket_queue = "General"; //The Queue name  
 $ticket_subject = "Ticket Subject"; //Subject on Ticket  
 $ticket_message = "Ticket Message"; //Message on Ticket  
 $rt_server = "rt-install.com"; //RT domain name  
   
 //Add a space after line breaks
 $ticket_message = str_replace("\n", "\n ", $ticket_message);

 //Complete URL  
 $url = "http://$rt_server/REST/1.0/ticket/new?user=$username&pass=$password";  
   
 //Create the Request  
 $request = new HttpRequest($url, HTTP_METH_POST);  
   
 //Create the POST Message  
 $message = "id: new\n";  
 $message .= "Queue: $ticket_queue\n";  
 $message .= "Requestor: $requester_email\n";  
 $message .= "Subject: $ticket_subject\n";  
 $message .= "Text: $ticket_message\n";  
   
 //Create an Array from the POST message  
 $post_data=array("content"=>$message);  
   
 //Add the POST Fields  
 $request->addPostFields($post_data);  
   
 try {  
   $response = $request->send()->getBody(); //Create the Ticket  
   echo $response; //Print the Response  
 } catch (HttpException $ex) {  
   echo $ex; //Print the Error  
 }  
   
 ?>  
Edit the configuration values to suit your needs. Run the PHP script a see if the ticket gets created.

Good Luck!

See: RT REST Wiki

Wednesday, October 26, 2011

Moving from Bugzilla to Trac

I decided to make the move from Bugzilla to Trac. Despite the articles I read, I seem to like the Trac UI. We have a small software development environment and Bugzilla was not a fit for us.

Why I Chose Bugzilla?
I was first drawn to Bugzilla because a lot of Free Software Projects use it. Red Hat Bugzilla is one, and they have integrated nicely with there color scheme.

Bugzilla Pro's

  • It integrates nicely with external Authentication (In my case AD)
  • Always adding new features
  • Edit Multiple Bugs at Once
Bugzilla Con's
  • Must abide by the way Bugzilla works
    •  Can't edit Description or comments
  • No integration for Customizable Reports (The search is very extensive though)
Overall I like Bugzilla. I would recommend it to large software projects. Especially if they were open to the public.

Tried Redmine

I did make an attempt with Redmine. It seems a little bloated. I just don't need certain things (Forum, News). It doesn't have multi-branch support. You have to create a project for each branch. That really doesn't work for me. It was able to setup AD Authentication in about five minutes though.

The Trac Advantage

What I like most about Trac is everything is integrated. Run a search and you will find everything (Wiki, Tickets, Milestones and Changesets). I just seems to make sense to me. I really like being able to make links to changesets in a Ticket or linking to Source in the Wiki for documentation. There doesn't seem to be much confusion when creating a ticket because there isn't many options (I see it as a good thing). I can edit ticket descriptions and comments if I make a mistake (I know you don't make mistakes), plus view the difference.

Trac Pro's
  • Integrated Wiki and Source within a single search
  • Support for Bazaar
  • Ability to easily link to anything (wiki, source)
  • Amazing Source Browser
  • Timeline to Keep "Trac" of Changes "I could almost turn email OFF"
  • Custom Query and Reports. Ability to save and a simple syntax
  • Good documentation that is built in
Trac Con's
  • Had trouble with the Bazaar plugin. If I was more than one directory deep in a branch and did a log view, my server would crash. Completely run out of memory. I did find help on Launchpad Bzr Answer. I did add memory but I do think it would still crash.
  • Not much change to the core. This seems to come up in a lot of searches. I had trouble with an LDAP/AD plugin. This should be in the core. 
Overall I do think Trac is about simplicity. Keep it simple, stable and get out of the way.