diff --git a/lib/ssh.pm b/lib/ssh.pm index ac06734..524307e 100644 --- a/lib/ssh.pm +++ b/lib/ssh.pm @@ -20,13 +20,12 @@ sub fetch { my $retmsg; my @toreturn; unless($seq) { - my $seqsth = $self->{'dbh'}->prepare("SELECT seq FROM logs WHERE program = 'sshd' ORDER BY seq DESC LIMIT 1") or $retmsg = DBI::errstr; - $seqsth->execute or $retmsg = DBI::errstr unless($retmsg); - $seq = $seqsth->fetchrow_arrayref->[0] or $retmsg = DBI::errstr unless($retmsg); + my $seqsth = $self->{'dbh'}->prepare("SELECT seq FROM logs WHERE program = 'sshd' ORDER BY seq DESC LIMIT 1") or return { retval => 0, retmsg => DBI::errstr, error => 1 }; + $seqsth->execute or return { retval => 0, retmsg => DBI::errstr, error => 1}; + $seq = $seqsth->fetchrow_arrayref->[0] or return { retval => 0, retmsg => DBI::errstr, error => 1}; } - return { retval => 0, retmsg => $retmsg, error => 1 } if($retmsg); - my $sth = $self->{'dbh'}->prepare("SELECT msg,seq FROM logs WHERE program = 'sshd' AND seq > $seq") or $retmsg = DBI::errstr unless($retmsg); - $sth->execute or $retmsg = DBI::errstr unless($retmsg); + my $sth = $self->{'dbh'}->prepare("SELECT msg,seq FROM logs WHERE program = 'sshd' AND seq > $seq") or return { retval => 1, retmsg => DBI::errstr, error => 1 }; + $sth->execute or return { retval => 0, retmsg => DBI::errstr, error => 1}; while(my $ref = $sth->fetchrow_hashref) { my $string = $$ref{'msg'}; $seq = $$ref{'seq'};