Merge branch 'ent-10905-comprobacion-en-el-servidor-de-que-tiene-acceso-a-la-api' into 'develop'

Ent-10905-comprobacion-en-el-servidor-de-que-tiene-acceso-a-la-api

Closes pandora_enterprise#10905

See merge request artica/pandorafms!6289
This commit is contained in:
Rafael Ameijeiras 2023-08-21 06:15:45 +00:00
commit 9c4825f03e
4 changed files with 69 additions and 1 deletions

View File

@ -210,6 +210,12 @@ class ConsoleSupervisor
$this->checkUpdateManagerRegistration();
/*
* Check if has API access.
* NOTIF.API.ACCESS
*/
$this->checkApiAccess();
/*
* Check if there're new messages in UM.
* NOTIF.UPDATEMANAGER.MESSAGES
@ -434,6 +440,12 @@ class ConsoleSupervisor
$this->checkUpdateManagerRegistration();
/*
* Check if has API access.
* NOTIF.API.ACCESS
*/
$this->checkApiAccess();
/*
* Check if event storm protection is activated.
* NOTIF.MISC.EVENTSTORMPROTECTION
@ -498,6 +510,12 @@ class ConsoleSupervisor
$this->checkUpdateManagerRegistration();
/*
* Check if has API access.
* NOTIF.API.ACCESS
*/
$this->checkApiAccess();
/*
* Check if there're new messages in UM.
* NOTIF.UPDATEMANAGER.MESSAGES
@ -864,6 +882,7 @@ class ConsoleSupervisor
case 'NOTIF.METACONSOLE.DB_CONNECTION':
case 'NOTIF.DOWNTIME':
case 'NOTIF.UPDATEMANAGER.REGISTRATION':
case 'NOTIF.API.ACCESS':
case 'NOTIF.MISC.EVENTSTORMPROTECTION':
case 'NOTIF.MISC.DEVELOPBYPASS':
case 'NOTIF.MISC.FONTPATH':
@ -2365,6 +2384,29 @@ class ConsoleSupervisor
}
}
/**
* Check if has access to the API
*
* @return void
*/
public function checkApiAccess()
{
global $config;
include_once $config['homedir'].'/include/functions_update_manager.php';
if (update_manager_verify_api() === false) {
$this->notify(
[
'type' => 'NOTIF.API.ACCESS',
'title' => __('Cannot access the Pandora FMS API '),
'message' => __('Please check the configuration, some components may fail due to this misconfiguration.'),
]
);
} else {
$this->cleanNotifications('NOTIF.API.ACCESS');
}
}
/**
* Check if user 'admin' is enabled and using default password.

View File

@ -145,6 +145,7 @@ function notifications_get_subtypes(?string $source=null)
'NOTIF.METACONSOLE.DB_CONNECTION',
'NOTIF.DOWNTIME',
'NOTIF.UPDATEMANAGER.REGISTRATION',
'NOTIF.API.ACCESS',
'NOTIF.MISC.EVENTSTORMPROTECTION',
'NOTIF.MISC.DEVELOPBYPASS',
'NOTIF.MISC.FONTPATH',

View File

@ -54,6 +54,17 @@ function update_manager_verify_registration()
return false;
}
/**
* Verifies api state.
*
* @return boolean Status.
*/
function update_manager_verify_api()
{
global $config;
return (isset($config['has_api_access']) === true && $config['has_api_access'] == '1');
}
/**
* Retrieves current update from DB.

View File

@ -733,15 +733,29 @@ sub main() {
my $command = $Config{'plugin_exec'}.' 30 curl --cookie-jar /tmp/cron-session-cookies '.$curl_execution.' 2>/dev/null';
my $exe_testing_api = `$command`;
my @res_testing_api = split(',', $exe_testing_api);
my $has_api_access = undef;
if ( $res_testing_api[0] ne 'OK' ) {
logger(\%Config, "Warning! The server does not have access to the API, this can trigger problems in the generation of reports and graphs.", 1);
pandora_event (\%Config, "Server does not have access to the API", 0, 0, 0, 0, 0, 'system', 0, $DBH);
pandora_event (\%Config, "The server " . $Config{'servername'} ." cannot access the Pandora FMS API through the supplied credentials. Please check the configuration, some components may fail due to this misconfiguration. Look in the manual for the configuration tokens related to console_api_pass.", 0, 0, 0, 0, 0, 'system', 0, $DBH);
$has_api_access = "0";
} else {
# Test successful.
pandora_set_tconfig_token($DBH, 'internal_user_pass',
pandora_input_password(\%Config, $Config{"console_pass"})
);
pandora_set_tconfig_token($DBH, 'internal_user', $Config{"console_user"});
$has_api_access = "1";
}
my $token = "has_api_access";
my $prev_access = pandora_get_config_value($DBH, $token);
if(defined($prev_access) && $prev_access ne "") {
db_update ($DBH, 'UPDATE tconfig SET value = ? WHERE token = ?', $has_api_access, $token);
}
else {
db_insert ($DBH, 'id_config', 'INSERT INTO tconfig (token, value) VALUES (?, ?)', $token, $has_api_access);
}
# Generate 'going up' events