mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 00:34:46 +02:00
2014-05-22 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/NmapParser.pm, lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Tools.pm, lib/PandoraFMS/Traceroute.pm, lib/PandoraFMS/WMIServer.pm: Fixes for win32. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9984 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
9af35a531f
commit
012634abca
@ -1,3 +1,13 @@
|
|||||||
|
2014-05-22 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* lib/PandoraFMS/NetworkServer.pm,
|
||||||
|
lib/PandoraFMS/NmapParser.pm,
|
||||||
|
lib/PandoraFMS/ReconServer.pm,
|
||||||
|
lib/PandoraFMS/SNMPServer.pm,
|
||||||
|
lib/PandoraFMS/Tools.pm,
|
||||||
|
lib/PandoraFMS/Traceroute.pm,
|
||||||
|
lib/PandoraFMS/WMIServer.pm: Fixes for win32.
|
||||||
|
|
||||||
2014-05-21 Junichi Satoh <junichi@rworks.jp>
|
2014-05-21 Junichi Satoh <junichi@rworks.jp>
|
||||||
|
|
||||||
* lib/PandoraFMS/Core.pm: Improved 'FF threshold' to be able to define
|
* lib/PandoraFMS/Core.pm: Improved 'FF threshold' to be able to define
|
||||||
|
@ -296,18 +296,18 @@ sub pandora_snmp_get_command ($$$$$$$$$$$) {
|
|||||||
# the call is the same than in linux
|
# the call is the same than in linux
|
||||||
if (($OSNAME eq "MSWin32") || ($OSNAME eq "MSWin32-x64") || ($OSNAME eq "cygwin")){
|
if (($OSNAME eq "MSWin32") || ($OSNAME eq "MSWin32-x64") || ($OSNAME eq "cygwin")){
|
||||||
if ($snmp_version ne "3"){
|
if ($snmp_version ne "3"){
|
||||||
$output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c $snmp_community $snmp_target $snmp_oid 2> NUL`;
|
$output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c $snmp_community $snmp_target $snmp_oid 2>$DEVNULL`;
|
||||||
} else {
|
} else {
|
||||||
$output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -l $snmp3_security_level $snmp3_extra $snmp_target $snmp_oid 2> NUL`;
|
$output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -l $snmp3_security_level $snmp3_extra $snmp_target $snmp_oid 2>$DEVNULL`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# by default LINUX/FreeBSD/Solaris calls
|
# by default LINUX/FreeBSD/Solaris calls
|
||||||
else {
|
else {
|
||||||
if ($snmp_version ne "3"){
|
if ($snmp_version ne "3"){
|
||||||
$output = `$snmpget_cmd -M+"$mib_dir" -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c '$snmp_community' $snmp_target $snmp_oid 2>/dev/null`;
|
$output = `$snmpget_cmd -M+"$mib_dir" -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c '$snmp_community' $snmp_target $snmp_oid 2>$DEVNULL`;
|
||||||
} else {
|
} else {
|
||||||
$output = `$snmpget_cmd -M+"$mib_dir" -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -l $snmp3_security_level $snmp3_extra $snmp_target $snmp_oid 2>/dev/null`;
|
$output = `$snmpget_cmd -M+"$mib_dir" -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -l $snmp3_security_level $snmp3_extra $snmp_target $snmp_oid 2>$DEVNULL`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ use vars qw($VERSION %D);
|
|||||||
|
|
||||||
$VERSION = 1.30;
|
$VERSION = 1.30;
|
||||||
|
|
||||||
|
#/dev/null
|
||||||
|
my $DEVNULL = ($^O eq 'MSWin32') ? '/Nul' : '/dev/null';
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
|
|
||||||
@ -143,16 +145,16 @@ sub parsescan {
|
|||||||
#if output file is defined, point it to a localfile then call parsefile instead.
|
#if output file is defined, point it to a localfile then call parsefile instead.
|
||||||
if ( defined( $self->{cache_file} ) ) {
|
if ( defined( $self->{cache_file} ) ) {
|
||||||
$cmd =
|
$cmd =
|
||||||
"$nmap $args -v -v -v -oX "
|
"\"$nmap\" $args -v -v -v -oX "
|
||||||
. $self->{cache_file} . " "
|
. $self->{cache_file} . " "
|
||||||
. ( join ' ', @ips );
|
. ( join ' ', @ips );
|
||||||
`$cmd 2> /dev/null`; #remove output from STDOUT
|
`$cmd 2>$DEVNULL`; #remove output from STDOUT
|
||||||
$self->parsefile( $self->{cache_file} );
|
$self->parsefile( $self->{cache_file} );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$cmd = "$nmap $args -v -v -v -oX - " . ( join ' ', @ips );
|
$cmd = "\"$nmap\" $args -v -v -v -oX - " . ( join ' ', @ips );
|
||||||
open $FH,
|
open $FH,
|
||||||
"$cmd 2>/dev/null |" || die "[Nmap-Parser] Could not perform nmap scan - $!";
|
"$cmd 2>$DEVNULL |" || die "[Nmap-Parser] Could not perform nmap scan - $!";
|
||||||
$self->parse($FH);
|
$self->parse($FH);
|
||||||
close $FH;
|
close $FH;
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ sub tcp_scan ($$$) {
|
|||||||
my ($pa_config, $host, $portlist) = @_;
|
my ($pa_config, $host, $portlist) = @_;
|
||||||
|
|
||||||
my $nmap = $pa_config->{'nmap'};
|
my $nmap = $pa_config->{'nmap'};
|
||||||
my $output = `$nmap -p$portlist $host | grep open | wc -l`;
|
my $output = `"$nmap" -p$portlist $host | grep open | wc -l`;
|
||||||
return 0 if ($? != 0);
|
return 0 if ($? != 0);
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
@ -422,14 +422,14 @@ sub guess_os {
|
|||||||
# Use xprobe2 if available
|
# Use xprobe2 if available
|
||||||
my $xprobe = $pa_config->{'xprobe2'};
|
my $xprobe = $pa_config->{'xprobe2'};
|
||||||
if (-e $xprobe){
|
if (-e $xprobe){
|
||||||
my $output = `$xprobe $host 2> /dev/null | grep 'Running OS' | head -1`;
|
my $output = `$xprobe $host 2>$DEVNULL | grep 'Running OS' | head -1`;
|
||||||
return 10 if ($? != 0);
|
return 10 if ($? != 0);
|
||||||
return pandora_get_os ($dbh, $output);
|
return pandora_get_os ($dbh, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use nmap by default
|
# Use nmap by default
|
||||||
my $nmap = $pa_config->{'nmap'};
|
my $nmap = $pa_config->{'nmap'};
|
||||||
my $output = `$nmap -F -O $host 2> /dev/null | grep 'Aggressive OS guesses'`;
|
my $output = `"$nmap" -F -O $host 2>$DEVNULL | grep 'Aggressive OS guesses'`;
|
||||||
return 10 if ($? != 0);
|
return 10 if ($? != 0);
|
||||||
return pandora_get_os ($dbh, $output);
|
return pandora_get_os ($dbh, $output);
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ sub stop () {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if ($self->{'snmp_trapd'} ne 'manual') {
|
if ($self->{'snmp_trapd'} ne 'manual') {
|
||||||
system ('kill -9 `cat /var/run/pandora_snmptrapd.pid 2> /dev/null`');
|
system ("kill -9 `cat /var/run/pandora_snmptrapd.pid 2>$DEVNULL`");
|
||||||
unlink ('/var/run/pandora_snmptrapd.pid');
|
unlink ('/var/run/pandora_snmptrapd.pid');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ sub start_snmptrapd ($) {
|
|||||||
$snmptrapd_args .= ' --format1=SNMPv1[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]' . $address_format . '[**]%N[**]%w[**]%W[**]%q[**]%v\\\n';
|
$snmptrapd_args .= ' --format1=SNMPv1[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]' . $address_format . '[**]%N[**]%w[**]%W[**]%q[**]%v\\\n';
|
||||||
$snmptrapd_args .= ' --format2=SNMPv2[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%b[**]%v\\\n';
|
$snmptrapd_args .= ' --format2=SNMPv2[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%b[**]%v\\\n';
|
||||||
|
|
||||||
if (system ($config->{'snmp_trapd'} . $snmptrapd_args . ' >/dev/null 2>&1') != 0) {
|
if (system ($config->{'snmp_trapd'} . $snmptrapd_args . " >$DEVNULL 2>&1") != 0) {
|
||||||
logger ($config, " [E] Could not start snmptrapd.", 1);
|
logger ($config, " [E] Could not start snmptrapd.", 1);
|
||||||
print_message ($config, " [E] Could not start snmptrapd.", 1);
|
print_message ($config, " [E] Could not start snmptrapd.", 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -41,7 +41,8 @@ require Exporter;
|
|||||||
our @ISA = ("Exporter");
|
our @ISA = ("Exporter");
|
||||||
our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
|
our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
|
||||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||||
our @EXPORT = qw(
|
our @EXPORT = qw(
|
||||||
|
$DEVNULL
|
||||||
cron_get_closest_in_range
|
cron_get_closest_in_range
|
||||||
cron_next_execution
|
cron_next_execution
|
||||||
cron_next_execution_date
|
cron_next_execution_date
|
||||||
@ -75,6 +76,9 @@ our @EXPORT = qw(
|
|||||||
valid_regex
|
valid_regex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# /dev/null
|
||||||
|
our $DEVNULL = ($^O eq 'MSWin32') ? '/Nul' : '/dev/null';
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
## SUB pandora_trash_ascii
|
## SUB pandora_trash_ascii
|
||||||
# Generate random ascii strings with variable lenght
|
# Generate random ascii strings with variable lenght
|
||||||
@ -250,9 +254,9 @@ sub ascii_to_html($) {
|
|||||||
|
|
||||||
sub pandora_daemonize {
|
sub pandora_daemonize {
|
||||||
my $pa_config = $_[0];
|
my $pa_config = $_[0];
|
||||||
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
|
open STDIN, '$DEVNULL' or die "Can't read $DEVNULL: $!";
|
||||||
open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
|
open STDOUT, '>>$DEVNULL' or die "Can't write to $DEVNULL: $!";
|
||||||
open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
|
open STDERR, '>>$DEVNULL' or die "Can't write to $DEVNULL: $!";
|
||||||
chdir '/tmp' or die "Can't chdir to /tmp: $!";
|
chdir '/tmp' or die "Can't chdir to /tmp: $!";
|
||||||
defined(my $pid = fork) or die "Can't fork: $!";
|
defined(my $pid = fork) or die "Can't fork: $!";
|
||||||
exit if $pid;
|
exit if $pid;
|
||||||
@ -438,11 +442,12 @@ sub limpia_cadena {
|
|||||||
}
|
}
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# clean_blank (string) - Purge a string for any blank spaces in it
|
# clean_blank (string) - Remove leading and trailing blanks
|
||||||
########################################################################
|
########################################################################
|
||||||
sub clean_blank {
|
sub clean_blank {
|
||||||
my $input = $_[0];
|
my $input = $_[0];
|
||||||
$input =~ s/\s//g;
|
$input =~ s/^\s+//g;
|
||||||
|
$input =~ s/\s+$//g;
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,7 +808,7 @@ 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
|
||||||
`$ping_command -s -n $host 56 $retries >/dev/null 2>&1`;
|
`$ping_command -s -n $host 56 $retries >$DEVNULL 2>&1`;
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -821,7 +826,7 @@ 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
|
||||||
`$ping_command -q -n -c $retries $host >/dev/null 2>&1`;
|
`$ping_command -q -n -c $retries $host >$DEVNULL 2>&1`;
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -839,7 +844,7 @@ sub pandora_ping ($$$$) {
|
|||||||
# 'networktimeout' is not used by ping6 on NetBSD.
|
# 'networktimeout' is not used by ping6 on NetBSD.
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
`$ping_command -q -n -c $retries $host >/dev/null 2>&1`;
|
`$ping_command -q -n -c $retries $host >$DEVNULL 2>&1`;
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -856,7 +861,7 @@ sub pandora_ping ($$$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
`$ping_command -q -W $timeout -n -c $retries $host >/dev/null 2>&1`;
|
`$ping_command -q -W $timeout -n -c $retries $host >$DEVNULL 2>&1`;
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -902,7 +907,7 @@ sub pandora_ping_latency ($$$$) {
|
|||||||
my $ms_timeout = $timeout * 1000;
|
my $ms_timeout = $timeout * 1000;
|
||||||
$output = `ping -n $retries -w $ms_timeout $host`;
|
$output = `ping -n $retries -w $ms_timeout $host`;
|
||||||
|
|
||||||
if ($output =~ m/\=\s([0-9]*)[a-z][a-z]\r/){
|
if ($output =~ m/\=\s([0-9]+)ms$/){
|
||||||
return $1;
|
return $1;
|
||||||
} else {
|
} else {
|
||||||
return undef;
|
return undef;
|
||||||
@ -921,7 +926,7 @@ sub pandora_ping_latency ($$$$) {
|
|||||||
# 'networktimeout' is not used by ping on Solaris.
|
# 'networktimeout' is not used by ping on Solaris.
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
my @output = `$ping_command -s -n $host 56 $retries 2>/dev/null`;
|
my @output = `$ping_command -s -n $host 56 $retries 2>$DEVNULL`;
|
||||||
|
|
||||||
# Something went wrong
|
# Something went wrong
|
||||||
return undef if ($? != 0);
|
return undef if ($? != 0);
|
||||||
@ -945,7 +950,7 @@ sub pandora_ping_latency ($$$$) {
|
|||||||
# 'networktimeout' is not used on FreeBSD.
|
# 'networktimeout' is not used on FreeBSD.
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
my @output = `$ping_command -q -n -c $retries $host 2>/dev/null`;
|
my @output = `$ping_command -q -n -c $retries $host 2>$DEVNULL`;
|
||||||
|
|
||||||
# Something went wrong
|
# Something went wrong
|
||||||
return undef if ($? != 0);
|
return undef if ($? != 0);
|
||||||
@ -969,7 +974,7 @@ sub pandora_ping_latency ($$$$) {
|
|||||||
# 'networktimeout' is not used on NetBSD.
|
# 'networktimeout' is not used on NetBSD.
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
my @output = `$ping_command -q -n -c $retries $host >/dev/null 2>&1`;
|
my @output = `$ping_command -q -n -c $retries $host >$DEVNULL 2>&1`;
|
||||||
|
|
||||||
# Something went wrong
|
# Something went wrong
|
||||||
return undef in ($? != 0);
|
return undef in ($? != 0);
|
||||||
@ -990,7 +995,7 @@ sub pandora_ping_latency ($$$$) {
|
|||||||
|
|
||||||
|
|
||||||
# Ping the host
|
# Ping the host
|
||||||
my @output = `$ping_command -q -W $timeout -n -c $retries $host 2>/dev/null`;
|
my @output = `$ping_command -q -W $timeout -n -c $retries $host 2>$DEVNULL`;
|
||||||
|
|
||||||
# Something went wrong
|
# Something went wrong
|
||||||
return undef if ($? != 0);
|
return undef if ($? != 0);
|
||||||
@ -1050,7 +1055,7 @@ sub translate_obj ($$$) {
|
|||||||
my $mib_dir = $pa_config->{'attachment_dir'} . '/mibs';
|
my $mib_dir = $pa_config->{'attachment_dir'} . '/mibs';
|
||||||
|
|
||||||
# Translate!
|
# Translate!
|
||||||
my $oid = `snmptranslate -On -mALL -M+"$mib_dir" $obj 2>/dev/null`;
|
my $oid = `snmptranslate -On -mALL -M+"$mib_dir" $obj 2>$DEVNULL`;
|
||||||
|
|
||||||
if ($? != 0) {
|
if ($? != 0) {
|
||||||
return undef;
|
return undef;
|
||||||
|
@ -419,7 +419,11 @@ sub _make_pipe ($) {
|
|||||||
# XXX we probably shouldn't throw stderr away.
|
# XXX we probably shouldn't throw stderr away.
|
||||||
# XXX we probably shouldn't use named filehandles.
|
# XXX we probably shouldn't use named filehandles.
|
||||||
open(SAVESTDERR, ">&STDERR");
|
open(SAVESTDERR, ">&STDERR");
|
||||||
open(STDERR, ">/dev/null");
|
if ($^O eq 'MSWin32') {
|
||||||
|
open(STDERR, ">/Nul");
|
||||||
|
} else {
|
||||||
|
open(STDERR, ">/dev/null");
|
||||||
|
}
|
||||||
|
|
||||||
my $pipe = new IO::Pipe;
|
my $pipe = new IO::Pipe;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ sub new ($$;$) {
|
|||||||
return undef unless $config->{'wmiserver'} == 1;
|
return undef unless $config->{'wmiserver'} == 1;
|
||||||
|
|
||||||
# Check for a WMI client
|
# Check for a WMI client
|
||||||
if (system ($config->{'wmi_client'} . ' > /dev/null 2>&1') >> 8 != 1) {
|
if (system ($config->{'wmi_client'} . " >$DEVNULL 2>&1") >> 8 != 1) {
|
||||||
logger ($config, ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.", 1);
|
logger ($config, ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.", 1);
|
||||||
print_message ($config, ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.", 1);
|
print_message ($config, ' [E] ' . $config->{'wmi_client'} . " not found. Pandora FMS WMI Server needs a DCOM/WMI client.", 1);
|
||||||
return undef;
|
return undef;
|
||||||
@ -169,7 +169,7 @@ sub data_consumer ($$) {
|
|||||||
logger ($pa_config, "Executing AM # $module_id WMI command '$wmi_command'", 9);
|
logger ($pa_config, "Executing AM # $module_id WMI command '$wmi_command'", 9);
|
||||||
|
|
||||||
# Execute command
|
# Execute command
|
||||||
my $module_data = `$wmi_command 2>/dev/null`;
|
my $module_data = `$wmi_command 2>$DEVNULL`;
|
||||||
if ($? ne 0 || ! defined ($module_data)) {
|
if ($? ne 0 || ! defined ($module_data)) {
|
||||||
pandora_update_module_on_error ($pa_config, $module, $dbh);
|
pandora_update_module_on_error ($pa_config, $module, $dbh);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user