mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
2013-03-26 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Core.pm, lib/PandoraFMS/Tools.pm, lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/ReconServer.pm, bin/pandora_server: Improved pandora_get_os to support custom operating systems and moved it from Tools.pm to Core.pm. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7889 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a1186ab36b
commit
5782bce170
@ -1,3 +1,12 @@
|
||||
2013-03-26 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* lib/PandoraFMS/Core.pm,
|
||||
lib/PandoraFMS/Tools.pm,
|
||||
lib/PandoraFMS/DataServer.pm,
|
||||
lib/PandoraFMS/ReconServer.pm,
|
||||
bin/pandora_server: Improved pandora_get_os to support custom operating
|
||||
systems and moved it from Tools.pm to Core.pm.
|
||||
|
||||
2013-03-25 Hirofumi Kosaka <kosaka@rworks.jp>
|
||||
|
||||
* pandora_server_installer: Fixed false recognition of RHEL6.4.
|
||||
|
@ -313,7 +313,7 @@ while (1) {
|
||||
# Update module status and fired alert counts
|
||||
my @agents = get_db_rows ($DBH, 'SELECT id_agente, nombre, update_module_count, update_alert_count FROM tagente WHERE disabled = 0 AND (update_module_count=1 OR update_alert_count=1)');
|
||||
foreach my $agent (@agents) {
|
||||
logger (\%Config, " [*] Updating module status and alert fired counts for agent " . $agent->{'nombre'}, 10);
|
||||
logger (\%Config, "Updating module status and alert fired counts for agent " . $agent->{'nombre'}, 10);
|
||||
|
||||
if ($agent->{'update_module_count'} == 1) {
|
||||
pandora_update_agent_module_count ($DBH, $agent->{'id_agente'});
|
||||
|
@ -155,6 +155,7 @@ our @EXPORT = qw(
|
||||
pandora_get_config_value
|
||||
pandora_get_module_tags
|
||||
pandora_get_module_url_tags
|
||||
pandora_get_os
|
||||
pandora_module_keep_alive
|
||||
pandora_module_keep_alive_nd
|
||||
pandora_module_unknown
|
||||
@ -1925,8 +1926,6 @@ Update agent GIS information.
|
||||
sub pandora_update_gis_data ($$$$$$$$$) {
|
||||
my ($pa_config, $dbh, $agent_id, $agent_name, $longitude, $latitude, $altitude, $position_description, $timestamp) = @_;
|
||||
|
||||
logger($pa_config, "Updating GIS data for agent $agent_name (long: $longitude lat: $latitude alt: $altitude)", 10);
|
||||
|
||||
# Check for valid longitude and latitude
|
||||
if (!defined($longitude) || $longitude !~ /[-+]?[0-9,11,12]/ ||
|
||||
!defined($latitude) || $latitude !~ /[-+]?[0-9,11,12]/) {
|
||||
@ -1937,6 +1936,8 @@ sub pandora_update_gis_data ($$$$$$$$$) {
|
||||
if (!defined($altitude) || $altitude !~ /[-+]?[0-9,11,12]/) {
|
||||
$altitude = '';
|
||||
}
|
||||
|
||||
logger($pa_config, "Updating GIS data for agent $agent_name (long: $longitude lat: $latitude alt: $altitude)", 10);
|
||||
|
||||
# Get position description
|
||||
if ((!defined($position_description))) {
|
||||
@ -3955,6 +3956,65 @@ sub pandora_update_agent_alert_count ($$) {
|
||||
') WHERE id_agente = ' . $agent_id);
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# SUB pandora_get_os (string)
|
||||
# Detect OS using a string, and return id_os
|
||||
########################################################################
|
||||
sub pandora_get_os ($$) {
|
||||
my ($dbh, $os) = @_;
|
||||
|
||||
if (! defined($os) || $os eq "") {
|
||||
# Other OS
|
||||
return 10;
|
||||
}
|
||||
|
||||
if ($os =~ m/Windows/i) {
|
||||
return 9;
|
||||
}
|
||||
if ($os =~ m/Cisco/i) {
|
||||
return 7;
|
||||
}
|
||||
if ($os =~ m/SunOS/i || $os =~ m/Solaris/i) {
|
||||
return 2;
|
||||
}
|
||||
if ($os =~ m/AIX/i) {
|
||||
return 3;
|
||||
}
|
||||
if ($os =~ m/HP\-UX/i) {
|
||||
return 5;
|
||||
}
|
||||
if ($os =~ m/Apple/i || $os =~ m/Darwin/i) {
|
||||
return 8;
|
||||
}
|
||||
if ($os =~ m/Linux/i) {
|
||||
return 1;
|
||||
}
|
||||
if ($os =~ m/Enterasys/i || $os =~ m/3com/i) {
|
||||
return 11;
|
||||
}
|
||||
if ($os =~ m/Octopods/i) {
|
||||
return 13;
|
||||
}
|
||||
if ($os =~ m/embedded/i) {
|
||||
return 14;
|
||||
}
|
||||
if ($os =~ m/android/i) {
|
||||
return 15;
|
||||
}
|
||||
if ($os =~ m/BSD/i) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
# Search for a custom OS
|
||||
my $os_id = get_db_value ($dbh, 'SELECT id_os FROM tconfig_os WHERE name LIKE ?', '%' . $os . '%');
|
||||
if (defined ($os_id)) {
|
||||
return $os_id;
|
||||
}
|
||||
|
||||
# Other OS
|
||||
return 10;
|
||||
}
|
||||
|
||||
# End of function declaration
|
||||
# End of defined Code
|
||||
|
||||
|
@ -224,7 +224,6 @@ sub process_xml_data ($$$$$) {
|
||||
if ($parent_id < 1) { # Unknown parent
|
||||
$parent_id = 0;
|
||||
}
|
||||
logger($pa_config,"Parent_agent_name: $parent_agent_name parent_id: $parent_id",10);
|
||||
}
|
||||
|
||||
# Unknown agent!
|
||||
@ -274,7 +273,7 @@ sub process_xml_data ($$$$$) {
|
||||
}
|
||||
|
||||
# Get OS, group and description
|
||||
my $os = pandora_get_os ($data->{'os_name'});
|
||||
my $os = pandora_get_os ($dbh, $data->{'os_name'});
|
||||
my $group_id = -1;
|
||||
$group_id = get_group_id ($dbh, $data->{'group'}) if (defined ($data->{'group'}));
|
||||
if ($group_id == -1) {
|
||||
|
@ -184,7 +184,7 @@ sub data_consumer ($$) {
|
||||
# Filter by OS
|
||||
my $id_os = 11; # Network by default
|
||||
if ($task->{'os_detect'} == 1){
|
||||
$id_os = guess_os ($pa_config, $addr);
|
||||
$id_os = guess_os ($pa_config, $dbh, $addr);
|
||||
next if ($task->{'id_os'} > 0 && $task->{'id_os'} != $id_os);
|
||||
}
|
||||
|
||||
@ -374,7 +374,7 @@ sub get_host_parent {
|
||||
# Detect host's OS
|
||||
my $id_os = 11;
|
||||
if ($os_detect == 1) {
|
||||
$id_os = guess_os ($pa_config, $host_addr);
|
||||
$id_os = guess_os ($pa_config, $dbh, $host_addr);
|
||||
}
|
||||
|
||||
# Create the host
|
||||
@ -405,21 +405,21 @@ sub tcp_scan ($$$) {
|
||||
# Guess OS using xprobe2.
|
||||
##########################################################################
|
||||
sub guess_os {
|
||||
my ($pa_config, $host) = @_;
|
||||
my ($pa_config, $dbh, $host) = @_;
|
||||
|
||||
# Use xprobe2 if available
|
||||
my $xprobe = $pa_config->{'xprobe2'};
|
||||
if (-e $xprobe){
|
||||
my $output = `$xprobe $host 2> /dev/null | grep 'Running OS' | head -1`;
|
||||
return 10 if ($? != 0);
|
||||
return pandora_get_os ($output);
|
||||
return pandora_get_os ($dbh, $output);
|
||||
}
|
||||
|
||||
# Use nmap by default
|
||||
my $nmap = $pa_config->{'nmap'};
|
||||
my $output = `$nmap -F -O $host 2> /dev/null | grep 'Aggressive OS guesses'`;
|
||||
return 10 if ($? != 0);
|
||||
return pandora_get_os ($output);
|
||||
return pandora_get_os ($dbh, $output);
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
|
@ -53,7 +53,6 @@ our @EXPORT = qw(
|
||||
is_numeric
|
||||
clean_blank
|
||||
pandora_sendmail
|
||||
pandora_get_os
|
||||
pandora_trash_ascii
|
||||
enterprise_hook
|
||||
enterprise_load
|
||||
@ -229,69 +228,6 @@ sub ascii_to_html($) {
|
||||
return "&#x".substr(unpack("H*", pack("N", $ascii)),6,3).";";
|
||||
}
|
||||
|
||||
|
||||
########################################################################
|
||||
# SUB pandora_get_os (string)
|
||||
# Detect OS using a string, and return id_os
|
||||
########################################################################
|
||||
|
||||
sub pandora_get_os ($) {
|
||||
my $command = $_[0];
|
||||
if (defined($command) && $command ne "") {
|
||||
if ($command =~ m/Windows/i) {
|
||||
return 9;
|
||||
}
|
||||
elsif ($command =~ m/Cisco/i) {
|
||||
return 7;
|
||||
}
|
||||
elsif ($command =~ m/SunOS/i) {
|
||||
return 2;
|
||||
}
|
||||
elsif ($command =~ m/Solaris/i) {
|
||||
return 2;
|
||||
}
|
||||
elsif ($command =~ m/AIX/i) {
|
||||
return 3;
|
||||
}
|
||||
elsif ($command =~ m/HP\-UX/i) {
|
||||
return 5;
|
||||
}
|
||||
elsif ($command =~ m/Apple/i) {
|
||||
return 8;
|
||||
}
|
||||
elsif ($command =~ m/Darwin/i){
|
||||
return 8;
|
||||
}
|
||||
elsif ($command =~ m/Linux/i) {
|
||||
return 1;
|
||||
}
|
||||
elsif ($command =~ m/Enterasys/i) {
|
||||
return 11;
|
||||
}
|
||||
elsif ($command =~ m/3com/i) {
|
||||
return 11;
|
||||
}
|
||||
elsif ($command =~ m/Octopods/i) {
|
||||
return 13;
|
||||
}
|
||||
elsif ($command =~ m/embedded/i) {
|
||||
return 14;
|
||||
}
|
||||
elsif ($command =~ m/android/i) {
|
||||
return 15;
|
||||
}
|
||||
elsif ($command =~ m/BSD/i) {
|
||||
return 4;
|
||||
}
|
||||
else {
|
||||
return 10; # Unknown / Other
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# Sub daemonize ()
|
||||
# Put program in background (for daemon mode)
|
||||
|
Loading…
x
Reference in New Issue
Block a user