2012-09-28 Ramon Novoa <rnovoa@artica.es>

* lib/PandoraFMS/NetworkServer.pm,
	  lib/PandoraFMS/Tools.pm: Disable a module if a text obj tag cannot
	  be converted to an OID.

	* lib/PandoraFMS/ReconServer.pm: Small improvements.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7008 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2012-09-28 14:04:33 +00:00
parent c888327967
commit 229d03bc28
4 changed files with 80 additions and 71 deletions

View File

@ -1,3 +1,11 @@
2012-09-28 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm: Disable a module if a text obj tag cannot
be converted to an OID.
* lib/PandoraFMS/ReconServer.pm: Small improvements.
2012-09-28 Dario Rodriguez <dario.rodriguez@artica.es>
* util/pandora_xml_stress.conf,

View File

@ -502,23 +502,5 @@ sub exec_network_module ($$$$) {
}
}
###############################################################################
# Convert a text obj tag to an OID and update the module configuration.
###############################################################################
sub translate_obj ($$$) {
my ($dbh, $obj, $module_id) = @_;
# SNMP is not thread safe
$SNMPSem->down ();
my $oid = SNMP::translateObj ($obj);
$SNMPSem->up ();
# Update module configuration
$oid = '' unless defined ($oid);
db_do ($dbh, 'UPDATE tagente_modulo SET snmp_oid = ? WHERE id_agente_modulo = ?', $oid, $module_id);
return $oid;
}
1;
__END__

View File

@ -156,13 +156,24 @@ sub data_consumer ($$) {
# Update the recon task or break if it does not exist anymore
last if (update_recon_task ($dbh, $task_id, ceil ($progress / ($total_up / 100))) eq '0E0');
# Resolve hostnames
my $host_name = undef;
if ($task->{'resolve_names'} == 1){
$host_name = gethostbyaddr (inet_aton($addr), AF_INET);
}
$host_name = $addr unless defined ($host_name);
# Does the host already exist?
my $agent = get_agent_from_addr ($dbh, $addr);
if (! defined ($agent)) {
$agent = get_agent_from_name ($dbh, $host_name);
}
my $agent_id = defined ($agent) ? $agent->{'id_agente'} : 0;
if ($agent_id > 0) {
# Skip if not in learning mode or parent detection is disabled
next if ($agent->{'modo'} != 1 || $task->{'parent_detection'} == 0);
# Skip if not in learning mode
next if ($agent->{'modo'} != 1);
}
# Filter by TCP port
@ -183,6 +194,21 @@ sub data_consumer ($$) {
$parent_id = get_host_parent ($pa_config, $addr, $dbh, $task->{'id_group'}, $task->{'parent_recursion'}, $task->{'resolve_names'}, $task->{'os_detect'});
}
# Add the new address if it does not exist
my $addr_id = get_addr_id ($dbh, $addr);
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
if ($addr_id <= 0) {
logger($pa_config, "Could not add address '$addr' for host '$host_name'.", 3);
next;
}
# Assign the new address to the agent
my $agent_addr_id = get_agent_addr_id ($dbh, $addr_id, $agent_id);
if ($agent_addr_id <= 0) {
db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
VALUES (?, ?)', $addr_id, $agent_id);
}
# If the agent already exists update parent and continue
if ($agent_id > 0) {
if ($parent_id > 0) {
@ -190,29 +216,14 @@ sub data_consumer ($$) {
}
next;
}
# Resolve hostnames
my $host_name = undef;
if ($task->{'resolve_names'} == 1){
$host_name = gethostbyaddr (inet_aton($addr), AF_INET);
}
$host_name = $addr unless defined ($host_name);
# Add the new address if it does not exist
my $addr_id = get_addr_id ($dbh, $addr);
$addr_id = add_address ($dbh, $addr) unless ($addr_id > 0);
if ($addr_id <= 0) {
logger($pa_config, "Could not add address '$addr' for host '".safe_output($host_name)."'.", 3);
next;
}
# GIS Code -----------------------------
# GIS Code -----------------------------
# If GIS is activated try to geolocate the ip address of the agent
# and store also it's position.
# and store also it's position.
if($pa_config->{'activate_gis'} == 1 && $pa_config->{'recon_reverse_geolocation_mode'} !~ m/^disabled$/i) {
# Try to get aproximated positional information for the Agent.
my $region_info = undef;
if ($pa_config->{'recon_reverse_geolocation_mode'} =~ m/^sql$/i) {
@ -268,11 +279,7 @@ sub data_consumer ($$) {
logger($pa_config, "Error creating agent '$host_name'.", 3);
next;
}
# Assign the new address to the agent
db_do ($dbh, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
VALUES (?, ?)', $addr_id, $agent_id);
# Create network profile modules for the agent
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});

View File

@ -67,6 +67,7 @@ our @EXPORT = qw(
safe_input
safe_output
month_have_days
translate_obj
);
########################################################################
@ -809,14 +810,11 @@ sub pandora_ping ($$) {
# Windows XP .. Windows 7
if (($OSNAME eq "MSWin32") || ($OSNAME eq "MSWin32-x64") || ($OSNAME eq "cygwin")){
my $ms_timeout = $pa_config->{'networktimeout'} * 1000;
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
$output = `ping -n 1 -w $ms_timeout $host`;
if ($output =~ /TTL/){
return 1;
}
sleep 1;
$output = `ping -n $pa_config->{'icmp_checks'} -w $ms_timeout $host`;
if ($output =~ /TTL/){
return 1;
}
return 0;
return 0;
}
elsif ($OSNAME eq "solaris"){
@ -830,12 +828,9 @@ sub pandora_ping ($$) {
# 'networktimeout' is not used by ping on Solaris.
# Ping the host
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
`$ping_command -s -n $host 56 1 >/dev/null 2>&1`;
if ($? == 0) {
return 1;
}
sleep 1;
`$ping_command -s -n $host 56 $pa_config->{'icmp_checks'} >/dev/null 2>&1`;
if ($? == 0) {
return 1;
}
return 0;
}
@ -851,12 +846,9 @@ sub pandora_ping ($$) {
# 'networktimeout' is not used by ping6 on FreeBSD.
# Ping the host
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
`$ping_command -q -n -c 1 $host >/dev/null 2>&1`;
if ($? == 0) {
return 1;
}
sleep 1;
`$ping_command -q -n -c $pa_config->{'icmp_checks'} $host >/dev/null 2>&1`;
if ($? == 0) {
return 1;
}
return 0;
}
@ -871,12 +863,9 @@ sub pandora_ping ($$) {
}
# Ping the host
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
`$ping_command -q -W $pa_config->{'networktimeout'} -n -c 1 $host >/dev/null 2>&1`;
if ($? == 0) {
return 1;
}
sleep 1;
`$ping_command -q -W $pa_config->{'networktimeout'} -n -c $pa_config->{'icmp_checks'} $host >/dev/null 2>&1`;
if ($? == 0) {
return 1;
}
return 0;
}
@ -1026,6 +1015,29 @@ sub month_have_days($$) {
return $monthDays[$month];
}
###############################################################################
# Convert a text obj tag to an OID and update the module configuration.
###############################################################################
sub translate_obj ($$$) {
my ($dbh, $obj, $module_id) = @_;
# SNMP is not thread safe
$SNMPSem->down ();
my $oid = SNMP::translateObj ($obj);
$SNMPSem->up ();
# Could not translate OID, disable the module
if (! defined ($oid)) {
db_do ($dbh, 'UPDATE tagente_modulo SET disabled = 1', $oid, $module_id);
return '';
}
# Update module configuration
db_do ($dbh, 'UPDATE tagente_modulo SET snmp_oid = ? WHERE id_agente_modulo = ?', $oid, $module_id);
return $oid;
}
# End of function declaration
# End of defined Code