| 1 | package Net::DNS::Check::Test::ns_count; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use vars qw(@ISA $VERSION); | ||
| 5 | |||
| 6 | @ISA = qw(Net::DNS::Check::Test); | ||
| 7 | |||
| 8 | |||
| 9 | sub new { | ||
| 10 | my ($class) = shift; | ||
| 11 | |||
| 12 | my ($self) = bless {}, $class; | ||
| 13 | |||
| 14 | if ( @_ ) { | ||
| 15 | $self->_process_args(@_); | ||
| 16 | } | ||
| 17 | |||
| 18 | $self->test(); | ||
| 19 | |||
| 20 | return $self; | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | sub test() { | ||
| 25 | my ($self) = shift; | ||
| 26 | |||
| 27 | return unless ( $self->{config} ); | ||
| 28 | |||
| 29 | my $ns_min_count = $self->{config}->ns_min_count(); | ||
| 30 | my $ns_max_count = $self->{config}->ns_max_count(); | ||
| 31 | |||
| 32 | my $test_status = 1; | ||
| 33 | my $test_detail = {}; | ||
| 34 | |||
| 35 | foreach my $nsquery ( @{$self->{nsquery}} ) { | ||
| 36 | my $nscount = scalar $nsquery->ns_list(); | ||
| 37 | my $ns_name = $nsquery->ns_name(); | ||
| 38 | |||
| 39 | $test_detail->{$ns_name}->{desc} = "$nscount"; | ||
| 40 | |||
| 41 | if ($ns_min_count > 0 && $nscount < $ns_min_count ) { | ||
| 42 | $test_status = 0; | ||
| 43 | $test_detail->{$ns_name}->{status} = 0; | ||
| 44 | } elsif ($ns_max_count > 0 && $nscount > $ns_max_count ) { | ||
| 45 | $test_status = 0; | ||
| 46 | $test_detail->{$ns_name}->{status} = 0; | ||
| 47 | } else { | ||
| 48 | $test_detail->{$ns_name}->{status} = 1; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | $self->{test_status} = $test_status; | ||
| 53 | $self->{test_detail} = $test_detail; | ||
| 54 | |||
| 55 | return $test_status; | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; | ||
| 59 | |||
| 60 | __END__ |