#! /usr/bin/perl use strict ; use warnings ; package Probe::Iptables ; use base 'Probe' ; sub ITEMS { [ { name => 'iptables_f2b' , kind => 'spin' , args => [ qw(f2b-ssh fail2ban-ssh) ] } ] } ; sub main { my $self = shift ; my $itms = shift ; # items to probe : [ item, ... ] my $clnt = shift ; # main::CLIENT my $path = $self -> path ; my @prog = ( "$path/iptables.pl", qw() ) ; my %data = () ; my ( $err, $xit, $sig, @lines ) = Probe::Util::run_prog ( @prog ) ; if ( $err ) { $_ -> perr ( $err ) for @$itms ; } else { for my $item ( @$itms ) { if ( $item -> name eq 'iptables_f2b' ) { my $args = $item -> args ; my $re = join '|', @$args ; my $RE = qr/^chain ($re)/i ; my @lns = grep { $_ =~ $RE } @lines ; my $cnt = scalar @lns ; OBB::TT ( " re %s ; cnt %s", $RE, $cnt ) ; OBB::TT ( " line %s", $_ ) for @lns ; $item -> set_val ( $cnt == 1 ? 1 : 0 ) ; } } } } 1 ;