"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/Ocsinventory/Agent/Modules/SnmpScan.pm" between
Ocsinventory-Unix-Agent-2.8.0.tar.gz and Ocsinventory-Unix-Agent-2.8.1.tar.gz

About: Ocsinventory-Agent is a Linux agent for OCS Inventory NG.

SnmpScan.pm  (Ocsinventory-Unix-Agent-2.8.0):SnmpScan.pm  (Ocsinventory-Unix-Agent-2.8.1)
skipping to change at line 15 skipping to change at line 15
## ##
## This code is open source and may be copied and modified as long as the source ## This code is open source and may be copied and modified as long as the source
## code is always made freely available. ## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt ## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################ ################################################################################
package Ocsinventory::Agent::Modules::SnmpScan; package Ocsinventory::Agent::Modules::SnmpScan;
use strict; use strict;
no strict 'refs'; no strict 'refs';
no strict 'subs';
use warnings; use warnings;
use XML::Simple; use XML::Simple;
use Digest::MD5; use Digest::MD5;
sub new { sub new {
my $name="snmpscan"; #Set the name of your module here my $name="snmpscan"; #Set the name of your module here
my (undef,$context) = @_; my (undef,$context) = @_;
my $self = {}; my $self = {};
skipping to change at line 43 skipping to change at line 44
$self->{structure}= { $self->{structure}= {
name => $name, name => $name,
start_handler => $name."_start_handler", start_handler => $name."_start_handler",
prolog_writer => undef, prolog_writer => undef,
prolog_reader => $name."_prolog_reader", prolog_reader => $name."_prolog_reader",
inventory_handler => undef, inventory_handler => undef,
end_handler => $name."_end_handler", end_handler => $name."_end_handler",
}; };
$self->{number_scan}=0;
$self->{snmp_oid_run}=$name."_oid_run";
$self->{snmp_oid_xml}=$name."_oid_xml";
$self->{func_oid}={};
$self->{snmp_dir}=[];
$self->{snmp_vardir} = ["$self->{context}->{installpath}/snmp/mibs/local/","
$self->{context}->{installpath}/snmp/mibs/remote/"];
my $spec_dir_snmp="Ocsinventory/Agent/Modules/Snmp/";
$self->{spec_dir_snmp}=$spec_dir_snmp;
$self->{spec_module_snmp}="Ocsinventory::Agent::Modules::Snmp::";
# We are going to search where is the directory Ocsinventory/Modules/snmp
foreach my $dir ( @INC ) {
my $res_dir=$dir."/".$spec_dir_snmp;
if ( -d $res_dir ) {
push(@{$self->{snmp_dir}},$res_dir);
}
}
# We create a xml for the snmp inventory that we will be sent to server # We create a xml for the snmp inventory that we will be sent to server
$self->{inventory}={}; $self->{inventory}={};
bless $self; bless $self;
} }
sub snmpscan_start_handler { sub snmpscan_start_handler {
my $self = shift; my $self = shift;
my $logger = $self->{logger}; my $logger = $self->{logger};
my $common = $self->{context}->{common}; my $common = $self->{context}->{common};
skipping to change at line 94 skipping to change at line 76
$self->{disabled} = 1; $self->{disabled} = 1;
$logger->error("Net::SNMP perl module is missing !!"); $logger->error("Net::SNMP perl module is missing !!");
$logger->error("Humm my prerequisites are not OK...disabling module :( : ("); $logger->error("Humm my prerequisites are not OK...disabling module :( : (");
} }
} }
sub snmpscan_prolog_reader { sub snmpscan_prolog_reader {
my ($self, $prolog) = @_; my ($self, $prolog) = @_;
my $logger = $self->{logger}; my $logger = $self->{logger};
my $network = $self->{context}->{network}; my $network = $self->{context}->{network};
my $snmp_vardir = $self->{snmp_vardir};
my $option; my $option;
$logger->debug("Calling snmp_prolog_reader"); $logger->debug("Calling snmp_prolog_reader");
$prolog = XML::Simple::XMLin( $prolog, ForceArray => ['OPTION', 'PARAM']); $prolog = XML::Simple::XMLin( $prolog, ForceArray => ['OPTION', 'PARAM']);
for $option (@{$prolog->{OPTION}}){ for $option (@{$prolog->{OPTION}}){
if ($option->{NAME} =~/snmp/i){ if ($option->{NAME} =~/snmp/i){
$self->{doscans} = 1 ; $self->{doscans} = 1 ;
skipping to change at line 142 skipping to change at line 123
CONDITION_OID => $_->{CONDITION_OID}, CONDITION_OID => $_->{CONDITION_OID},
CONDITION_VALUE => $_->{CONDITION_VALUE} CONDITION_VALUE => $_->{CONDITION_VALUE}
}; };
push @{$self->{snmp_type_infos}},{ push @{$self->{snmp_type_infos}},{
TABLE_TYPE_NAME => $_->{TABLE_TYPE_NAME}, TABLE_TYPE_NAME => $_->{TABLE_TYPE_NAME},
LABEL_NAME => $_->{LABEL_NAME}, LABEL_NAME => $_->{LABEL_NAME},
OID => $_->{OID} OID => $_->{OID}
}; };
} }
# Creating the directory for xml if they don't yet exist
mkdir($self->{context}->{installpath}."/snmp") unless -d $self->
{context}->{installpath}."/snmp";
mkdir($self->{context}->{installpath}."/snmp/mibs") unless -d $s
elf->{context}->{installpath}."/snmp/mibs";
foreach my $dir ( @{$snmp_vardir}) {
mkdir($dir) unless -d $dir;
}
} }
} }
} }
} }
sub snmpscan_end_handler { sub snmpscan_end_handler {
my $self = shift; my $self = shift;
my $logger = $self->{logger}; my $logger = $self->{logger};
my $common = $self->{context}->{common}; my $common = $self->{context}->{common};
my $network = $self->{context}->{network}; my $network = $self->{context}->{network};
skipping to change at line 170 skipping to change at line 144
$logger->debug("Calling snmp_end_handler"); $logger->debug("Calling snmp_end_handler");
# If no order form server # If no order form server
return unless $self->{doscans}; return unless $self->{doscans};
# Flushing xmltags if it has not been done # Flushing xmltags if it has not been done
$common->flushXMLTags(); $common->flushXMLTags();
# We get the config # We get the config
my $config = $self->{context}->{config}; my $config = $self->{context}->{config};
# Load setting from the config file
my $configagent = new Ocsinventory::Agent::Config;
$configagent->loadUserParams();
my $communities=$self->{communities}; my $communities=$self->{communities};
if ( ! defined ($communities ) ) { if ( ! defined ($communities ) ) {
$logger->debug("We have no Community from server, we use default public community"); $logger->debug("We have no Community from server, we use default public community");
$communities=[{VERSION=>"2c",NAME=>"public"}]; $communities=[{VERSION=>"2c",NAME=>"public"}];
} }
my ($name,$comm,$error,$system_oid); my ($name,$comm,$error,$system_oid);
# Initalising the XML properties # Initalising the XML properties
skipping to change at line 215 skipping to change at line 192
# Search for the good snmp community in the table community # Search for the good snmp community in the table community
LIST_SNMP: foreach $comm ( @$communities ) { LIST_SNMP: foreach $comm ( @$communities ) {
# Test if we use SNMP v3 # Test if we use SNMP v3
if ( $comm->{VERSION} eq "3" ) { if ( $comm->{VERSION} eq "3" ) {
($session, $error) = Net::SNMP->session( ($session, $error) = Net::SNMP->session(
-retries => 2 , -retries => 2 ,
-timeout => 3, -timeout => 3,
-version => 'snmpv'.$comm->{VERSION}, -version => 'snmpv'.$comm->{VERSION},
-hostname => $device->{IPADDR}, -hostname => $device->{IPADDR},
-translate => [-nosuchinstance => 0, -nosuchobject => 0], -translate => [-nosuchinstance => 0, -nosuchobject => 0, - octetstring => 0],
-username => $comm->{USERNAME}, -username => $comm->{USERNAME},
-authpassword => $comm->{AUTHPASSWD}, -authpassword => $comm->{AUTHPASSWD},
-authprotocol => $comm->{AUTHPROTO}, -authprotocol => $comm->{AUTHPROTO},
-privpassword => $comm->{PRIVPASSWD}, -privpassword => $comm->{PRIVPASSWD},
-privprotocol => $comm->{PRIVPROTO}, -privprotocol => $comm->{PRIVPROTO},
); );
# For a use in constructor module (Cisco) # For a use in constructor module (Cisco)
$self->{username}=$comm->{USERNAME}; $self->{username}=$comm->{USERNAME};
$self->{authpassword}=$comm->{AUTHPASSWD}; $self->{authpassword}=$comm->{AUTHPASSWD};
$self->{authprotocol}=$comm->{AUTHPROTO}; $self->{authprotocol}=$comm->{AUTHPROTO};
$self->{privpassword}=$comm->{PRIVPASSWD}; $self->{privpassword}=$comm->{PRIVPASSWD};
$self->{privprotocol}= $comm->{PRIVPROTO}; $self->{privprotocol}= $comm->{PRIVPROTO};
} else { } else {
# We have an older version v2c ou v1 # We have an older version v2c ou v1
($session, $error) = Net::SNMP->session( ($session, $error) = Net::SNMP->session(
-retries => 1 , -retries => $configagent->{config}{snmpretry}, # SNMP re
-timeout => 3, tyr in config file
-timeout => $configagent->{config}{snmptimeout}, # SNMP
Timeout in config file
-version => 'snmpv'.$comm->{VERSION}, -version => 'snmpv'.$comm->{VERSION},
-hostname => $device->{IPADDR}, -hostname => $device->{IPADDR},
-community => $comm->{NAME}, -community => $comm->{NAME},
-translate => [-nosuchinstance => 0, -nosuchobject => 0], -translate => [-nosuchinstance => 0, -nosuchobject => 0, - octetstring => 0],
); );
}; };
unless (defined($session)) { unless (defined($session)) {
$logger->error("Snmp ERROR: $error"); $logger->error("Snmp ERROR: $error");
} else { } else {
$self->{snmp_session}=$session; $self->{snmp_session}=$session;
# For a use in constructor module (Cisco) # For a use in constructor module (Cisco)
$self->{snmp_community}=$comm->{NAME}; $self->{snmp_community}=$comm->{NAME};
$self->{snmp_version}=$comm->{VERSION}; $self->{snmp_version}=$comm->{VERSION};
 End of changes. 8 change blocks. 
34 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)