-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfusioninventory-netdiscovery
executable file
·170 lines (133 loc) · 3.45 KB
/
fusioninventory-netdiscovery
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/perl
use strict;
use warnings;
use lib './lib';
use English qw(-no_match_vars);
use Getopt::Long;
use Pod::Usage;
use FusionInventory::Agent::Task::NetDiscovery;
use FusionInventory::Agent::Logger;
my $options = {
community => 'public',
threads => 1
};
GetOptions(
$options,
'first=s',
'last=s',
'dictionnary=s',
'community=s',
'entity=s',
'threads=i',
'debug+',
'help',
) or pod2usage(-verbose => 0);
pod2usage(-verbose => 0, -exitval => 0) if $options->{help};
pod2usage(
-message => "no first address, aborting\n", -verbose => 0
) unless $options->{first};
pod2usage(
-message => "no last address, aborting\n", -verbose => 0
) unless $options->{last};
my $discovery = FusionInventory::Agent::Task::NetDiscovery->new(
target => FusionInventory::Agent::Task::NetInventory::Target->new(
dictionnary => $options->{dictionnary}
),
logger => FusionInventory::Agent::Logger->new(
debug => $options->{debug}
)
);
$discovery->{options} = {
NAME => 'NETDISCOVERY',
PARAM => [
{
PID => 1,
THREADS_DISCOVERY => $options->{threads}
}
],
RANGEIP => [
{
ID => 1,
IPSTART => $options->{first},
IPEND => $options->{last},
}
],
AUTHENTICATION => [
{
ID => 1,
COMMUNITY => $options->{community},
VERSION => '2c'
}
]
};
if ($options->{dictionnary}) {
die "no such file $options->{dictionnary}"
unless -f $options->{dictionnary};
$discovery->{options}->{DICO} = getDictionnary($options->{dictionnary});
}
if ($options->{entity}) {
$discovery->{options}->{RANGEIP}->[0]->{ENTITY} = $options->{entity};
}
$discovery->{client} =
FusionInventory::Agent::Task::NetInventory::Client->new();
$discovery->{deviceid} = 'foo';
$discovery->run();
sub getDictionnary {
my ($file) = @_;
open (my $handle, '<', $file) or die "Can't open $file: $ERRNO";
local $INPUT_RECORD_SEPARATOR;
my $string = <$handle>;
close $handle;
return $string;
}
package FusionInventory::Agent::Task::NetInventory::Client;
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub send {
my ($self, %params) = @_;
print $params{message}->getContent();
}
package FusionInventory::Agent::Task::NetInventory::Target;
sub new {
my ($class, %params) = @_;
my $storage = FusionInventory::Agent::Task::NetInventory::Storage->new();
return bless {
storage => $storage
}, $class;
}
sub getStorage {
my ($self, %params) = @_;
return $self->{storage};
}
sub getUrl {
my ($self, %params) = @_;
return undef;
}
package FusionInventory::Agent::Task::NetInventory::Storage;
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub save {
}
sub restore {
return {
dictionary =>
FusionInventory::Agent::Task::NetDiscovery::Dictionary->new()
};
}
__END__
=head1 NAME
fusioninventory-discovery - Network inventory from command line
=head1 SYNOPSIS
fusioninventory-discovery [options] --start <start> --stop <stop>
Options:
-h --help this menu
--first address IP range first address
--last address IP range last address
--dictionnary dictionnary file
--community community string (default: public)
--threads nb number of discovery threads (default: 1)
--debug verbose output