-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpengear.pm
55 lines (50 loc) · 1.18 KB
/
Opengear.pm
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
package CFG2JSON::Opengear;
use strict;
use NetAddr::IP;
use Data::Dumper;
my $gbics;
sub new{
my $gbics=();
my $class = shift;
my $args = { @_ };
my $config=$args->{config};
my $dev=getinfo($config);
#print Dumper $gbics;
my $interfaces=getinterfaces($config);
#my $interfaces={};
$dev->{interfaces}=$interfaces;
my $self = bless {device=>$dev}, $class;
}
sub getinfo{
my @config=split("\n",$_[0]);
my $obj={};
for(@config){
$obj->{model}=$1 if $_=~/config.system.model\s+(.*)/i;
$obj->{version}=$1 if $_=~/.*Version\s+([\w\.]+).*/i;
$obj->{serial}=$1 if $_=~/config.system.name\s(.*)/i;
}
my $sn=pop @config;
$obj->{serial}=$sn if $sn=~/^[\d]+$/;
return $obj;
}
sub getinterfaces{
my @config=split("\n",$_[0]);
my ($holdints,$ints);
for(@config){
if($_=~/config\.ports\.(port[\d]+)\.([\w]+)\s(.*)/i){
my ($int,$key,$value)=($1,$2,$3);
$int=~s/port/p/;
$holdints->{$int}{$key}=$value
}
}
#print Dumper $holdints;
for(keys %{$holdints}){
my $label=$holdints->{$_}{label};
$label=~s/-new ceres//i;
my $i=$_.':'.$label;
$ints->{$i}{formfactor}='NONE';
$ints->{$i}{label}=$label;
}
return $ints;
}
1