summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2020-04-30 10:55:21 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2020-04-30 10:55:21 (GMT)
commitda4c5a335f0637315b94271e35532aaba0d4c794 (patch) (side-by-side diff)
treeab498372b20da9afdb87ca0466222f59c26b19dd
parent3284f879c364a2a7b6d9c1227b21c6ed29246d28 (diff)
downloadmangemanche-da4c5a335f0637315b94271e35532aaba0d4c794.tar.gz
mangemanche-da4c5a335f0637315b94271e35532aaba0d4c794.tar.bz2
nagios: exclude hosts that don't resolve; push a sorted IP listHEADmaster
Diffstat (more/less context) (ignore whitespace changes)
-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 {
'config|c=s' => 'nagiosconf');
}
+sub valid_host {
+ my ($self,$s) = @_;
+ return 1 if $s =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
+ (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/x;
+ unless (gethostbyname($s)) {
+ $self->error("warning: $s does not resolve; skipping");
+ return 0;
+ }
+ return 1;
+}
+
sub run {
my $self = shift;
$self->SUPER::run;
@@ -36,7 +47,7 @@ sub run {
}
}
- my @iplist = keys %iph;
+ my @iplist = sort grep { $self->valid_host($_) } keys %iph;
my $n = @iplist;
$self->error("info: collected $n addresses");
unless ($self->agent->set_ip_list([@iplist])) {

Return to:

Send suggestions and report system problems to the System administrator.