Moved ReconServer to DiscoveryServer
Former-commit-id: 5e18aa75d669f6b45d3b4e2648f31473fd206091
This commit is contained in:
parent
27da41c7da
commit
ed63ef47fa
|
@ -19,7 +19,7 @@ ui_require_css_file('firts_task');
|
|||
|
||||
<div class="new_task">
|
||||
<div class="image_task">
|
||||
<?php echo html_print_image('images/firts_task/icono_grande_reconserver.png', true, ['title' => __('Recon server')]); ?>
|
||||
<?php echo html_print_image('images/firts_task/icono_grande_reconserver.png', true, ['title' => __('Discovery server')]); ?>
|
||||
</div>
|
||||
<div class="text_task">
|
||||
<h3> <?php echo __('Create Recon Task'); ?> <p id="description_task">
|
||||
|
|
|
@ -248,9 +248,9 @@ $table->rowclass[17] = 'recon_script';
|
|||
$table->data[0][0] = '<b>'.__('Task name').'</b>';
|
||||
$table->data[0][1] = html_print_input_text('name', $name, '', 25, 0, true);
|
||||
|
||||
// Recon server
|
||||
$table->data[1][0] = '<b>'.__('Recon server').ui_print_help_tip(
|
||||
__('You must select a Recon Server for the Task, otherwise the Recon Task will never run'),
|
||||
// Discovery server
|
||||
$table->data[1][0] = '<b>'.__('Discovery server').ui_print_help_tip(
|
||||
__('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'),
|
||||
true
|
||||
);
|
||||
|
||||
|
|
|
@ -402,9 +402,9 @@ class HostDevices implements Wizard
|
|||
$table->data[0][0] = '<b>'.__('Task name').'</b>';
|
||||
$table->data[0][1] = html_print_input_text('name', $name, '', 25, 0, true);
|
||||
|
||||
// Recon server.
|
||||
$table->data[1][0] = '<b>'.__('Recon server').ui_print_help_tip(
|
||||
__('You must select a Recon Server for the Task, otherwise the Recon Task will never run'),
|
||||
// Discovery server.
|
||||
$table->data[1][0] = '<b>'.__('Discovery server').ui_print_help_tip(
|
||||
__('You must select a Discovery Server for the Task, otherwise the Recon Task will never run'),
|
||||
true
|
||||
);
|
||||
|
||||
|
@ -818,8 +818,8 @@ function get_explanation_recon_script (id) {
|
|||
}
|
||||
|
||||
</script>
|
||||
<?php
|
||||
return null;
|
||||
<?php
|
||||
return null;
|
||||
/*
|
||||
Page 4, last.
|
||||
return [
|
||||
|
|
|
@ -937,57 +937,66 @@ class ConsoleSupervisor
|
|||
);
|
||||
|
||||
$time = time();
|
||||
foreach ($queue_state as $queue) {
|
||||
$key = $queue['id_server'];
|
||||
$type = $queue['server_type'];
|
||||
$new_data[$key] = $queue['queued_modules'];
|
||||
if (is_array($queue_state) === true) {
|
||||
foreach ($queue_state as $queue) {
|
||||
$key = $queue['id_server'];
|
||||
$type = $queue['server_type'];
|
||||
$new_data[$key] = $queue['queued_modules'];
|
||||
|
||||
// Compare queue increments in a not over 900 seconds.
|
||||
if (empty($previous[$key]['modules'])
|
||||
|| ($time - $previous[$key]['utime']) > 900
|
||||
) {
|
||||
$previous[$key]['modules'] = 0;
|
||||
}
|
||||
|
||||
$modules_queued = ($queue['queued_modules'] - $previous[$key]['modules']);
|
||||
|
||||
// 50 Modules queued since last check. Or more than 1500 queued.
|
||||
if ($modules_queued > $MAX_GROWN
|
||||
|| $queue['queued_modules'] > $MAX_QUEUE
|
||||
) {
|
||||
$msg = 'Queue has grown %d modules. Total %d';
|
||||
if ($modules_queued <= 0) {
|
||||
$msg = 'Queue is decreasing in %d modules. But there are %d queued.';
|
||||
$modules_queued *= -1;
|
||||
// Compare queue increments in a not over 900 seconds.
|
||||
if (empty($previous[$key]['modules'])
|
||||
|| ($time - $previous[$key]['utime']) > 900
|
||||
) {
|
||||
$previous[$key]['modules'] = 0;
|
||||
}
|
||||
|
||||
$this->notify(
|
||||
[
|
||||
'type' => 'NOTIF.SERVER.QUEUE.'.$key,
|
||||
'title' => __(
|
||||
'%s (%s) performance is being lacked.',
|
||||
servers_get_server_string_name($type),
|
||||
$queue['name']
|
||||
),
|
||||
'message' => __(
|
||||
$msg,
|
||||
$modules_queued,
|
||||
$queue['queued_modules']
|
||||
),
|
||||
'url' => ui_get_full_url(
|
||||
'index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=60'
|
||||
),
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->cleanNotifications('NOTIF.SERVER.QUEUE.'.$key);
|
||||
$modules_queued = ($queue['queued_modules'] - $previous[$key]['modules']);
|
||||
|
||||
// 50 Modules queued since last check. Or more than 1500 queued.
|
||||
if ($modules_queued > $MAX_GROWN
|
||||
|| $queue['queued_modules'] > $MAX_QUEUE
|
||||
) {
|
||||
$msg = 'Queue has grown %d modules. Total %d';
|
||||
if ($modules_queued <= 0) {
|
||||
$msg = 'Queue is decreasing in %d modules. But there are %d queued.';
|
||||
$modules_queued *= -1;
|
||||
}
|
||||
|
||||
$this->notify(
|
||||
[
|
||||
'type' => 'NOTIF.SERVER.QUEUE.'.$key,
|
||||
'title' => __(
|
||||
'%s (%s) performance is being lacked.',
|
||||
servers_get_server_string_name($type),
|
||||
$queue['name']
|
||||
),
|
||||
'message' => __(
|
||||
$msg,
|
||||
$modules_queued,
|
||||
$queue['queued_modules']
|
||||
),
|
||||
'url' => ui_get_full_url(
|
||||
'index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=60'
|
||||
),
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->cleanNotifications('NOTIF.SERVER.QUEUE.'.$key);
|
||||
}
|
||||
|
||||
$new[$key]['modules'] = $queue['queued_modules'];
|
||||
$new[$key]['utime'] = $time;
|
||||
}
|
||||
|
||||
$new[$key]['modules'] = $queue['queued_modules'];
|
||||
$new[$key]['utime'] = $time;
|
||||
}
|
||||
// Update file content.
|
||||
file_put_contents($idx_file, json_encode($new));
|
||||
} else {
|
||||
// No queue data, ignore.
|
||||
unlink($idx_file);
|
||||
|
||||
file_put_contents($idx_file, json_encode($new));
|
||||
// Clean notifications.
|
||||
$this->cleanNotifications('NOTIF.SERVER.QUEUE.%');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -366,7 +366,7 @@ define('PASSSWORD_POLICIES_EXPIRED', 2);
|
|||
define('SERVER_TYPE_DATA', 0);
|
||||
define('SERVER_TYPE_NETWORK', 1);
|
||||
define('SERVER_TYPE_SNMP', 2);
|
||||
define('SERVER_TYPE_RECON', 3);
|
||||
define('SERVER_TYPE_DISCOVERY', 3);
|
||||
define('SERVER_TYPE_PLUGIN', 4);
|
||||
define('SERVER_TYPE_PREDICTION', 5);
|
||||
define('SERVER_TYPE_WMI', 6);
|
||||
|
|
|
@ -1378,7 +1378,7 @@ function events_print_type_description($type, $return=false)
|
|||
break;
|
||||
|
||||
case 'recon_host_detected';
|
||||
$output .= __('Recon server detected a new host');
|
||||
$output .= __('Discovery server detected a new host');
|
||||
break;
|
||||
|
||||
case 'new_agent';
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
* ============================================================================
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/constants.php';
|
||||
|
||||
|
||||
/**
|
||||
* Get a server.
|
||||
|
@ -203,7 +205,7 @@ function servers_get_performance()
|
|||
case SERVER_TYPE_EXPORT:
|
||||
case SERVER_TYPE_INVENTORY:
|
||||
case SERVER_TYPE_EVENT:
|
||||
case SERVER_TYPE_RECON:
|
||||
case SERVER_TYPE_DISCOVERY:
|
||||
case SERVER_TYPE_SYSLOG:
|
||||
break;
|
||||
}
|
||||
|
@ -424,8 +426,8 @@ function servers_get_info($id_server=-1)
|
|||
$id_modulo = 0;
|
||||
break;
|
||||
|
||||
case SERVER_TYPE_RECON:
|
||||
$server['img'] = html_print_image('images/recon.png', true, ['title' => __('Recon server')]);
|
||||
case SERVER_TYPE_DISCOVERY:
|
||||
$server['img'] = html_print_image('images/recon.png', true, ['title' => __('Discovery server')]);
|
||||
$server['type'] = 'recon';
|
||||
$id_modulo = 0;
|
||||
break;
|
||||
|
@ -598,11 +600,11 @@ function servers_get_info($id_server=-1)
|
|||
$server['lag'] = 0;
|
||||
$server['module_lag'] = 0;
|
||||
}
|
||||
// Recon server
|
||||
else if ($server['server_type'] == SERVER_TYPE_RECON) {
|
||||
// Discovery server
|
||||
else if ($server['server_type'] == SERVER_TYPE_DISCOVERY) {
|
||||
$server['name'] = '<a href="index.php?sec=estado&sec2=operation/servers/recon_view&server_id='.$server['id_server'].'">'.$server['name'].'</a>';
|
||||
|
||||
// Total jobs running on this recon server
|
||||
// Total jobs running on this Discovery server
|
||||
$server['modules'] = db_get_sql(
|
||||
'SELECT COUNT(id_rt)
|
||||
FROM trecon_task
|
||||
|
@ -978,7 +980,7 @@ function servers_get_server_string_name(int $server)
|
|||
case SERVER_TYPE_EVENT:
|
||||
return __('Event server');
|
||||
|
||||
case SERVER_TYPE_RECON:
|
||||
case SERVER_TYPE_DISCOVERY:
|
||||
return __('Discovery server');
|
||||
|
||||
case SERVER_TYPE_SYSLOG:
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<p>The "ReconScripts" allows to work with more flexible capabilities. The recon scripts are developped in an individual way with completely specific targets, such as the network plugins or the agent plugins. Each ReconScript is different and has one purpose.</p>
|
||||
|
||||
<p>Its basic idea consist on "detect" things in the system it recognizes and automatically log in one monitoring (network, plugin or wmi) so in a completely customized way we could automatically log in requests in an Oracle database, new virtual host in a VmWare that is managed with VirtualCenter or we also can detect new requests in an WebLogic application Server. It is possible to do an script or application that does the task that are wanted and schedule its execution through the Recon Server.</p>
|
||||
<p>Its basic idea consist on "detect" things in the system it recognizes and automatically log in one monitoring (network, plugin or wmi) so in a completely customized way we could automatically log in requests in an Oracle database, new virtual host in a VmWare that is managed with VirtualCenter or we also can detect new requests in an WebLogic application Server. It is possible to do an script or application that does the task that are wanted and schedule its execution through the Discovery Server.</p>
|
||||
|
||||
<p>A field with importance is:</p>
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ If you choose to edit or create a new task of network recon, then you should fil
|
|||
|
||||
Name of the discovery task. It's only a descriptive value to could distinguish the task in case it would have several of them with different values of filter or template. <br><br>
|
||||
|
||||
<b>Recon server</b><br>
|
||||
<b>Discovery server</b><br>
|
||||
|
||||
Recon Server assigned to the task. If you have several Recon Servers, then you have to select here which of them you want to do the recon task. <br><br>
|
||||
Discovery Server assigned to the task. If you have several Discovery Servers, then you have to select here which of them you want to do the recon task. <br><br>
|
||||
|
||||
<b>Mode</b><br>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
検出タスクの名前です。フィルターやテンプレートとは異なり、タスクを区別しやすい説明を入れるだけです。<br><br>
|
||||
|
||||
<b>自動検出サーバ(Recon server)</b><br>
|
||||
<b>自動検出サーバ(Discovery server)</b><br>
|
||||
|
||||
タスクを割り当てる自動検出サーバです。複数の自動検出サーバがある場合は、自動検出タスクをどのサーバで実行するかを選択します。<br><br>
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ $servers = db_get_all_rows_sql('SELECT * FROM tserver WHERE server_type = 3');
|
|||
if ($servers === false) {
|
||||
$servers = [];
|
||||
ui_print_page_header(__('Recon View'), 'images/op_recon.png', false, '', false);
|
||||
ui_print_error_message(__('Recon Server is disabled'));
|
||||
ui_print_error_message(__('Discovery Server is disabled'));
|
||||
return;
|
||||
} else {
|
||||
$recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task');
|
||||
|
|
|
@ -33,7 +33,7 @@ use PandoraFMS::Core;
|
|||
use PandoraFMS::DataServer;
|
||||
use PandoraFMS::NetworkServer;
|
||||
use PandoraFMS::SNMPServer;
|
||||
use PandoraFMS::ReconServer;
|
||||
use PandoraFMS::DiscoveryServer;
|
||||
use PandoraFMS::WMIServer;
|
||||
use PandoraFMS::PluginServer;
|
||||
use PandoraFMS::PredictionServer;
|
||||
|
@ -123,7 +123,7 @@ sub pandora_startup () {
|
|||
pandora_reset_server (\%Config, $DBH);
|
||||
push (@Servers, new PandoraFMS::DataServer (\%Config, $DBH));
|
||||
push (@Servers, new PandoraFMS::NetworkServer (\%Config, $DBH));
|
||||
push (@Servers, new PandoraFMS::ReconServer (\%Config, $DBH));
|
||||
push (@Servers, new PandoraFMS::DiscoveryServer (\%Config, $DBH));
|
||||
push (@Servers, new PandoraFMS::SNMPServer (\%Config, $DBH));
|
||||
push (@Servers, new PandoraFMS::WMIServer (\%Config, $DBH));
|
||||
push (@Servers, new PandoraFMS::PluginServer (\%Config, $DBH));
|
||||
|
|
|
@ -4514,7 +4514,7 @@ sub pandora_server_statistics ($$) {
|
|||
$server->{"lag"} = 0;
|
||||
$server->{"module_lag"} = 0;
|
||||
# Recon server
|
||||
} elsif ($server->{"server_type"} == RECONSERVER) {
|
||||
} elsif ($server->{"server_type"} == DISCOVERYSERVER) {
|
||||
|
||||
# Total jobs running on this recon server
|
||||
$server->{"modules"} = get_db_value ($dbh, "SELECT COUNT(id_rt) FROM trecon_task WHERE id_recon_server = ?", $server->{"id_server"});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package PandoraFMS::ReconServer;
|
||||
package PandoraFMS::DiscoveryServer;
|
||||
##########################################################################
|
||||
# Pandora FMS Recon Server.
|
||||
# Pandora FMS Discovery Server.
|
||||
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
|
||||
##########################################################################
|
||||
# Copyright (c) 2005-2009 Artica Soluciones Tecnologicas S.L
|
||||
|
@ -57,16 +57,16 @@ use constant OS_ROUTER => 17;
|
|||
use constant OS_SWITCH => 18;
|
||||
|
||||
########################################################################################
|
||||
# Recon Server class constructor.
|
||||
# Discovery Server class constructor.
|
||||
########################################################################################
|
||||
sub new ($$$$$$) {
|
||||
my ($class, $config, $dbh) = @_;
|
||||
|
||||
return undef unless $config->{'reconserver'} == 1;
|
||||
return undef unless $config->{'reconserver'} == 1 || $config->{'discoveryserver'} == 1;
|
||||
|
||||
if (! -e $config->{'nmap'}) {
|
||||
logger ($config, ' [E] ' . $config->{'nmap'} . " needed by " . $config->{'rb_product_name'} . " Recon Server not found.", 1);
|
||||
print_message ($config, ' [E] ' . $config->{'nmap'} . " needed by " . $config->{'rb_product_name'} . " Recon Server not found.", 1);
|
||||
logger ($config, ' [E] ' . $config->{'nmap'} . " needed by " . $config->{'rb_product_name'} . " Discovery Server not found.", 1);
|
||||
print_message ($config, ' [E] ' . $config->{'nmap'} . " needed by " . $config->{'rb_product_name'} . " Discovery Server not found.", 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -78,14 +78,14 @@ sub new ($$$$$$) {
|
|||
|
||||
# Restart automatic recon tasks.
|
||||
db_do ($dbh, 'UPDATE trecon_task SET utimestamp = 0 WHERE id_recon_server = ? AND status <> -1 AND interval_sweep > 0',
|
||||
get_server_id ($dbh, $config->{'servername'}, RECONSERVER));
|
||||
get_server_id ($dbh, $config->{'servername'}, DISCOVERYSERVER));
|
||||
|
||||
# Reset (but do not restart) manual recon tasks.
|
||||
db_do ($dbh, 'UPDATE trecon_task SET status = -1 WHERE id_recon_server = ? AND status <> -1 AND interval_sweep = 0',
|
||||
get_server_id ($dbh, $config->{'servername'}, RECONSERVER));
|
||||
get_server_id ($dbh, $config->{'servername'}, DISCOVERYSERVER));
|
||||
|
||||
# Call the constructor of the parent class
|
||||
my $self = $class->SUPER::new($config, RECONSERVER, \&PandoraFMS::ReconServer::data_producer, \&PandoraFMS::ReconServer::data_consumer, $dbh);
|
||||
my $self = $class->SUPER::new($config, DISCOVERYSERVER, \&PandoraFMS::DiscoveryServer::data_producer, \&PandoraFMS::DiscoveryServer::data_consumer, $dbh);
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
|
@ -98,7 +98,7 @@ sub run ($) {
|
|||
my $self = shift;
|
||||
my $pa_config = $self->getConfig ();
|
||||
|
||||
print_message ($pa_config, " [*] Starting " . $pa_config->{'rb_product_name'} . " Recon Server.", 1);
|
||||
print_message ($pa_config, " [*] Starting " . $pa_config->{'rb_product_name'} . " Discovery Server.", 1);
|
||||
$self->setNumThreads ($pa_config->{'recon_threads'});
|
||||
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
|
||||
}
|
||||
|
@ -121,9 +121,10 @@ sub data_producer ($) {
|
|||
# Status -1 means "done".
|
||||
|
||||
my @rows = get_db_rows ($dbh, 'SELECT * FROM trecon_task
|
||||
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);
|
||||
WHERE id_recon_server = ?
|
||||
AND disabled = 0
|
||||
AND ((utimestamp = 0 AND interval_sweep != 0 OR status = 1)
|
||||
OR (status = -1 AND interval_sweep > 0 AND (utimestamp + interval_sweep) < UNIX_TIMESTAMP()))', $server_id);
|
||||
foreach my $row (@rows) {
|
||||
|
||||
# Update task status
|
||||
|
@ -154,12 +155,13 @@ sub data_consumer ($$) {
|
|||
logger($pa_config, 'Starting recon task for net ' . $task->{'subnet'} . '.', 10);
|
||||
}
|
||||
|
||||
# Call nmap
|
||||
my $nmap_args = '-nsP -PE --max-retries '.$pa_config->{'icmp_checks'}.' --host-timeout '.$pa_config->{'networktimeout'}.'s -T'.$pa_config->{'recon_timing_template'};
|
||||
my $np = new PandoraFMS::NmapParser;
|
||||
eval {
|
||||
my @subnets = split(/,/, safe_output($task->{'subnet'}));
|
||||
my @communities = split(/,/, safe_output($task->{'snmp_community'}));
|
||||
my @auth_strings = ();
|
||||
if(defined($task->{'auth_strings'})) {
|
||||
@auth_strings = split(/,/, safe_output($task->{'auth_strings'}));
|
||||
}
|
||||
|
||||
my $recon = new PandoraFMS::Recon::Base(
|
||||
communities => \@communities,
|
||||
|
@ -186,6 +188,8 @@ sub data_consumer ($$) {
|
|||
subnets => \@subnets,
|
||||
task_id => $task->{'id_rt'},
|
||||
vlan_cache_enabled => $task->{'vlan_enabled'},
|
||||
wmi_enabled => $task->{'wmi_enabled'},
|
||||
auth_strings_array => \@auth_strings,
|
||||
%{$pa_config}
|
||||
);
|
||||
|
||||
|
@ -748,6 +752,35 @@ sub PandoraFMS::Recon::Base::set_parent($$$) {
|
|||
db_do($self->{'dbh'}, 'UPDATE tagente SET id_parent=? WHERE id_agente=?', $agent_parent->{'id_agente'}, $agent->{'id_agente'});
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Create a WMI module for the given agent.
|
||||
##########################################################################
|
||||
sub PandoraFMS::Recon::Base::wmi_module {
|
||||
my ($self, $agent_id, $target, $wmi_query, $wmi_auth, $column,
|
||||
$module_name, $module_description, $module_type, $unit) = @_;
|
||||
|
||||
# Check whether the module already exists.
|
||||
my $module_id = get_agent_module_id($self->{'dbh'}, $module_name, $agent_id);
|
||||
return if ($module_id > 0);
|
||||
|
||||
my ($user, $pass) = ($wmi_auth ne '') ? split('%', $wmi_auth) : (undef, undef);
|
||||
my %module = (
|
||||
'descripcion' => safe_input($module_description),
|
||||
'id_agente' => $agent_id,
|
||||
'id_modulo' => 6,
|
||||
'id_tipo_modulo' => get_module_id($self->{'dbh'}, $module_type),
|
||||
'ip_target' => $target,
|
||||
'nombre' => safe_input($module_name),
|
||||
'plugin_pass' => defined($pass) ? $pass : '',
|
||||
'plugin_user' => defined($user) ? $user : '',
|
||||
'snmp_oid' => $wmi_query,
|
||||
'tcp_port' => $column,
|
||||
'unit' => defined($unit) ? $unit : ''
|
||||
);
|
||||
|
||||
pandora_create_module_from_hash($self->{'pa_config'}, \%module, $self->{'dbh'});
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Update recon task status.
|
||||
##########################################################################
|
|
@ -123,6 +123,12 @@ sub new {
|
|||
# Globally enable/disable SNMP scans.
|
||||
snmp_enabled => 1,
|
||||
|
||||
# Globally enable/disable WMI scans.
|
||||
wmi_enabled => 0,
|
||||
auth_strings_array => [],
|
||||
wmi_timeout => 3,
|
||||
timeout_cmd => '',
|
||||
|
||||
# Switch to switch connections. Used to properly connect hosts
|
||||
# that are connected to a switch wich is in turn connected to another switch,
|
||||
# since the hosts will show up in the latter's switch AFT too.
|
||||
|
@ -217,6 +223,19 @@ sub new {
|
|||
}
|
||||
}
|
||||
|
||||
# Prepare auth array.
|
||||
# WMI could be launched with '-N' - no pass - argument.
|
||||
if ($self->{'wmi_enabled'} == 1){
|
||||
if (defined($self->{'auth_strings_str'})) {
|
||||
@{$self->{'auth_strings_array'}} = split(',', $self->{'auth_strings_str'});
|
||||
}
|
||||
|
||||
# Timeout available only in linux environments.
|
||||
if ($^O =~ /lin/i && defined($self->{'plugin_exec'}) && defined($self->{'wmi_timeout'})) {
|
||||
$self->{'timeout_cmd'} = $self->{'plugin_exec'}.' '.$self->{'wmi_timeout'}.' ';
|
||||
}
|
||||
}
|
||||
|
||||
# Remove all snmp related values if disabled
|
||||
if (!$self->{'snmp_enabled'}) {
|
||||
$self->{'communities'} = [];
|
||||
|
@ -1312,6 +1331,9 @@ sub scan_subnet($) {
|
|||
$progress += $step;
|
||||
|
||||
$self->snmp_discovery($host);
|
||||
|
||||
# Add wmi scan if enabled.
|
||||
$self->wmi_scan($host) if ($self->{'wmi_enabled'} == 1);
|
||||
}
|
||||
}
|
||||
# ping scan.
|
||||
|
@ -1330,6 +1352,9 @@ sub scan_subnet($) {
|
|||
next if ($self->ping($host) == 0);
|
||||
|
||||
$self->snmp_discovery($host);
|
||||
|
||||
# Add wmi scan if enabled.
|
||||
$self->wmi_scan($host) if ($self->{'wmi_enabled'} == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1579,6 +1604,168 @@ sub traceroute_connectivity($$) {
|
|||
}
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Returns the credentials with which the host responds to WMI queries or
|
||||
# undef if it does not respond to WMI.
|
||||
##########################################################################
|
||||
sub responds_to_wmi {
|
||||
my ($self, $target) = @_;
|
||||
|
||||
foreach my $auth (@{$self->{'auth_strings_array'}}) {
|
||||
my @output;
|
||||
if ($auth ne '') {
|
||||
@output = `$self->{'timeout_cmd'}$self->{'wmi_client'} -U $auth //$target "SELECT * FROM Win32_ComputerSystem" 2>&1`;
|
||||
} else {
|
||||
@output = `$self->{'timeout_cmd'}$self->{'wmi_client'} -N //$target "SELECT * FROM Win32_ComputerSystem" 2>&1`;
|
||||
}
|
||||
|
||||
foreach my $line (@output) {
|
||||
chomp($line);
|
||||
return $auth if ($line =~ m/^CLASS: Win32_ComputerSystem$/);
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Add wmi modules to the given host.
|
||||
##########################################################################
|
||||
sub wmi_scan {
|
||||
my ($self, $target) = @_;
|
||||
|
||||
$self->call('message', "[".$target."] Checking WMI.", 5);
|
||||
|
||||
my $auth = $self->responds_to_wmi($target);
|
||||
return unless defined($auth);
|
||||
|
||||
$self->call('message', "[".$target."] WMI available.", 10);
|
||||
# Create the agent if it does not exist.
|
||||
my $agent_id = $self->call('create_agent', $target);
|
||||
next unless defined($agent_id);
|
||||
|
||||
# CPU.
|
||||
my @cpus = $self->wmi_get_value_array($target, $auth, 'SELECT DeviceId FROM Win32_Processor', 0);
|
||||
foreach my $cpu (@cpus) {
|
||||
$self->call(
|
||||
'wmi_module',
|
||||
(
|
||||
$agent_id,
|
||||
$target,
|
||||
"SELECT LoadPercentage FROM Win32_Processor WHERE DeviceId='$cpu'",
|
||||
$auth,
|
||||
1,
|
||||
"CPU Load $cpu",
|
||||
"Load for $cpu (%)",
|
||||
'generic_data'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
# Memory.
|
||||
my $mem = $self->wmi_get_value($target, $auth, 'SELECT FreePhysicalMemory FROM Win32_OperatingSystem', 0);
|
||||
if (defined($mem)) {
|
||||
$self->call('wmi_module',
|
||||
(
|
||||
$agent_id,
|
||||
$target,
|
||||
"SELECT FreePhysicalMemory, TotalVisibleMemorySize FROM Win32_OperatingSystem",
|
||||
$auth,
|
||||
0,
|
||||
'FreeMemory',
|
||||
'Free memory',
|
||||
'generic_data',
|
||||
'KB'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
# Disk.
|
||||
my @units = $self->wmi_get_value_array($target, $auth, 'SELECT DeviceID FROM Win32_LogicalDisk', 0);
|
||||
foreach my $unit (@units) {
|
||||
$self->call(
|
||||
'wmi_module',
|
||||
(
|
||||
$agent_id,
|
||||
$target,
|
||||
"SELECT FreeSpace FROM Win32_LogicalDisk WHERE DeviceID='$unit'",
|
||||
$auth,
|
||||
1,
|
||||
"FreeDisk $unit",
|
||||
'Available disk space in kilobytes',
|
||||
'generic_data',
|
||||
'KB'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Extra: WMI imported methods. DO NOT EXPORT TO AVOID DOUBLE DEF.
|
||||
##########################################################################
|
||||
|
||||
##########################################################################
|
||||
# Performs a wmi get requests and returns the response as an array.
|
||||
##########################################################################
|
||||
sub wmi_get {
|
||||
my ($self, $target, $auth, $query) = @_;
|
||||
|
||||
my @output;
|
||||
if (defined($auth) && $auth ne '') {
|
||||
@output = `$self->{'timeout_cmd'}"$self->{'wmi_client'}" -U $auth //$target "$query" 2>&1`;
|
||||
}else {
|
||||
@output = `$self->{'timeout_cmd'}"$self->{'wmi_client'}" -N //$target "$query" 2>&1`;
|
||||
}
|
||||
|
||||
# Something went wrong.
|
||||
return () if ($? != 0);
|
||||
|
||||
return @output;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Performs a WMI request and returns the requested column of the first row.
|
||||
# Returns undef on error.
|
||||
##########################################################################
|
||||
sub wmi_get_value {
|
||||
my ($self, $target, $auth, $query, $column) = @_;
|
||||
my @result;
|
||||
|
||||
my @output = $self->wmi_get($target, $auth, $query);
|
||||
return undef unless defined($output[2]);
|
||||
|
||||
my $line = $output[2];
|
||||
chomp($line);
|
||||
my @columns = split(/\|/, $line);
|
||||
return undef unless defined($columns[$column]);
|
||||
|
||||
return $columns[$column];
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Performs a WMI request and returns row values for the requested column
|
||||
# in an array.
|
||||
##########################################################################
|
||||
sub wmi_get_value_array {
|
||||
my ($self, $target, $auth, $query, $column) = @_;
|
||||
my @result;
|
||||
|
||||
my @output = $self->wmi_get($target, $auth, $query);
|
||||
foreach (my $i = 2; defined($output[$i]); $i++) {
|
||||
my $line = $output[$i];
|
||||
chomp($line);
|
||||
my @columns = split(/\|/, $line);
|
||||
next unless defined($columns[$column]);
|
||||
push(@result, $columns[$column]);
|
||||
}
|
||||
|
||||
return @result;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# END: WMI imported methods.
|
||||
##########################################################################
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ our @EXPORT = qw(
|
|||
DATASERVER
|
||||
NETWORKSERVER
|
||||
SNMPCONSOLE
|
||||
RECONSERVER
|
||||
DISCOVERYSERVER
|
||||
PLUGINSERVER
|
||||
PREDICTIONSERVER
|
||||
WMISERVER
|
||||
|
@ -134,7 +134,7 @@ our @EXPORT = qw(
|
|||
use constant DATASERVER => 0;
|
||||
use constant NETWORKSERVER => 1;
|
||||
use constant SNMPCONSOLE => 2;
|
||||
use constant RECONSERVER => 3;
|
||||
use constant DISCOVERYSERVER => 3;
|
||||
use constant PLUGINSERVER => 4;
|
||||
use constant PREDICTIONSERVER => 5;
|
||||
use constant WMISERVER => 6;
|
||||
|
|
Loading…
Reference in New Issue