[Perl]Nagios_topology

3813阅读 0评论2009-12-08 一路征程一路笑
分类:Python/Ruby

#!/usr/bin/perl

use strict;

my $new=0;
my $parent;
my $hostname;
my %topology;

while(<>){
    if(m/define host/ .. /}/){
    if(!$new and (($hostname) = m/host_name\s+(\S+)/)){
    
        $new=1;
        next;
    }
    if(($parent) = m/parents\s+(\S+)/){
    $topology{$parent} .= " $hostname" unless($topology{$parent} =~ m/$hostname/);
    $new=0;
    }
    }
}

foreach (keys %topology){
    print "$_:\n";
    foreach my $host (split ' ',$topology{$_}){
        print "\t$host\n";
    }
}



上一篇:[Perl]traceroutex.pl
下一篇:没有了