Title: montrap

Hi,

  I started using mon about a week ago and got very confused when I wanted to send traps and got different answers with different versions of mon when using the montrap contributed script. I worked out there were a number of issues:

1) montrap didn't actually use the port parameter
2) mon changed from the opstatus to the retval parameter being "important" between the stable and development versions
3) montrap didn't set the retval parameter properly

The modified version below seems to fix these problems. Hope it helps someone else.

Julian
=====================
#!/usr/bin/perl

use strict;
use Getopt::Std;
use Mon::Client;

my @opstrings= (
        "fail", "ok", "coldstart", "warmstart", "linkdown",
        "unknown", "timeout", "untested",
        );

my $usage= "montrap [-p port] [-r retval] -o opstatus -s summary [-d detail] host group:service\n";

use vars qw($opt_p $opt_r $opt_o $opt_s $opt_d);
getopts("p:r:o:s:d:");


die $usage unless @ARGV == 2 and $ARGV[1] =~ /[^:]+:[^:]+/;

my $host= $ARGV[0];
my ($group, $service)= $ARGV[1] =~ /^([^:]+):([^:]+)/;

my $port= $opt_p || 2583;
my $opstatus= $opt_o || die "montrap: '-o opstatus' required\n";
my $retval;
if(defined $opt_r){
  $retval = $opt_r;
} else {
  $retval = 255;
}

die "montrap: unrecognized opstatus: $opstatus\n" unless
        grep $opstatus, @opstrings;


my $summary= $opt_s  || die "montrap: '-s summary' required\n";
my $detail= $opt_d || "";

my $mon;

        if (!defined ($mon = Mon::Client->new)) {
                die "$0: could not create client object: $@";
        }
        $mon->host($host);
        $mon->port($port);

        $mon->send_trap(
                group=> $group,
                service=> $service,
                retval=> $retval,
                opstatus=> $opstatus,
                summary=> $summary,
                detail => $detail,
                );




http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
_______________________________________________
mon mailing list
mon@linux.kernel.org
http://linux.kernel.org/mailman/listinfo/mon

Reply via email to