From 534116391332780086eae68aa45b941c87fad9f9 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 22 Jun 2012 23:57:43 -0400 Subject: [PATCH] karma: improve error handling --- plugins/karma | 9 ++++++--- plugins/karma_tool | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/karma b/plugins/karma index b85f5e6..e46fdfb 100644 --- a/plugins/karma +++ b/plugins/karma @@ -240,7 +240,7 @@ use Fcntl qw(:DEFAULT :flock LOCK_EX LOCK_NB); use Net::IP; sub register { - my ($self, $qp ) = shift, shift; + my ($self, $qp ) = (shift, shift); $self->log(LOGERROR, "Bad arguments") if @_ % 2; $self->{_args} = { @_ }; $self->{_args}{negative} ||= 1; @@ -265,7 +265,10 @@ sub connect_handler { my $db = $self->get_db_location(); my $lock = $self->get_db_lock( $db ) or return DECLINED; my $tied = $self->get_db_tie( $db, $lock ) or return DECLINED; - my $key = $self->get_db_key(); + my $key = $self->get_db_key() or do { + $self->log( LOGINFO, "skip, unable to get DB key" ); + return DECLINED; + }; if ( ! $tied->{$key} ) { $self->log(LOGINFO, "pass, no record"); @@ -372,7 +375,7 @@ sub cleanup_and_return { sub get_db_key { my $self = shift; - my $nip = Net::IP->new( $self->qp->connection->remote_ip ); + my $nip = Net::IP->new( $self->qp->connection->remote_ip ) or return; return $nip->intip; # convert IP to an int }; diff --git a/plugins/karma_tool b/plugins/karma_tool index d7556a5..eb3d921 100755 --- a/plugins/karma_tool +++ b/plugins/karma_tool @@ -38,7 +38,7 @@ sub usage { list takes no arguments. -search [ naughty nice both ] +search [ naughty nice both ] and returns a list of matching IPs capture [ IP ] @@ -115,7 +115,7 @@ sub main { elsif ( $search eq 'both' ) { next if ! $naughty || ! $nice; } - elsif ( is_ip() && $search ne $ip ) { + elsif ( is_ip( $ARGV[1] ) && $search ne $ip ) { next; } };