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:
parent
c888327967
commit
229d03bc28
|
@ -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>
|
2012-09-28 Dario Rodriguez <dario.rodriguez@artica.es>
|
||||||
|
|
||||||
* util/pandora_xml_stress.conf,
|
* util/pandora_xml_stress.conf,
|
||||||
|
|
|
@ -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;
|
1;
|
||||||
__END__
|
__END__
|
||||||
|
|
|
@ -156,13 +156,24 @@ sub data_consumer ($$) {
|
||||||
# Update the recon task or break if it does not exist anymore
|
# 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');
|
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?
|
# Does the host already exist?
|
||||||
my $agent = get_agent_from_addr ($dbh, $addr);
|
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;
|
my $agent_id = defined ($agent) ? $agent->{'id_agente'} : 0;
|
||||||
if ($agent_id > 0) {
|
if ($agent_id > 0) {
|
||||||
|
|
||||||
# Skip if not in learning mode or parent detection is disabled
|
# Skip if not in learning mode
|
||||||
next if ($agent->{'modo'} != 1 || $task->{'parent_detection'} == 0);
|
next if ($agent->{'modo'} != 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Filter by TCP port
|
# 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'});
|
$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 the agent already exists update parent and continue
|
||||||
if ($agent_id > 0) {
|
if ($agent_id > 0) {
|
||||||
if ($parent_id > 0) {
|
if ($parent_id > 0) {
|
||||||
|
@ -191,21 +217,6 @@ sub data_consumer ($$) {
|
||||||
next;
|
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
|
# If GIS is activated try to geolocate the ip address of the agent
|
||||||
|
@ -269,10 +280,6 @@ sub data_consumer ($$) {
|
||||||
next;
|
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 for the agent
|
||||||
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});
|
create_network_profile_modules ($pa_config, $dbh, $agent_id, $task->{'id_network_profile'}, $addr, $task->{'snmp_community'});
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ our @EXPORT = qw(
|
||||||
safe_input
|
safe_input
|
||||||
safe_output
|
safe_output
|
||||||
month_have_days
|
month_have_days
|
||||||
|
translate_obj
|
||||||
);
|
);
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -809,13 +810,10 @@ sub pandora_ping ($$) {
|
||||||
# Windows XP .. Windows 7
|
# Windows XP .. Windows 7
|
||||||
if (($OSNAME eq "MSWin32") || ($OSNAME eq "MSWin32-x64") || ($OSNAME eq "cygwin")){
|
if (($OSNAME eq "MSWin32") || ($OSNAME eq "MSWin32-x64") || ($OSNAME eq "cygwin")){
|
||||||
my $ms_timeout = $pa_config->{'networktimeout'} * 1000;
|
my $ms_timeout = $pa_config->{'networktimeout'} * 1000;
|
||||||
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
|
$output = `ping -n $pa_config->{'icmp_checks'} -w $ms_timeout $host`;
|
||||||
$output = `ping -n 1 -w $ms_timeout $host`;
|
|
||||||
if ($output =~ /TTL/){
|
if ($output =~ /TTL/){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sleep 1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,13 +828,10 @@ sub pandora_ping ($$) {
|
||||||
# 'networktimeout' is not used by ping on Solaris.
|
# 'networktimeout' is not used by ping on Solaris.
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
|
`$ping_command -s -n $host 56 $pa_config->{'icmp_checks'} >/dev/null 2>&1`;
|
||||||
`$ping_command -s -n $host 56 1 >/dev/null 2>&1`;
|
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sleep 1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -851,13 +846,10 @@ sub pandora_ping ($$) {
|
||||||
# 'networktimeout' is not used by ping6 on FreeBSD.
|
# 'networktimeout' is not used by ping6 on FreeBSD.
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
|
`$ping_command -q -n -c $pa_config->{'icmp_checks'} $host >/dev/null 2>&1`;
|
||||||
`$ping_command -q -n -c 1 $host >/dev/null 2>&1`;
|
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sleep 1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,13 +863,10 @@ sub pandora_ping ($$) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
for ($i=0; $i < $pa_config->{'icmp_checks'}; $i++) {
|
`$ping_command -q -W $pa_config->{'networktimeout'} -n -c $pa_config->{'icmp_checks'} $host >/dev/null 2>&1`;
|
||||||
`$ping_command -q -W $pa_config->{'networktimeout'} -n -c 1 $host >/dev/null 2>&1`;
|
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sleep 1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1026,6 +1015,29 @@ sub month_have_days($$) {
|
||||||
return $monthDays[$month];
|
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 function declaration
|
||||||
# End of defined Code
|
# End of defined Code
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue