From 18d8f90f90503b8a5e672be57c4bad1a1561a139 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 3 Jul 2019 16:04:40 +0200 Subject: [PATCH 1/6] Credential store upgrade Azure --- pandora_console/godmode/groups/credential_store.php | 4 ++-- pandora_console/include/functions_credential_store.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/groups/credential_store.php b/pandora_console/godmode/groups/credential_store.php index 9a822dc986..8c9540d581 100644 --- a/pandora_console/godmode/groups/credential_store.php +++ b/pandora_console/godmode/groups/credential_store.php @@ -534,8 +534,8 @@ echo ''; $('#div-extra_1').hide(); $('#div-extra_2').hide(); } else if ($('#product :selected').val() == "AZURE") { - $('#div-username label').text(''); - $('#div-password label').text(''); + $('#div-username label').text(''); + $('#div-password label').text(''); $('#div-extra_1 label').text(''); $('#div-extra_2 label').text(''); $('#div-extra_1').show(); diff --git a/pandora_console/include/functions_credential_store.php b/pandora_console/include/functions_credential_store.php index cf09e6d67b..0293cf9721 100644 --- a/pandora_console/include/functions_credential_store.php +++ b/pandora_console/include/functions_credential_store.php @@ -292,8 +292,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 +319,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; From 07edee619a92b7178006b90ab80c9ce4a7cebdc4 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 3 Jul 2019 16:38:26 +0200 Subject: [PATCH 2/6] CS filtering and constant --- pandora_console/include/constants.php | 1 + pandora_console/include/functions_credential_store.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 69e867bb40..c5cce5d347 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -602,6 +602,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'); diff --git a/pandora_console/include/functions_credential_store.php b/pandora_console/include/functions_credential_store.php index 0293cf9721..20b643d0b8 100644 --- a/pandora_console/include/functions_credential_store.php +++ b/pandora_console/include/functions_credential_store.php @@ -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 ); From 0e3fd848f7e1e5a66ba670058c278ef4d1bcea85 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 4 Jul 2019 19:34:03 +0200 Subject: [PATCH 3/6] minor fixes and visual change in azure credentials --- pandora_console/include/constants.php | 1 + pandora_console/include/functions_credential_store.php | 4 ++-- pandora_console/operation/agentes/ver_agente.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index c5cce5d347..7e44f1c080 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -590,6 +590,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. diff --git a/pandora_console/include/functions_credential_store.php b/pandora_console/include/functions_credential_store.php index 20b643d0b8..eaf756f7b1 100644 --- a/pandora_console/include/functions_credential_store.php +++ b/pandora_console/include/functions_credential_store.php @@ -362,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, ] @@ -375,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, diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index b9b2a2128d..b625595930 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -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 From bd80e013f56330d91e33cdc3cd19b4425cca8582 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 9 Jul 2019 12:02:07 +0200 Subject: [PATCH 4/6] minor fix to avoid log messages --- pandora_console/include/load_session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/load_session.php b/pandora_console/include/load_session.php index 99bae81244..8b243d808a 100644 --- a/pandora_console/include/load_session.php +++ b/pandora_console/include/load_session.php @@ -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; } } From 0cabc4d4dac8ac6895b18208ae5cf0177ceeb287 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 9 Jul 2019 12:02:29 +0200 Subject: [PATCH 5/6] Azure discovery task form completed --- .../wizards/DiscoveryTaskList.class.php | 112 +++++++++++------- .../include/functions_snmp_browser.php | 2 - 2 files changed, 70 insertions(+), 44 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index e018ec3d30..586f24335b 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -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')] - ).'  '; - $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')] + ).'  '; + $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')] - ).'  '; - $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')] + ).'  '; + $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')] - ).'  '; - $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')] + ).'  '; + $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')] + ).'  '; + $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')] + ).'  '; + $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 - ).'  '; - $data[6] .= $recon_script_name; + } else { + // APP or external script recon task. + $data[6] = html_print_image( + 'images/plugin.png', + true + ).'  '; + $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'; diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index dded175af5..5b485d9e54 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -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 .= '
  • '; @@ -225,7 +224,6 @@ function snmp_browser_print_tree( $last_array, $sufix, $checked, - $return, $descriptive_ids, $previous_id ); From ca3b893073db33d06b250250ea6614b34e893392 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 9 Jul 2019 16:08:29 +0200 Subject: [PATCH 6/6] Discovery Cloud Azure --- .../lib/PandoraFMS/DiscoveryServer.pm | 58 ++----------------- pandora_server/lib/PandoraFMS/Tools.pm | 20 +++++++ 2 files changed, 26 insertions(+), 52 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 80fcbef8d3..8993826931 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -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( diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 6271698c03..4a96c5851d 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -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";