Managing notes with Request Tracker

Usable command line integration with RT


TODO notes are something that I need, but I can never get a good enough solution to store and manage them. I want them to be accessible regardless of my location, extremely easy to create and fairly easy to maintain. As it turned out, VPS-hosted RT is my dream solution - but not just by itself, as it would be far too much hassle to log into it or send an email. I need automation, so that I can note whatever I have in mind before it gets a chance to escape.

What I came up with is a script that talks to RT's REST API, remembers my password and is easily accessible from the command line, where I spend most of my time. RT will hold the notes in another non-public queue and send newsletters to my mail everyday with summary of notes that might be getting urgent.

The interface

Here's how I interact with my new todo script:

bartosz@linux-712w:~$ todo
Subject: just a note
Content:
OK 39
Open in Firefox?
bartosz@linux-712w:~$

As you can see, the script name is as plain as it gets to save time and reduce wrist strain. In reality I just don't like long names in my command line.

The script is designed to take no arguments, as I don't find this type of interaction as convenient for humans. It just prompts for data interactively instead - it asks for a subject, content and a password. In the example above I was not prompted for a password because it saves it in a text file after first use. File mode is 0600, so it is stored just like a non-encrypted ssh private key which I think is good enough. The password is also base64-encoded just to make sure you don't disclose it by opening the file by accident in front of somebody.

Another UX feature of that script is it can be easily clicked through after specifying the subject. I can just <Enter> the content prompt, so that subject will be copied into content. After a successful API call another prompt asks if a new Firefox tab should be opened with RT view of that ticket, but another <Enter> discards that offer.

All in all, it is very convenient way of creating todo notes, as opposed to opening a new browser tab for some web page - any of them, not just RT - and then logging in and clicking through the interface.

The script

As for the script, it is just a short perl script with minimal dependencies. Promping is done with a very convenient little module called IO::Prompter, while API stuff is covered by the awesome Mojo web toolkit. The script can be seen in full here.

Since the script resides in my personal configfile repository, it is preconfigured to match my username and RT address. Username can also be specified as the only argument to the script, and each user will have their own password file created. It's not something I actively use, but it's better to have some flexibility if needed.

There isn't much else to say about the script than to show its API call code. All the other code is pretty dull, but this one snippet is interesting due to how easy it really is to automate RT with Mojo:

my $url = Mojo::URL->new("$rt/REST/2.0/ticket")->userinfo("$user:$password");
my $data = {
        Queue => 'todo',
        Requestor => $user,
        Subject => $subject,
        Content => $content,
};

my $ua = Mojo::UserAgent->new;
my $res = $ua->post($url, json => $data)->res;

The newsletter

The icing on the cake is the newsletter mail that RT sends me everyday. One of the sections it contains is dedicated to the notes I made, which a quite sophisticated search query:

Queue = 'todo'
AND Status = '__Active__'
AND Status != 'stalled'
AND ( Priority > 'Low'
      OR Created < '-30 days' )

It only shows me the notes that are not stalled, with priority above low unless they were created more than a month ago. The resutls are also sorted by priority and creation date. This is a very convenient way of getting the reminders without the need to log in into RT at all. The only problem with this is that RT base64-encodes the full HTML DOM tree, which makes some programs think that this is a scam message as apparently this is a technique that scammers use. It doesn't worry me at all though for it is for my eyes only.

Conclusion

Request Tracker is easy to harness to some custom solution, and even easier with Perl and Mojo toolkit. Even though it's just a ticketing system it is flexible enough to store arbitrary data as long as it somehow resembles a support ticket. Its search and mailing capabilities make it easy to notify people about important stuff periodically.


Comments? Suggestions? Send to feedback@bbrtj.eu
Published on 2021-01-31