2007-10-04 Sancho Lerena <slerena@gmail.com>

* conf/pandora_server.conf, lib/PandoraFMS/Config.pm, bin/pandora_network:

        Merged code from NG branch: Added multiping check (global setting 'icmp_checks')
        on network server because in some WAN enviroments with erratic packet loss on non TCP
        connections would cause recurrent false positives. New config token added to config
        file (icmp_checks). Updated default .conf



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@667 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2007-10-04 10:45:46 +00:00
parent 2fdb207ae8
commit 15d224798a
4 changed files with 126 additions and 100 deletions

View File

@ -1,3 +1,12 @@
2007-10-04 Sancho Lerena <slerena@gmail.com>
* conf/pandora_server.conf, lib/PandoraFMS/Config.pm, bin/pandora_network:
Merged code from NG branch: Added multiping check (global setting 'icmp_checks')
on network server because in some WAN enviroments with erratic packet loss on non TCP
connections would cause recurrent false positives. New config token added to config
file (icmp_checks).
2007-10-03 Sancho lerena <slerena@gmail.com> 2007-10-03 Sancho lerena <slerena@gmail.com>
* lib/PandoraFMS/DB.pm: Fixed alert that fires always one time more than * lib/PandoraFMS/DB.pm: Fixed alert that fires always one time more than

View File

@ -243,65 +243,71 @@ sub pandora_network_producer ($) {
} }
############################################################################## ##############################################################################
# pandora_ping_icmp (destination, timeout) - Do a ICMP scan, 1 if alive, 0 if not # pandora_ping_icmp (config, destination, timeout)
# Do a ICMP scan, return 1 if alive, 0 if not
############################################################################## ##############################################################################
sub pandora_ping_icmp { sub pandora_ping_icmp {
my $dest = $_[0]; my $pa_config = $_[0];
my $l_timeout = $_[1]; my $dest = $_[1];
my $l_timeout = $_[2];
# temporal vars. # temporal vars.
my $result = 0; my $result = 0;
my $result2 = 0; my $result2 = 0;
my $temp;
my $p; my $p;
# Check for valid destination if ($pa_config->{'icmp_checks'} eq ""){
if (!defined($dest)) { $pa_config->{'icmp_checks'} = 1;
return 0;
}
# Some hosts don't accept ICMP with too small payload. Use 16 Bytes
{
lock $icmp_lock;
$p = Net::Ping->new("icmp", $l_timeout, 16);
$result = $p->ping($dest);
} }
# Make more than a single ping (as defined in icmp_checks
for ($temp =0; $temp < $pa_config->{'icmp_checks'}; $temp++){
# Some hosts don't accept ICMP with too small payload. Use 16 Bytes
{
lock $icmp_lock;
$p = Net::Ping->new("icmp", $l_timeout, 32);
$result = $p->ping($dest);
}
if (defined($result)){ if (defined($result)){
$p->close(); $p->close();
if ($result == 1){ if ($result == 1){
return 1; $result2 = 1;
} $temp = $pa_config->{'icmp_checks'}; # Exit for
} }
return 0; }
}
return $result2;
} }
############################################################################## ##############################################################################
# pandora_ping_latency (destination, timeout, data, result) - Do a ICMP latency check # pandora_ping_latency (destination, timeout, data, result) - Do a ICMP latency check
############################################################################## ##############################################################################
sub pandora_ping_latency { sub pandora_ping_latency {
my $dest = $_[0]; my $dest = $_[0];
my $l_timeout = $_[1]; my $l_timeout = $_[1];
my $module_data = $_[2]; my $module_data = $_[2];
my $module_result = $_[3]; my $module_result = $_[3];
my $icmp_return;
my $icmp_return; my $icmp_reply;
my $icmp_reply; my $icmp_ip;
my $icmp_ip; my $nm;
my $nm;
# Locking for use ICMP call safety # Locking for use ICMP call safety
{ {
lock $icmp_lock; lock $icmp_lock;
$nm = Net::Ping->new("icmp", $l_timeout, 16); $nm = Net::Ping->new("icmp", $l_timeout, 32);
$nm->hires(); $nm->hires();
($icmp_return, $icmp_reply, $icmp_ip) = $nm->ping ($dest,$l_timeout); ($icmp_return, $icmp_reply, $icmp_ip) = $nm->ping ($dest,$l_timeout);
} }
if ($icmp_return) { if ($icmp_return) {
$$module_data = $icmp_reply * 1000; # milliseconds $$module_data = $icmp_reply * 1000; # milliseconds
$$module_result = 0; # Successful $$module_result = 0; # Successful
} else { } else {
$$module_result = 1; # Error. $$module_result = 1; # Error.
$$module_data = 0; $$module_data = 0;
} }
$nm->close(); $nm->close();
} }
########################################################################## ##########################################################################
@ -504,66 +510,69 @@ sub exec_network_module {
my $module_result = 1; # Fail by default my $module_result = 1; # Fail by default
my $module_data = 0; my $module_data = 0;
# ICMP Modules if ((defined($ip_target)) && ($ip_target ne "")) {
# ------------
if ($id_tipo_modulo == 6){ # ICMP (Connectivity only: Boolean) # ICMP Modules
$temp = pandora_ping_icmp ($ip_target, $pa_config->{'networktimeout'}); # ------------
if ($temp == 1 ){ if ($id_tipo_modulo == 6){ # ICMP (Connectivity only: Boolean)
$module_result = 0; # Successful $temp = pandora_ping_icmp ($pa_config, $ip_target, $pa_config->{'networktimeout'});
$module_data = 1; if ($temp == 1 ){
} else { $module_result = 0; # Successful
$module_result = 0; # If cannot connect, its down. $module_data = 1;
$module_data = 0; } else {
} $module_result = 0; # If cannot connect, its down.
} elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms) $module_data = 0;
# This module only could be executed if executed as root }
if ($> == 0){ } elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms)
pandora_ping_latency ($ip_target, $pa_config->{"networktimeout"}, \$module_data, \$module_result); # This module only could be executed if executed as root
} else { if ($> == 0){
$module_result = 0; # Done but, with zero value pandora_ping_latency ($ip_target, $pa_config->{"networktimeout"}, \$module_data, \$module_result);
$module_data = 0; # This should don't happen } else {
} $module_result = 0; # Done but, with zero value
# SNMP Modules (Proc=18, inc, data, string) $module_data = 0; # This should don't happen
# ------------ }
} elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 18) || ($id_tipo_modulo == 16) || ($id_tipo_modulo == 17)) { # SNMP module # SNMP Modules (Proc=18, inc, data, string)
if ($snmp_oid ne ""){ # ------------
$temp2 = pandora_query_snmp ($pa_config, $snmp_oid, $snmp_community, $ip_target, $error); } elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 18) || ($id_tipo_modulo == 16) || ($id_tipo_modulo == 17)) { # SNMP module
} else { if ((defined($snmp_oid)) && ($snmp_oid ne "") && (defined($snmp_community)) && ($snmp_community ne "")) { # Port check
$error = 1 $temp2 = pandora_query_snmp ($pa_config, $snmp_oid, $snmp_community, $ip_target, $error);
} } else {
if ($error == 0) { # A correct SNMP Query $error = 1
$module_result = 0; }
# SNMP_DATA_PROC if ($error == 0) { # A correct SNMP Query
if ($id_tipo_modulo == 18){ #snmp_data_proc $module_result = 0;
if ($temp2 != 1){ # up state is 1, down state in SNMP is 2 .... # SNMP_DATA_PROC
$temp2 = 0; if ($id_tipo_modulo == 18){ #snmp_data_proc
} if ($temp2 != 1){ # up state is 1, down state in SNMP is 2 ....
$module_data = $temp2; $temp2 = 0;
} }
# SNMP_DATA and SNMP_DATA_INC $module_data = $temp2;
elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 16) ){ }
if ($temp2 =~ /[A-Za-z\.\,\-\/\\\(\)\[\]]/){ # SNMP_DATA and SNMP_DATA_INC
$module_result = 1; # Alphanumeric data, not numeric elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 16) ){
} else { if ($temp2 =~ /[A-Za-z\.\,\-\/\\\(\)\[\]]/){
$module_data = $temp2; # Float values are also valid $module_result = 1; # Alphanumeric data, not numeric
} } else {
} else { # String SNMP $module_data = $temp2; # Float values are also valid
$module_data = $temp2; }
} } else { # String SNMP
} else { # Failed SNMP-GET $module_data = $temp2;
$module_data = 0; }
$module_result = 1; # No data, cannot connect } else { # Failed SNMP-GET
} $module_data = 0;
# TCP Module $module_result = 1; # No data, cannot connect
# ---------- }
} elsif (($id_tipo_modulo == 8) || ($id_tipo_modulo == 9) || ($id_tipo_modulo == 10) || ($id_tipo_modulo == 11)) { # TCP Module # TCP Module
if (($tcp_port < 65536) && ($tcp_port > 0)){ # Port check # ----------
pandora_query_tcp ($pa_config, $tcp_port, $ip_target, \$module_result, \$module_data, $tcp_send, $tcp_rcv, $id_tipo_modulo); } elsif (($id_tipo_modulo == 8) || ($id_tipo_modulo == 9) || ($id_tipo_modulo == 10) || ($id_tipo_modulo == 11)) { # TCP Module
} else { if ((defined($tcp_port)) && ($tcp_port < 65536) && ($tcp_port > 0)) { # Port check
# Invalid port, get no check pandora_query_tcp ($pa_config, $tcp_port, $ip_target, \$module_result, \$module_data, $tcp_send, $tcp_rcv, $id_tipo_modulo);
$module_result = 1; } else {
} # Invalid port, get no check
} $module_result = 1;
}
}
}
# -------------------------------------------------------- # --------------------------------------------------------
# Write data section # Write data section

View File

@ -96,3 +96,5 @@ server_threshold 15
network_threads 5 network_threads 5
# icmp_checks x : defines number of pings for each icmp_proc module type. at least one of that ping should be 1 to report 1
icmp_checks 2

View File

@ -34,8 +34,8 @@ our @EXPORT = qw( pandora_help_screen
# There is no global vars, all variables (setup) passed as hash reference # There is no global vars, all variables (setup) passed as hash reference
# version: Defines actual version of Pandora Server for this module only # version: Defines actual version of Pandora Server for this module only
my $pandora_version = "1.3beta2"; my $pandora_version = "1.3beta3";
my $pandora_build="PS070827"; my $pandora_build="PS071004";
our $VERSION = $pandora_version." ".$pandora_build; our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash # Setup hash
@ -136,6 +136,7 @@ sub pandora_loadconfig {
$pa_config->{"servername"}=~ s/\s//g; # Replace ' ' chars $pa_config->{"servername"}=~ s/\s//g; # Replace ' ' chars
$pa_config->{"networkserver"}=0; $pa_config->{"networkserver"}=0;
$pa_config->{"dataserver"}=0; $pa_config->{"dataserver"}=0;
$pa_config->{"icmp_checks"}=1;
$pa_config->{"reconserver"}=0; $pa_config->{"reconserver"}=0;
$pa_config->{"servermode"}=""; $pa_config->{"servermode"}="";
$pa_config->{'snmp_logfile'}="/var/log/pandora/pandora_snmptrap.log"; $pa_config->{'snmp_logfile'}="/var/log/pandora/pandora_snmptrap.log";
@ -222,7 +223,12 @@ sub pandora_loadconfig {
} }
elsif ($parametro =~ m/^servername\s(.*)/i) { $pa_config->{'servername'}= $1; } elsif ($parametro =~ m/^servername\s(.*)/i) { $pa_config->{'servername'}= $1; }
elsif ($parametro =~ m/^checksum\s([0-9])/i) { $pa_config->{"pandora_check"} = $1; } elsif ($parametro =~ m/^checksum\s([0-9])/i) { $pa_config->{"pandora_check"} = $1; }
elsif ($parametro =~ m/^master\s([0-9])/i) { $pa_config->{"pandora_master"} = $1; } elsif ($parametro =~ m/^master\s([0-9])/i) {
$pa_config->{"pandora_master"} = $1;
}
elsif ($parametro =~ m/^icmp_checks\s([0-9])/i) {
$pa_config->{"icmp_checks"} = $1;
}
elsif ($parametro =~ m/^snmpconsole\s([0-9])/i) { elsif ($parametro =~ m/^snmpconsole\s([0-9])/i) {
$pa_config->{"snmpconsole"} = $1; $pa_config->{"snmpconsole"} = $1;
} }