/
c3mc-device-find-owner
executable file
·54 lines (41 loc) · 1.24 KB
/
c3mc-device-find-owner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/data/Software/mydan/perl/bin/perl
use strict;
use warnings;
use YAML::XS;
use Encode;
use utf8;
$| ++;
my @ip = split /,/, join ',', @ARGV;
@ip = <STDIN> unless @ip;
chomp @ip;
my @data = `c3mc-device-cat-all-cache get`;
chomp @data;
my @title = split /\t/, shift @data;
die "unfind title" unless @title;
my %title = map{ $title[$_] => $_ } 0 .. $#title;
my ( %res, %cnt );
for( @data )
{
my @d = split /\t/, $_;
my $uuid = join ',', map{ $d[$title{$_}] }map{ Encode::encode( 'utf8', $_ )}qw( 实例ID );
my $data = join ' ', map{ $d[$title{$_}] }map{ Encode::encode( 'utf8', $_ )}qw( system );
my $cont = join ' ', map{ $d[$title{$_}] }map{ Encode::encode( 'utf8', $_ )}qw( contact );
my $owner = 'unknown';
my @cont = split /\|/, $cont;
if( @cont >= 2 )
{
$owner = $cont[1] if $cont[1] && $cont[1] =~ /@/;
$owner =~ s/^\s*//;
$owner =~ s/\s*$//;
}
next if $owner eq 'unkown';
next if $owner eq 'unknown';
map{ next if $_ eq 'aws-eip' }@d;
my @tmpid = grep{ $_ =~ /^\d+\.\d+\.\d+\.\d+$/ }split /\s/, $data;
push @tmpid, $uuid;
map{ $res{$_} = $owner; $cnt{$_} ++ } @tmpid;
}
for my $x ( @ip )
{
printf "$x: %s\n", $cnt{$x} && $cnt{$x} eq 1 ? $res{$x} : "unknown";
}