Skip to content

Commit

Permalink
drop SNMP dictionary support
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Mar 17, 2014
1 parent da9dd01 commit aad1f0d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 254 deletions.
87 changes: 1 addition & 86 deletions lib/FusionInventory/Agent/Task/NetDiscovery.pm
Expand Up @@ -15,7 +15,6 @@ use FusionInventory::Agent::HTTP::Client::OCS;
use FusionInventory::Agent::Message::Outbound;
use FusionInventory::Agent::Recipient::Stdout;
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Task::NetDiscovery::Dictionary;

our $VERSION = $FusionInventory::Agent::VERSION;

Expand Down Expand Up @@ -58,53 +57,11 @@ sub getConfiguration {
push @credentials, $credential;
}

# dictionary
my $dictionary = $self->_getDictionary(
$options,
$params{controller}->getStorage()
);

if (!$dictionary) {
$self->{logger}->debug(
"No dictionary available, sending update message and exiting"
);
my $client = FusionInventory::Agent::HTTP::Client::OCS->new(
logger => $self->{logger},
user => $params{user},
password => $params{password},
proxy => $params{proxy},
ca_cert_file => $params{ca_cert_file},
ca_cert_dir => $params{ca_cert_dir},
no_ssl_check => $params{no_ssl_check},
);

my $message = FusionInventory::Agent::Message::Outbound->new(
deviceid => $self->{config}->{deviceid},
query => 'NETDISCOVERY',
content => {
AGENT => {
END => '1'
},
MODULEVERSION => $FusionInventory::Agent::VERSION,
PROCESSNUMBER => $options->{PARAM}->[0]->{PID},
DICO => "REQUEST",
}
);

$client->send(
url => $params{controller}->getUrl(),
message => $message
);

return;
}

return (
pid => $options->{PARAM}->[0]->{PID},
threads => $options->{PARAM}->[0]->{THREADS_DISCOVERY},
timeout => $options->{PARAM}->[0]->{TIMEOUT},
credentials => \@credentials,
dictionary => $dictionary,
blocks => \@blocks
);
}
Expand All @@ -130,7 +87,7 @@ sub run {
my $pid = $self->{config}->{pid};

# check discovery methods available
my ($nmap_parameters, $snmp_credentials, $snmp_dictionary);
my ($nmap_parameters, $snmp_credentials);

if (canRun('nmap')) {
my ($major, $minor) = getFirstMatch(
Expand Down Expand Up @@ -161,7 +118,6 @@ sub run {
);
} else {
$snmp_credentials = _filterCredentials($self->{config}->{credentials});
$snmp_dictionary = $self->{config}->{dictionary};
}

# blocks list
Expand Down Expand Up @@ -197,7 +153,6 @@ sub run {
datadir => $self->{config}->{datadir},
nmap_parameters => $nmap_parameters,
snmp_credentials => $snmp_credentials,
snmp_dictionary => $snmp_dictionary,
threads => $threads,
timeout => $self->{config}->{timeout}
);
Expand Down Expand Up @@ -284,46 +239,6 @@ sub run {
);
}

sub _getDictionary {
my ($self, $options, $storage) = @_;

# use dictionary sent by the server, if available
if ($options->{DICO}) {
$self->{logger}->debug("New dictionary sent by the server");

my $dictionary =
FusionInventory::Agent::Task::NetDiscovery::Dictionary->new(
string => $options->{DICO},
hash => $options->{DICOHASH}
);

$storage->save(
name => 'dictionary',
data => { dictionary => $dictionary }
);
return $dictionary;
}

# otherwise, retrieve last saved one
$self->{logger}->debug("Retrieving stored dictionary");
my $data = $storage->restore(name => 'dictionary');
my $dictionary = $data->{dictionary};

if (!$dictionary) {
$self->{logger}->debug("Dictionary is missing");
return;
}

# check its status
my $hash = $dictionary->getHash();
if ($hash ne $options->{DICOHASH}) {
$self->{logger}->debug("Dictionary is outdated");
return;
}

return $dictionary;
}

sub _filterCredentials {
my ($credentials) = @_;

Expand Down
120 changes: 0 additions & 120 deletions lib/FusionInventory/Agent/Task/NetDiscovery/Dictionary.pm

This file was deleted.

2 changes: 0 additions & 2 deletions lib/FusionInventory/Agent/Task/NetDiscovery/Engine.pm
Expand Up @@ -15,7 +15,6 @@ sub new {
my $self = {
nmap_parameters => $params{nmap_parameters},
snmp_credentials => $params{snmp_credentials},
snmp_dictionary => $params{snmp_dictionary},
logger => $params{logger},
timeout => $params{timeout} || 1,
datadir => $params{datadir},
Expand Down Expand Up @@ -147,7 +146,6 @@ sub _scanAddressBySNMPReal {

return getDeviceInfo(
snmp => $snmp,
dictionary => $self->{snmp_dictionary},
datadir => $self->{datadir},
);
}
Expand Down
46 changes: 5 additions & 41 deletions lib/FusionInventory/Agent/Tools/Hardware.pm
Expand Up @@ -602,22 +602,11 @@ sub _loadDeviceModels {
return $models;
}

sub _getSerial {
my ($snmp, $model) = @_;

return unless $model->{SERIAL};
return _getCanonicalSerialNumber($snmp->get($model->{SERIAL}));
}

sub _getMacAddress {
my ($snmp, $model) = @_;
my ($snmp) = @_;

my $mac_oid =
$model->{MAC} ||
".1.3.6.1.2.1.17.1.1.0"; # SNMPv2-SMI::mib-2.17.1.1.0
my $dynmac_oid =
$model->{DYNMAC} ||
".1.3.6.1.2.1.2.2.1.6"; # IF-MIB::ifPhysAddress
my $mac_oid = ".1.3.6.1.2.1.17.1.1.0"; # SNMPv2-SMI::mib-2.17.1.1.0
my $dynmac_oid = ".1.3.6.1.2.1.2.2.1.6"; # IF-MIB::ifPhysAddress

my $address = _getCanonicalMacAddress($snmp->get($mac_oid));

Expand All @@ -638,37 +627,13 @@ sub getDeviceInfo {
my (%params) = @_;

my $snmp = $params{snmp};
my $dictionary = $params{dictionary};

# the device is initialized with basic information
# deduced from its sysdescr
my %device = getDeviceBaseInfo($snmp, $params{datadir});
return unless %device;

# then, we try to get a matching model from the dictionary,
# using its current description as identification key
my $model = $dictionary ?
$dictionary->getModel($device{DESCRIPTION}) : undef;

if ($model) {
# if found, we complete the device with model-defined mappings
$device{MANUFACTURER} = $model->{MANUFACTURER}
if $model->{MANUFACTURER};
$device{TYPE} =
$model->{TYPE} == 1 ? 'COMPUTER' :
$model->{TYPE} == 2 ? 'NETWORKING' :
$model->{TYPE} == 3 ? 'PRINTER' :
undef
if $model->{TYPE};

$device{MAC} = _getMacAddress($snmp, $model);
$device{SERIAL} = _getSerial($snmp, $model);
$device{MODELSNMP} = $model->{MODELSNMP};
$device{FIRMWARE} = $model->{FIRMWARE};
} else {
# otherwise, we fallback on default mappings
$device{MAC} = _getMacAddress($snmp);
}
$device{MAC} = _getMacAddress($snmp);

return %device;
}
Expand Down Expand Up @@ -1587,8 +1552,7 @@ set of rules hardcoded in the agent.
=head2 getDeviceInfo(%params)
return a limited set of information for a device through SNMP, according to a
set of rules hardcoded in the agent and the usage of generic knowledge base,
the dictionary.
set of rules hardcoded in the agent and the usage of generic knowledge base.
=head2 getDeviceFullInfo(%params)
Expand Down
6 changes: 3 additions & 3 deletions t/agent/tools/hardware/force10.t
Expand Up @@ -25486,9 +25486,9 @@ foreach my $test (sort keys %tests) {
datadir => './share'
);
cmp_deeply(
\%device1,
\%discovery,
$tests{$test}->[0],
"$test: discovery, without dictionary"
"$test: discovery"
);

my $inventory = getDeviceFullInfo(
Expand All @@ -25498,6 +25498,6 @@ foreach my $test (sort keys %tests) {
cmp_deeply(
$inventory,
$tests{$test}->[2],
"$test: inventory, without model"
"$test: inventory"
);
}
4 changes: 2 additions & 2 deletions t/agent/tools/hardware/juniper.t
Expand Up @@ -96064,7 +96064,7 @@ foreach my $test (sort keys %tests) {
cmp_deeply(
\%discovery,
$tests{$test}->[0],
"$test: discovery, without dictionary"
"$test: discovery"
);

my $inventory = getDeviceFullInfo(
Expand All @@ -96074,6 +96074,6 @@ foreach my $test (sort keys %tests) {
cmp_deeply(
$inventory,
$tests{$test}->[2],
"$test: inventory, without model"
"$test: inventory"
);
}

0 comments on commit aad1f0d

Please sign in to comment.