- 论坛徽章:
- 0
|
本帖最后由 353764437 于 2013-05-31 17:04 编辑
#!/usr/bin/perl
use warnings;
use strict;
my ($servicegroup_name,$alias);
my $cfg_dir = "/home/nagios/data/";
my $cfg_ext = "cache";
opendir (CF,$cfg_dir) or die "Can't open:$!\n";
my @cfg_list = grep {/$cfg_ext$/ && -f "$cfg_dir/$_" } readdir(CF);
closedir (CF);
chomp (my $date=`date +"%Y%m%d%H%M"`);
my $out_file = "/home/nagios/test_servicegroup/notes_".$date.".log";
open (OUTFILE,">",$out_file) or die "cannt open $out_file:$!\n";
foreach my $file(sort @cfg_list){
open (FH,"$cfg_dir/$file") or die "Can't open: $!\n";
$/ = "";
while (<FH>){
my $message = $_;
while($message =~ m{define\s+(\w+)\s+\{(.+?)\}\n}isg){
my $category = $1;
my $content = $2;
if ($category eq 'servicegroup'){
if( $content =~ m{servicegroup_name\s+(.+?)\n\s+alias\s+(.+?)\n\s+members\s+.+?\n?\s+notes\s+(业务)\n?}i || $content =~ m{servicegroup_name\s+(.+?)\n\s+alias\s+(
.+?)\n\s+notes\s+(业务)\n?}i){
($servicegroup_name,$alias) = ($1,$2);
print OUTFILE "$alias\n";
}
}
}
}
}
close (FH);
close (OUTFILE);
主要匹配文件中这两种情况:
define servicegroup {
servicegroup_name Android
alias Android测试
members mob1001,mob1002
notes 服务
}
define servicegroup {
servicegroup_name Android
alias Android测试
notes 服务
}
回复 3# 公孙孟
|
|