From e066ecf2d84f33666c98d230571536a3030c739a Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Thu, 7 Jul 2011 08:48:38 +0000 Subject: [PATCH] 2011-07-07 Sergio Martin * Makefile.PL lib/PandoraFMS/ReconServer.pm util/recon_scripts/snmpdevices.pl: Added disabled condition to recon tasks, readd NetAddr dependence and fix several bugs in addres loop into recon script git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4516 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 8 +++++++ pandora_server/Makefile.PL | 1 + pandora_server/lib/PandoraFMS/ReconServer.pm | 3 ++- .../util/recon_scripts/snmpdevices.pl | 24 ++++++++++++++----- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index ece53616bc..ca1e6a4308 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2011-07-07 Sergio Martin + + * Makefile.PL + lib/PandoraFMS/ReconServer.pm + util/recon_scripts/snmpdevices.pl: Added disabled + condition to recon tasks, readd NetAddr dependence and + fix several bugs in addres loop into recon script + 2011-07-01 Ramon Novoa * Makefile.PL: Removed NetAddr::IP from the dependency list. Not diff --git a/pandora_server/Makefile.PL b/pandora_server/Makefile.PL index 883b76bbde..6f6516d62a 100644 --- a/pandora_server/Makefile.PL +++ b/pandora_server/Makefile.PL @@ -10,6 +10,7 @@ WriteMakefile( VERSION_FROM => 'lib/PandoraFMS/Config.pm', AUTHOR => 'Artica ST ', PREREQ_PM => { + NetAddr::IP => 0, DBI => 0, threads::shared => 0, IO::Socket => 0, diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index 0da4715a4d..c11404758c 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -96,7 +96,8 @@ sub data_producer ($) { # Status -1 means "done". my @rows = get_db_rows ($dbh, 'SELECT * FROM trecon_task - WHERE id_recon_server = ? + WHERE id_recon_server = ? + AND disabled = 0 AND utimestamp = 0 OR (status = -1 AND interval_sweep > 0 AND (utimestamp + interval_sweep) < UNIX_TIMESTAMP())', $server_id); foreach my $row (@rows) { diff --git a/pandora_server/util/recon_scripts/snmpdevices.pl b/pandora_server/util/recon_scripts/snmpdevices.pl index 26cbd1b37e..94b38f0112 100755 --- a/pandora_server/util/recon_scripts/snmpdevices.pl +++ b/pandora_server/util/recon_scripts/snmpdevices.pl @@ -60,7 +60,7 @@ sub show_help { print "Usage:\n\n"; print " $0 \n\n"; print " * custom_field1 = network. i.e.: 192.168.100.0/24\n"; - print " * custom_field2 = snmp_community. \n\n"; + print " * custom_field2 = snmp_community. \n"; print " * custom_field3 = optative parameter to force process downed interfaces (use: '-a'). Only up interfaces are processed by default \n\n"; print " Additional information:\nWhen the script is called from a recon task, 'task_id' parameter is automatically filled, "; print "group_id and create_incident_flag are passed from interface form combos and custom fields manually filled.\n\n\n"; @@ -125,7 +125,7 @@ sub process_module_snmp ($$$$$$$$$){ pandora_create_module_from_hash ($conf, \%parameters, $dbh); } else { - pandora_update_module_from_hash ($conf, \%parameters, $dbh, 'id_agente_modulo', $module_id); + pandora_update_module_from_hash ($conf, \%parameters, 'id_agente_modulo', $module_id, $dbh); } } @@ -166,16 +166,28 @@ if (! defined ($net_addr)) { # Scan the network for hosts my ($total_hosts, $hosts_found, $addr_found) = ($net_addr->num, 0, ''); -for (my $i = 1, $net_addr++; $net_addr <= $net_addr->broadcast; $i++, $net_addr++) { +my $last = 0; +for (my $i = 1; $net_addr <= $net_addr->broadcast; $i++, $net_addr++) { + if($last == 1) { + last; + } + if($net_addr eq $net_addr++) { + $last = 1; + } + + + if ($net_addr =~ /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.(\d{1,3})\b/) { + if($1 eq '0' || $1 eq '255') { + next; + } + } + my $addr = (split(/\//, $net_addr))[0]; $hosts_found ++; # Update the recon task update_recon_task ($dbh, $task_id, ceil ($i / ($total_hosts / 100))); - - # Does the host already exist? - next if (get_agent_from_addr ($dbh, $addr) > 0); my $alive = 0; if (pandora_ping (\%conf, $addr) == 1) {