aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-04-30 13:55:21 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-04-30 13:55:21 +0300
commitda4c5a335f0637315b94271e35532aaba0d4c794 (patch)
treeab498372b20da9afdb87ca0466222f59c26b19dd /lib
parent3284f879c364a2a7b6d9c1227b21c6ed29246d28 (diff)
downloadmangemanche-da4c5a335f0637315b94271e35532aaba0d4c794.tar.gz
mangemanche-da4c5a335f0637315b94271e35532aaba0d4c794.tar.bz2
nagios: exclude hosts that don't resolve; push a sorted IP list
Diffstat (limited to 'lib')
-rw-r--r--lib/App/Mangemanche/Command/nagios.pm13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/App/Mangemanche/Command/nagios.pm b/lib/App/Mangemanche/Command/nagios.pm
index 016ba6d..7c28038 100644
--- a/lib/App/Mangemanche/Command/nagios.pm
+++ b/lib/App/Mangemanche/Command/nagios.pm
@@ -15,6 +15,17 @@ sub new {
15 'config|c=s' => 'nagiosconf'); 15 'config|c=s' => 'nagiosconf');
16} 16}
17 17
18sub valid_host {
19 my ($self,$s) = @_;
20 return 1 if $s =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
21 (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/x;
22 unless (gethostbyname($s)) {
23 $self->error("warning: $s does not resolve; skipping");
24 return 0;
25 }
26 return 1;
27}
28
18sub run { 29sub run {
19 my $self = shift; 30 my $self = shift;
20 $self->SUPER::run; 31 $self->SUPER::run;
@@ -36,7 +47,7 @@ sub run {
36 } 47 }
37 } 48 }
38 49
39 my @iplist = keys %iph; 50 my @iplist = sort grep { $self->valid_host($_) } keys %iph;
40 my $n = @iplist; 51 my $n = @iplist;
41 $self->error("info: collected $n addresses"); 52 $self->error("info: collected $n addresses");
42 unless ($self->agent->set_ip_list([@iplist])) { 53 unless ($self->agent->set_ip_list([@iplist])) {

Return to:

Send suggestions and report system problems to the System administrator.