78
79
my $lanToDiscover = $current_context->{'PARAMS'}{'IPDISCOVER'}->{'TVALUE'};
79
80
my $behaviour = $current_context->{'PARAMS'}{'IPDISCOVER'}->{'IVALUE'};
80
81
my $groupsParams = $current_context->{'PARAMS_G'};
83
#Only if communication is https
84
if ($current_context->{'APACHE_OBJECT'}->subprocess_env('https')) {
86
$select_deviceid_req=$dbh->prepare('SELECT DEVICEID FROM hardware WHERE DEVICEID=?');
87
$select_deviceid_req->execute($current_context->{'DEVICEID'});
89
#Only if agent deviceid already exists in database
90
if ($select_deviceid_req->fetchrow_hashref) {
82
#If the computer is Ipdicover elected
83
if ($behaviour == 1 || $behaviour == 2) {
85
#Getting non inventoried network devices for the agent subnet
86
$select_ip_req=$dbh->prepare('SELECT IP,MAC FROM netmap WHERE NETID=? AND mac NOT IN (SELECT DISTINCT(macaddr) FROM networks WHERE macaddr IS NOT NULL AND IPSUBNET=?)');
87
$select_ip_req->execute($lanToDiscover,$lanToDiscover);
89
while(my $row = $select_ip_req->fetchrow_hashref){
90
push @DevicesToScan,$row;
95
#Adding devices informations in the XML
96
foreach my $device (@DevicesToScan) {
98
'IPADDR' => $device->{IP},
99
'MACADDR' => $device->{MAC},
104
#Getting snmp_com.txt URI
105
$select_snmpcom_uri=$dbh->prepare('SELECT TVALUE FROM config WHERE NAME="SNMP_URI"');
106
$select_snmpcom_uri->execute();
108
if (my $row = $select_snmpcom_uri->fetchrow_hashref) {
109
#Adding snmp_com.txt URI in XML
111
'TYPE' => 'COMMUNITY',
112
'SNMPCOM_LOC' => $row->{'TVALUE'},
117
push @{ $resp->{'OPTION'} },{
92
#If the computer is Ipdicover elected
93
if ($behaviour == 1 || $behaviour == 2) {
95
#Getting non inventoried network devices for the agent subnet
96
$select_ip_req=$dbh->prepare('SELECT IP,MAC FROM netmap WHERE NETID=? AND mac NOT IN (SELECT DISTINCT(macaddr) FROM networks WHERE macaddr IS NOT NULL AND IPSUBNET=?)');
97
$select_ip_req->execute($lanToDiscover,$lanToDiscover);
99
while(my $row = $select_ip_req->fetchrow_hashref){
100
push @devicesToScan,$row;
103
if (@devicesToScan) {
105
#Adding devices informations in the XML
106
foreach my $device (@devicesToScan) {
108
'IPADDR' => $device->{IP},
109
'MACADDR' => $device->{MAC},
114
#Getting snmp communities
115
$select_communities_req = $dbh->prepare('SELECT VERSION,NAME,USERNAME,AUTHKEY,AUTHPASSWD FROM snmp_communities');
116
$select_communities_req->execute();
118
while(my $row = $select_communities_req->fetchrow_hashref){
119
push @communities,$row;
123
foreach my $community (@communities) {
125
'VERSION' => $community->{'VERSION'}?$community->{'VERSION'}:'',
126
'NAME' => $community->{'NAME'}?$community->{'NAME'}:'',
127
'USERNAME' => $community->{'USERNAME'}?$community->{'USERNAME'}:'',
128
'AUTHKEY' => $community->{'AUTHKEY'}?$community->{'AUTHKEY'}:'',
129
'AUTHPASSWD' => $community->{'AUTHPASSWD'}?$community->{'AUTHPASSWD'}:'',
130
'TYPE' => 'COMMUNITY',
136
push @{ $resp->{'OPTION'} },{
142
} else { &_log(104,'snmp',"error: agent must have a deviceid in database !!"); }
143
} else { &_log(103,'snmp',"error: agent must communicate using https to be able to get SNMP communities !!"); }
125
146
sub snmp_handler{
127
147
my $current_context = shift;
129
149
#Verify if SNMP is enable for this computer or in config