全部博文(1144)
分类: 系统运维
2014-01-14 17:37:25
my %h = map {($_, $self->{options}->{$_})} split(',', $list);
sub get_non_default_options {
my $self = shift;
my $list = shift;
if (! $list) {
my %h = map {
($_, $self->{options}->{$_})
} grep {
! exists $self->{defaultoptions}->{$_} ||
"$self->{defaultoptions}->{$_}" ne "$self->{options}->{$_}";
} keys %{$self->{options}};
return \%h;
} else {
my %h = map {
($_, $self->{options}->{$_})
} grep {
! exists $self->{defaultoptions}->{$_} ||
"$self->{defaultoptions}->{$_}" ne "$self->{options}->{$_}";
} split(',', $list);
return \%h;
}
}
@output = map { chomp; $_; } grep !/^$/, @output;
map { /^CHECK_LOGFILES/ && delete $ENV{$_}; } keys %{$ENV};
my @nfsmounts = grep {
substr($_->[2], 0, 3) eq "nfs"
} map {
my ($dev, $mountpoint, $fstype, $rest) = split(/\s+/, $_);
[$mountpoint, length($mountpoint), $fstype];
} @mtab;
my @mountpoints = sort {
$b->[1] <=> $a->[1]
} grep {
substr($file, 0, $_->[1]) eq $_->[0];
} map {
my ($dev, $mountpoint, $fstype, $rest) = split(/\s+/, $_);
# printf STDERR "line: %s,%s,%s\n", $dev, $mountpoint, $fstype;
[$mountpoint, length($mountpoint), $fstype];
} @mtab;
map {
push @dirs, $_;
mkdir(join('/', @dirs))
if join('/', @dirs) && ! -d join('/', @dirs);
} split(/\//, dirname($self->{pidfile}));
my $class = sprintf "Nagios::CheckLogfiles::Search::%s",
join "::", map {
(uc substr($_, 0, 1)).substr($_, 1);
} split(/::/, $self->{type});
map {
my $value = $params->{(lc $level).'patterns'}->{$_};
$self->{patternkeys}->{$level}->{$value} = $_;
} keys %{$params->{(lc $level).'patterns'}};
map {
my $value = $filepatterns->{$level.'patterns'}->{$_};
$self->{patternkeys}->{uc $level}->{$value} = $_;
} keys %{$filepatterns->{$level.'patterns'}};
@{$self->{negpatterns}->{$level}} = map {
if (substr($_, 0, 1) eq "!") {
push(@{$self->{negpatterncnt}->{$level}}, 0);
substr($_, 1)
} else { () }
} @{$self->{patterns}->{$level}};
@{$self->{patterns}->{$level}} = map {
if (substr($_, 0, 1) ne "!") { $_ } else { () }
} @{$self->{patterns}->{$level}};
$self->trace(sprintf "relevant files: %s", join(", ", map { basename $_->{filename} } @rotatedfiles));
@rotatedfiles = reverse map {
$self->trace("%s has fingerprint %s", $_->{filename}, $_->{fingerprint});
# because of the windows dummy devino 0:0, we need to add the size
if (exists $seen{$_->{fingerprint}}) {
$self->trace("skipping %s (identical to %s)",
$_->{filename}, $seen{$_->{fingerprint}});
();
} else {
$seen{$_->{fingerprint}} = $_->{filename};
$_;
}
} reverse @rotatedfiles;
@rotatedfiles = reverse map {
if (exists $seen{$_->{filename}}) {
$self->trace("skipping duplicate %s (was growing during analysis)",
$_->{filename});
();
} else {
$seen{$_->{filename}} = 1;
$_;
}
} reverse @rotatedfiles;
@matchingfiles = sort { $a->{modtime} <=> $b->{modtime} } map {
my $archive = $_;
({ filename => $archive, modtime => (stat $archive)[9]});
} @matchingfiles;
@matchingfiles = sort { $a->{modtime} <=> $b->{modtime} } map {
my $archive = $_;
({ filename => $archive, modtime => (stat $archive)[9]});
} map {
sprintf "%s/%s", $self->{archivedir}, $_;
} grep /^$self->{filenamepattern}/, readdir(DIR);
@tmp_searches = reverse map {
if (! exists $seen{$_->{tag}}) {
$seen{$_->{tag}}++;
$_;
} else {
();
}
} reverse @tmp_searches;
@{$self->{searches}} = map {
my $srch = $_;
if (grep { $srch->{tag} eq $_ } @{$self->{selectedsearches}}) {
# gilt sowohl fuer normale searches
$srch;
} elsif ($srch->{template} && grep { $srch->{template} eq $_ } @{$self->{selectedsearches}}) {
# als auch fuer template (tag ist hier bereits template."_".tag,
# wobei tag auf der kommandozeile uebergeben wurde)
$srch;
} elsif (grep { $_ =~ /[*?]/ && $srch->{tag} =~ /$_/ } @{$self->{selectedsearches}}) {
# --selectedsearches "regexp,regexp"
$srch;
} elsif ($srch->{tag} eq "prescript") {
$srch;
} elsif ($srch->{tag} eq "postscript") {
$srch;
} else {
$self->trace("skipping non-selected search %s", $srch->{tag});
();
}
} @{$self->{searches}};
$self->{perfdata} = join (" ",
map { $_->formulate_perfdata(); if ($_->{perfdata}) {$_->{perfdata}} else {()} }
@{$self->{searches}});