Merge remote-tracking branch 'remotes/origin/ent-3545-8250-7558-7882-monitorizar-servicios-de-azure' into ent-2441-despliegue-de-agentes-desde-pandora

This commit is contained in:
fbsanchez 2019-07-10 22:05:02 +02:00
commit 58465090b2
9 changed files with 112 additions and 106 deletions

View File

@ -534,8 +534,8 @@ echo '</div>';
$('#div-extra_1').hide();
$('#div-extra_2').hide();
} else if ($('#product :selected').val() == "AZURE") {
$('#div-username label').text('<?php echo __('Account ID'); ?>');
$('#div-password label').text('<?php echo __('Password'); ?>');
$('#div-username label').text('<?php echo __('Client ID'); ?>');
$('#div-password label').text('<?php echo __('Application secret'); ?>');
$('#div-extra_1 label').text('<?php echo __('Tenant or domain name'); ?>');
$('#div-extra_2 label').text('<?php echo __('Subscription id'); ?>');
$('#div-extra_1').show();

View File

@ -501,41 +501,60 @@ class DiscoveryTaskList extends Wizard
$data[5] = __('Pending');
}
if ($task['id_recon_script'] == 0) {
// Internal discovery task.
switch ($task['type']) {
case DISCOVERY_CLOUD_AWS_RDS:
// Discovery Applications MySQL.
$data[6] = html_print_image(
'images/network.png',
true,
['title' => __('Discovery Cloud RDS')]
).'&nbsp;&nbsp;';
$data[6] .= __('Discovery.Cloud.Aws.RDS');
break;
switch ($task['type']) {
case DISCOVERY_CLOUD_AZURE_COMPUTE:
// Discovery Applications MySQL.
$data[6] = html_print_image(
'images/plugin.png',
true,
['title' => __('Discovery Cloud Azure Compute')]
).'&nbsp;&nbsp;';
$data[6] .= __('Cloud.Azure.Compute');
break;
case DISCOVERY_APP_MYSQL:
// Discovery Applications MySQL.
$data[6] = html_print_image(
'images/network.png',
true,
['title' => __('Discovery Applications MySQL')]
).'&nbsp;&nbsp;';
$data[6] .= __('Discovery.App.MySQL');
break;
case DISCOVERY_CLOUD_AWS_EC2:
// Discovery Applications MySQL.
$data[6] = html_print_image(
'images/plugin.png',
true,
['title' => __('Discovery Cloud AWS EC2')]
).'&nbsp;&nbsp;';
$data[6] .= __('Cloud.AWS.EC2');
break;
case DISCOVERY_APP_ORACLE:
// Discovery Applications Oracle.
$data[6] = html_print_image(
'images/network.png',
true,
['title' => __('Discovery Applications Oracle')]
).'&nbsp;&nbsp;';
$data[6] .= __('Discovery.App.Oracle');
break;
case DISCOVERY_CLOUD_AWS_RDS:
// Discovery Cloud RDS.
$data[6] = html_print_image(
'images/network.png',
true,
['title' => __('Discovery Cloud RDS')]
).'&nbsp;&nbsp;';
$data[6] .= __('Discovery.Cloud.Aws.RDS');
break;
case DISCOVERY_HOSTDEVICES:
default:
case DISCOVERY_APP_MYSQL:
// Discovery Applications MySQL.
$data[6] = html_print_image(
'images/network.png',
true,
['title' => __('Discovery Applications MySQL')]
).'&nbsp;&nbsp;';
$data[6] .= __('Discovery.App.MySQL');
break;
case DISCOVERY_APP_ORACLE:
// Discovery Applications Oracle.
$data[6] = html_print_image(
'images/network.png',
true,
['title' => __('Discovery Applications Oracle')]
).'&nbsp;&nbsp;';
$data[6] .= __('Discovery.App.Oracle');
break;
case DISCOVERY_HOSTDEVICES:
default:
if ($task['id_recon_script'] == 0) {
// Discovery NetScan.
$data[6] = html_print_image(
'images/network.png',
@ -550,15 +569,15 @@ class DiscoveryTaskList extends Wizard
} else {
$data[6] .= __('Discovery.NetScan');
}
break;
}
} else {
// APP recon task.
$data[6] = html_print_image(
'images/plugin.png',
true
).'&nbsp;&nbsp;';
$data[6] .= $recon_script_name;
} else {
// APP or external script recon task.
$data[6] = html_print_image(
'images/plugin.png',
true
).'&nbsp;&nbsp;';
$data[6] .= $recon_script_name;
}
break;
}
if ($task['status'] <= 0 || $task['status'] > 100) {
@ -699,7 +718,16 @@ class DiscoveryTaskList extends Wizard
if ($script !== false) {
switch ($script['type']) {
case DISCOVERY_SCRIPT_CLOUD_AWS:
return 'wiz=cloud&mode=amazonws&ki='.$task['auth_strings'].'&page=1';
switch ($task['type']) {
case DISCOVERY_CLOUD_AWS_EC2:
return 'wiz=cloud&mode=amazonws&ki='.$task['auth_strings'].'&page=1';
case DISCOVERY_CLOUD_AZURE_COMPUTE:
return 'wiz=cloud&mode=azure&ki='.$task['auth_strings'].'&sub=compute&page=0';
default:
return 'wiz=cloud';
}
case DISCOVERY_SCRIPT_APP_VMWARE:
return 'wiz=app&mode=vmware&page=0';

View File

@ -582,6 +582,7 @@ define('DISCOVERY_APP_MYSQL', 4);
define('DISCOVERY_APP_ORACLE', 5);
define('DISCOVERY_CLOUD_AWS_EC2', 6);
define('DISCOVERY_CLOUD_AWS_RDS', 7);
define('DISCOVERY_CLOUD_AZURE_COMPUTE', 8);
// Discovery types matching definition.
@ -594,6 +595,7 @@ define('DISCOVERY_SCRIPT_IPAM_RECON', 3);
define('DISCOVERY_SCRIPT_IPMI_RECON', 4);
// Discovery task descriptions.
define('CLOUDWIZARD_AZURE_DESCRIPTION', 'Discovery.Cloud.Azure.Compute');
define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2');
define('CLOUDWIZARD_VMWARE_DESCRIPTION', 'Discovery.App.VMware');

View File

@ -72,6 +72,10 @@ function credentials_get_all(
throw new Exception('[credential_get_all] Fields must be an array or "count".');
}
if (isset($filter['product']) && !empty($filter['product'])) {
$sql_filters[] = sprintf(' AND cs.product = "%s"', $filter['product']);
}
if (isset($filter['free_search']) && !empty($filter['free_search'])) {
$sql_filters[] = vsprintf(
' AND (lower(cs.username) like lower("%%%s%%")
@ -163,7 +167,7 @@ function credentials_get_all(
%s
%s',
join(',', $fields),
join(',', $sql_filters),
join(' ', $sql_filters),
$order_by,
$pagination
);
@ -292,8 +296,8 @@ function print_inputs($values=null)
'script' => 'calculate_inputs()',
'fields' => [
// 'CUSTOM' => __('Custom'),
'AWS' => __('Aws'),
// 'AZURE' => __('Azure'),
'AWS' => __('Aws'),
'AZURE' => __('Azure'),
// 'GOOGLE' => __('Google'),
],
'selected' => $values['product'],
@ -319,7 +323,7 @@ function print_inputs($values=null)
case 'AZURE':
$user_label = __('Account ID');
$pass_label = __('Password');
$pass_label = __('Application secret');
$extra_1_label = __('Tenant or domain name');
$extra_2_label = __('Subscription id');
break;
@ -358,7 +362,7 @@ function print_inputs($values=null)
'label' => $extra_1_label,
'name' => 'extra_1',
'input_class' => 'flex-row',
'type' => 'password',
'type' => 'text',
'value' => $values['extra_1'],
'return' => true,
]
@ -371,7 +375,7 @@ function print_inputs($values=null)
'label' => $extra_2_label,
'name' => 'extra_2',
'input_class' => 'flex-row',
'type' => 'password',
'type' => 'text',
'value' => $values['extra_2'],
'return' => true,
'display' => $extra2,

View File

@ -96,7 +96,6 @@ function snmp_browser_get_html_tree(
foreach ($tree['__LEAVES__'] as $level => $sub_level) {
// Id used to expand leafs.
$sub_id = time().rand(0, getrandmax());
// Display the branch.
$output .= '<li id="li_'.$sub_id.'" style="margin: 0; padding: 0;">';
@ -225,7 +224,6 @@ function snmp_browser_print_tree(
$last_array,
$sufix,
$checked,
$return,
$descriptive_ids,
$previous_id
);

View File

@ -94,7 +94,7 @@ function pandora_session_write($session_id, $data)
if (is_ajax()) {
// Avoid session upadte while processing ajax responses - notifications.
if (get_parameter('check_new_notifications', false)) {
return false;
return true;
}
}

View File

@ -70,7 +70,7 @@ if (is_ajax()) {
if ($id_agente > 0) {
$last_contact = db_get_value_sql(
sprintf(
'SELECT intervalo - (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(IF(ultimo_contacto > ultimo_contacto_remoto, ultimo_contacto, ultimo_contacto_remoto)))
'SELECT format(intervalo,2) - (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(IF(ultimo_contacto > ultimo_contacto_remoto, ultimo_contacto, ultimo_contacto_remoto))) as "val"
FROM `tagente`
WHERE id_agente = %d ',
$id_agente

View File

@ -56,15 +56,7 @@ my $TaskSem :shared;
use constant {
OS_OTHER => 10,
OS_ROUTER => 17,
OS_SWITCH => 18,
DISCOVERY_HOSTDEVICES => 0,
DISCOVERY_HOSTDEVICES_CUSTOM => 1,
DISCOVERY_CLOUD_AWS => 2,
DISCOVERY_APP_VMWARE => 3,
DISCOVERY_APP_MYSQL => 4,
DISCOVERY_APP_ORACLE => 5,
DISCOVERY_CLOUD_AWS_EC2 => 6,
DISCOVERY_CLOUD_AWS_RDS => 7
OS_SWITCH => 18
};
########################################################################################
@ -196,49 +188,11 @@ sub data_consumer ($$) {
my $main_event = pandora_event($pa_config, "[Discovery] Execution summary",$task->{'id_group'}, 0, 0, 0, 0, 'system', 0, $dbh);
my %cnf_extra;
if ($task->{'type'} == DISCOVERY_CLOUD_AWS_EC2
|| $task->{'type'} == DISCOVERY_CLOUD_AWS_RDS) {
# auth_strings stores the crential identifier to be used.
my $key = pandora_get_credential($dbh, $task->{'auth_strings'});
if (ref($key) eq "HASH") {
$cnf_extra{'aws_access_key_id'} = $key->{'username'};
$cnf_extra{'aws_secret_access_key'} = $key->{'password'};
} else {
# Invalid credential.
return;
}
$cnf_extra{'cloud_util_path'} = pandora_get_config_value($dbh, 'cloud_util_path');
# Pass credentials by file due Perl limitations. We cannot update ENV here.
$cnf_extra{'creds_file'} = $pa_config->{'temporal'} . '/tmp_discovery.' . md5($task->{'id_rt'} . $task->{'name'} . time());
eval {
open(my $__file_cfg, '> '. $cnf_extra{'creds_file'}) or die($!);
print $__file_cfg $cnf_extra{'aws_access_key_id'} . "\n";
print $__file_cfg $cnf_extra{'aws_secret_access_key'} . "\n";
close($__file_cfg);
set_file_permissions(
$pa_config,
$cnf_extra{'creds_file'},
"0600"
);
};
if ($@) {
logger(
$pa_config,
'Cannot instantiate configuration file for task: ' . safe_output($task->{'name'}),
5
);
# A server restart will override ENV definition (see run)
logger(
$pa_config,
'Cannot execute Discovery task: ' . safe_output($task->{'name'}) . '. Please restart the server.',
1
);
# Skip this task.
return;
}
my $r = enterprise_hook('discovery_generate_extra_cnf',[$pa_config, $dbh, $task, \%cnf_extra]);
if (isset($r) && $r eq 'ERR') {
# Could not generate extra cnf, skip this task.
return;
}
my $recon = new PandoraFMS::Recon::Base(

View File

@ -72,6 +72,15 @@ our @EXPORT = qw(
MIGRATIONSERVER
METACONSOLE_LICENSE
OFFLINE_LICENSE
DISCOVERY_HOSTDEVICES
DISCOVERY_HOSTDEVICES_CUSTOM
DISCOVERY_CLOUD_AWS
DISCOVERY_APP_VMWARE
DISCOVERY_APP_MYSQL
DISCOVERY_APP_ORACLE
DISCOVERY_CLOUD_AWS_EC2
DISCOVERY_CLOUD_AWS_RDS
DISCOVERY_CLOUD_AZURE_COMPUTE
$DEVNULL
$OS
$OS_VERSION
@ -172,6 +181,17 @@ use constant OFFLINE_LICENSE => 0x02;
use constant RECOVERED_ALERT => 0;
use constant FIRED_ALERT => 1;
# Discovery task types
use constant DISCOVERY_HOSTDEVICES => 0;
use constant DISCOVERY_HOSTDEVICES_CUSTOM => 1;
use constant DISCOVERY_CLOUD_AWS => 2;
use constant DISCOVERY_APP_VMWARE => 3;
use constant DISCOVERY_APP_MYSQL => 4;
use constant DISCOVERY_APP_ORACLE => 5;
use constant DISCOVERY_CLOUD_AWS_EC2 => 6;
use constant DISCOVERY_CLOUD_AWS_RDS => 7;
use constant DISCOVERY_CLOUD_AZURE_COMPUTE => 8;
# Set OS, OS version and /dev/null
our $OS = $^O;
our $OS_VERSION = "unknown";