Ramblings

<rant>

Subscribe to RSS feed

Posts tagged with "irc"

Bugzilla crawling on IRC

, , , ...

Sometimes when you are working with a bug tracking system you want to see the bugs as they appear or heavy changes are done. This was the case with me and a project I'm working on and without finding anyone else having done the same I took the challenge.

The goal was to show new bugs appearing and changes done to them in an IRC channel. I had already an eggdrop bot running there and I needed to somehow connect Bugzilla with it.

1. I started out by adding a QA contact in bugzilla which gets all new bugs and changes done to them.

2. Then I had to configure exim4 to send email received to a script that could communicate with eggdrop. As it turned out, I simply let the script add each mail message as a file in an explicit catalogue.

Exim config: /etc/exim4/exim4.conf.template

bugs_router:
  driver = accept # accept the mail

  # the following two lines makes it get email sent to bugzilla@bugs.domain.com
  local_parts = bugzilla # username it should answer to
  domains = bugs.domain.com # which domain it should answer to

  senders = bugzilla-daemon@bugzillahost.com # Only mail sent from bugzilla
  transport = bugs_transport # which transport should take care of the mail

# ...

bugs_transport:
  driver = pipe # pipe the mail content to a command
  command = /home/bugsuser/scripts/bugzillahandler.pl
  user = bugsuser # run as this user
  group = bugsuser
  return_output # fail on output
  log_output

Then the script that puts the mail messages in individual files looked like this:

/home/bugsuser/scripts/bugzillahandler.pl:

#!/usr/bin/perl
use strict;
use warnings;

my $ts = time();

if (open(my $out, ">", "/var/log/bugzillahandler/$ts")) {
  local $/;
  print $out (<>);
  close($out) or die "Cannopt close $ts: $!";
} else {
  die "cannot open $ts for >: $!";
}

3. Now the eggdrop has to get these files somehow and I add a timer based part that runs whenever the eggdrop is online in a script file included in the eggdrop:

# this code basically calls a perl script every 60 seconds 
# and outputs its output to the channel

set interval 60
set channel "#bugsoutput"

# delete existing timers
foreach t [utimers] {
  if {[lindex $t 1] == "checkbugzilla"} {
    killutimer [lindex $t end]
  }
}

# set up a new timer
set bugzillatimer [utimer $interval checkbugzilla]

# function that is called
proc checkbugzilla {} {
  global interval channel
  set ret "[exec /home/bugsuser/eggdrop/scripts/perl/checkbugzilla.pl]"
    if {$ret != 0} {
    set lines [split "$ret" "\n"]
    foreach line $lines {
      # output each line as one line to the irc channel
      putquick "NOTICE $channel :$line"
    }
  }
  # set up next call
  set bugzillatimer [utimer $interval checkbugzilla]
}

4. Finally the perl script that parses the files and outputs them in a nice fashion, one line per bug that has appeared since last time.

/home/bugsuser/eggdrop/scripts/perl/checkbugzilla.pl:

#!/usr/bin/perl
# get all the files that have changed since last time we checked (1 minute)
$files = `find /var/log/bugzillahandler -mmin -1 \! -type d`;
foreach $file (split/\n/,$files) {
  if(open(IN,$file)) {
    # open the file and read out its content.
    my $content;
    while(<IN>) {
      $content .= $_;
    }
    close(IN);

    # do some crude pattern matching to get out info about new bugs 
    # and bugs that have changed to or from RESOLVED state.

    ($head, $body) = split(/\n\n/,$content,2);
    $head =~ /^Subject:\s*(.*)$/mgi;
    $subject = $1;
    $subject =~ /\[Bug (\d+)\]/mgi;
    $bugnum = $1;
    $subject =~ s/\s*\[.*?\]\s*//mgi;
    $subject = trim($subject);
    if ($subject =~ /New/mgi) {
      $body =~ /Product: (.*?)\s*$/mgi;
      $product = $1;
      $body =~ /Component: (.*?)\s*$/mgi;
      $component = $1;
      $body =~ /ReportedBy: (.*?)\s*$/mgi;
      $reporter = $1;
      $out .= "[Bug $bugnum] $subject <$product/$component> ($reporter)".
              " | http://bugzillahost.com/bugzilla/show_bug.cgi?id=$bugnum\n";
    } elsif ($body =~ /Status\|([^\|]+?)\|([^|]+?)$/mgi) {
      $from_status = trim($1);
      $to_status = trim($2);
      $resolution = "";
      if ($body =~ /Resolution\|([^\|]+?)\s*\|([^|]+?)\s*$/mgi) {
        $from_resolution = trim($1);
        $to_resolution = trim($2);
        if ($to_status eq "RESOLVED") {
          $resolution = "$to_resolution: ";
        }
      }
      # populate output buffer
      $out .= "[Bug $bugnum] $to_status: $resolution$subject".
              " | http://bugzillahost.com/bugzilla/show_bug.cgi?id=$bugnum\n";
    }
  }
}

# if there is no output print out a single "0" to let 
# the eggdrop part know it shouldn't do anything.
if ($out ne "") {
  print $out;
} else {
  print "0";
}
exit(0);

sub trim($) {
  # remove whitespaces in front and behind a string
  my $string = shift;
  $string =~ s/^\s+//;
  $string =~ s/\s+$//;
  return $string;
}

5. Voilá, a bot that outputs bug information automatically.

07:45 [Bug 1234] New: There is an error <Coffemaker/filter_obj> \
(reporter@customer.com) | http://bugzillahost.com/bugzilla/show_bug.cgi?id=1234

Most of the scripts are kind of patchwork evolved while experimenting. They could all have been smaller and smarter, and also fewer steps. However, this solution worked and I didn't feel like fixing it. (If it works don't fix it).

If you want to suggest improvements I'm all ears though. Hopefully some of you will find this useful. I felt I had to write it down somewhere at least so that next time I need to add something I don't have to go back and decipher it.

IM-prove Opera with a little bit of Bitlbee

, , , ...

So you are a blabber mouth? Or, at least, you like to stay in touch with friends and family using instant messaging? Follow this guide to see how you can make Opera your IM client

The fine guys over at Bitlbee.org has made an IM proxy. That is, they have made an IRC server that allows you to add various IM protocols when you log on to it. IRC chat is supported by Opera and hence you can log on to a Bitlbee server, restore your account details and be online with Yahoo,ICQ/AOL,MSN and Jabber, at the same time. -- Everything in a simple chat window in Opera.

Connect to Bitlbee

After starting Opera (I bet you are already using it ;) Go to the following url: irc://im.bitlbee.org

You should now be in the root channel, which is your control channel. You type in commands here, but don't worry, you don't need to use them that much.

For a more permanent access to Bitlbee, go into Tools -> Mail and chat accounts select the im.bitlbee.org (temporary) account and add some info to it.

In the Outgoing tab you might add a default action to be performed when connecting, this is useful for automatically "logging in" so that you get the accounts and contacts you have added the next time you log in. I'll explain later.

Adding accounts

Bitlbee uses as mentioned a root channel window where you can type in various commands. You can start by typing help commands followed by [Return] to get a list of commands. help quickstart is also useful to get to know Bitlbee better.

Anyway, let's cut the chase and start adding an account. If you have an ICQ account you want to add, you type in the following: account add oscar 12345678 p455w0rd icq.mirabilis.com (*). Naturally you need to provide your own UID and password. The server name at the end is not necessary for most protocols, but ICQ needs it. For MSN you'd do: account add msn cyberBoy@hotmail.com p455w0rd.

Now you should have at least one account added, you can view your accounts with account list. To let the accounts go into online mode type account on.

(*) OSCAR is the name of the protocol that ICQ uses.

Adding users

If you don't get all your previous contacts automatically added you can add more contacts from within Bitlbee. Adding contacts is done by the add command, but Bitlbee needs to know which account you want a user to be added to. So, you need to do a account list to find out the number of the account you want a new contact to be added to. When you've done this you can smply do: add account_number nick/uid. For instance: add 0 16639703 (If your 0th account is ICQ, you will add me to your list.)

If you don't like your buddies' names or they clash with eachother you can rename them with rename old_nick new_nick

Chatting

There are two ways to chat:

  • 1. The simplest one is to open a query window by clicking on the users in the userlist like you do normally for private chat.
  • 2. If you are lazy or just want to send a quick message, you can use the nick of the user followed with a colon (:) and then the message. Only that user will see the message even if all the users are listed in your control channel. Example: grrrl24: See you later, need to go!
  • Remembering settings

    Finally you probably don't want to do this everytime you want to use IM with Opera. Luckily there is a simple solution to this. What you need to do is to register yourself within Bitlbee with a password. Next time you log on you log in and voila! all your contacts and accounts are there.

    To register use the following: register p455w0rd (Choose your own password). To log in next time: identify p455w0rd.

    As I mentioned previosuly you might want to let this be done automatically when logging into Bitlbee. Go to the Perform command when connected text field in the Tools -> Mail and chat accounts -> im.bitlbee.org -> Outgoing then add /msg &bitlbee identify p455w0rd.

    More info

    • You can also set up your own Bitlbee server if you don't trust the official one, or just like to experiment.
    • Bitlbee of course also works with any other IRC client.
    • For more info about Bitblee check out their website
    • Get latest stable Opera at http://opera.com/download
June 2013
M T W T F S S
May 2013July 2013
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30