ActiveMQ stomp end to end test for nagios

03.09.2008 15:07

posted by: Benjamin Smith

Posted Under: , , ,

I recently found myself needing to test producing and consuming messages from activemq via stomp. It’s a pretty trivial task thanks to Perl and nagios! Here is a quick script to test the production and consumption of messages and the command you’ll need to put into core.cfg (nagios v2). It’s slim on libs to cut down on excess fat. Enjoy!

Prerequisites..

Class::Accessor (Net::Stomp wants it)
Net::Stomp
$USER3$ = custom location of nagios check scripts..
check_mq = the name of the script.
$ARG1$ = host to check
$ARG1$ = number of messages to produce/consume
$ARG2$ = name of queue to test with

The command for core.cfg:

define command{
        command_name    check_mq
        command_line    $USER3$/check_mq $ARG1$ $ARG2$ $ARG3$
        }

The code:

#!/usr/bin/perl -w

use strict;
use Net::Stomp;

my $host = $ARGV[0];
my $nummsgs = $ARGV[1];
my $queue = $ARGV[2];

my $stomp = Net::Stomp->new( { hostname => $host, port => '61613' } );

$stomp->connect();

for (my $i=0; $i <$nummsgs; $i++) {
    $stomp->send({ destination => "/queue/$queue",
                   body => "$queue$i",
                   persistent => 'true'} );
}

$stomp->subscribe({ destination => "/queue/$queue",
                    'ack' => 'client',
                    'activemq.prefetchSize' => 1});

my $count = 0;
for (my $i=0; $i <$nummsgs; $i++) {
    my $frame = $stomp->receive_frame;
    my $body = $frame->body;
    if ($body eq "$queue$i") {
        $count++;
    }
    $stomp->ack( { frame => $frame } );
}

$stomp->disconnect();

print "Produced: $nummsgs Consumed $count\n";

if ($count == $nummsgs) {
    exit(0);
}
elsif (($count != $nummsgs) && ($count != 0)) {
    exit(1);
}
elsif ($count == 0) {
    exit(2);
}

Oh so simple..

0 comments | 1 pingback
Add post to: Delicious Reddit Slashdot Digg Technorati Google
Comment

Comments

No comments for this post

Comment form for «ActiveMQ stomp end to end test for nagios»

Required. 30 chars of fewer.

Required.

captcha image Please, enter symbols, which you see on the image