-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrape.pm
More file actions
131 lines (125 loc) · 3.13 KB
/
Scrape.pm
File metadata and controls
131 lines (125 loc) · 3.13 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package CFG2JSON::Scrape;
use strict;
use FindBin;
use lib $FindBin::Bin;
use JSON;
use CFG2JSON::Force10;
use CFG2JSON::Arista;
use CFG2JSON::Arbor;
use CFG2JSON::Opengear;
use CFG2JSON::Cisco;
use CFG2JSON::Juniper;
use File::Slurp;
sub new{
my $class = shift;
my $args = { @_ };
my $filepath=$args->{filepath};
my $hostname=$args->{hostname};
my $sitename=$args->{sitename};
my $config=read_file($filepath.'/'.$sitename.'/configs/'.$hostname);
my $vendor=_getVendor($config);
my $mgmtip=nslookup($hostname);
my $dev;
if($vendor eq 'force10'){
$dev=CFG2JSON::Force10->new(config=>$config);
}elsif($vendor eq 'arista'){
$dev=CFG2JSON::Arista->new(config=>$config);
}elsif($vendor eq 'cisco'){
$dev=CFG2JSON::Cisco->new(config=>$config);
}elsif($vendor eq 'opengear'){
$dev=CFG2JSON::Opengear->new(config=>$config);
}elsif($vendor =~ /juniper/){
$dev=CFG2JSON::Juniper->new(config=>$config);
}elsif($vendor eq 'arbor'){
$dev=CFG2JSON::Arbor->new(config=>$config);
}else{
$dev->{error}="No matching vendor found for $hostname!";
}
$dev->{device}{serial}='72481708004539' if $hostname eq 'ap-northeast-1c-4-oob';
$dev->{device}{mgmtip}=$mgmtip;
$dev->{device}{sitename}=$sitename;
$dev->{device}{hostname}=$hostname;
$dev->{device}{vendor}=$vendor;
$dev->{device}{devicerole}=getDeviceRole($hostname);
my $self = bless {
config => $config,
device => $dev->{device}
}, $class;
}
sub _getVendor{
my @cl=split("\n",$_[0]);
my $vl=shift @cl;
$vl=~s/[!#]RANCID-CONTENT-TYPE: //i;
$vl=~s/joy-//i;
$vl=~s/-srx//i;
return $vl
}
sub json{
my $self=shift;
return encode_json $self->{device};
}
sub gethash{
my $self=shift;
return $self->{device}
}
sub nslookup{
my $hn=$_[0];
#print "nslookup $hn\n";
my $nsl=`nslookup $_[0]`;
$nsl=~s/\n//g;
$nsl=~s/\'//g;
$nsl=~s/.*usAddress: (.*)$/$1/i;
$nsl=~s/.*server cant find.*/notfound/i;
return $nsl;
}
sub getDeviceRole{
my $l = shift;
my $req;
if($l=~/agg/){
$req='Aggregate';
}elsif($l=~/-lef([\d]+)?-/){
$req='Leaf'
}elsif($l=~/-spn([\d]+)?-/){
$req='Spine'
}elsif($l=~/.*(drc|-dc)$/i){
$req='DirectConnect';
}elsif($l=~/.*-(dc|mx480|service|ss|edg|svc|bro)/i){
$req='Edge';
}elsif($l=~/pdu/i){
$req='PDU';
}elsif($l=~/HSM/i){
$req='HSM';
}elsif($l=~/SDX/i){
$req='SDX';
}elsif($l=~/WAF/i){
$req='WAF';
}elsif($l=~/(srx|afw|sfw)/i){
$req='Firewall';
}elsif($l=~/ids/i){
$req='IDS';
}elsif($l=~/.*(bigswitch|bs4048|bsmf|bmf|\-BS).*/i){
$req='BigSwitch';
}elsif($l=~/.*(admin|mgt|mgg).*/i){
$req='NW Admin';
}elsif($l=~/.*(dist|dst).*/i){
$req='Distribution';
}elsif($l=~/.*(core).*/i){
$req='Core';
}elsif($l=~/.*(arbor|tms).*/i){
$req='Arbor';
}elsif($l=~/.*(logr|lr[12])/){
$req='LogRythm';
}elsif($l=~/.*-(con|oob)/i){
$req='NW Console';
}elsif($l=~/.*(kvm|dns|tac|opennms|cacti|netopsinfo|noctool|nftracker|ns[12]\.).*/i){
$req='Server';
}elsif($l=~/.*mx204.*/){
$req='Core';
}elsif($l=~/.*-e300-[12]/){
$req='Core';
}elsif($l=~/.*-tor/i || $l=~/.*[\d]+\-[12]/){
$req='TOR';
}
return $req;
}
1;