public function StatuspageController::content in Nagios Monitoring 8
Main function building the string to show via HTTP.
Parameters
string $module_name: Only check the given module with a hook_nagios() implementation.
string $id_for_hook: An arbitrary value to pass into the hook_nagios() implementation.
Return value
\Symfony\Component\HttpFoundation\Response
1 string reference to 'StatuspageController::content'
- nagios.settings.yml in config/
install/ nagios.settings.yml - config/install/nagios.settings.yml
File
- src/
Controller/ StatuspageController.php, line 39
Class
- StatuspageController
- Class StatuspageController produces the HTTP output that the bash script in the nagios-plugin directory understands.
Namespace
Drupal\nagios\ControllerCode
public function content(string $module_name = '', string $id_for_hook = '') {
// Disable cache:
\Drupal::service('page_cache_kill_switch')
->trigger();
// Check the unique ID string and access permissions first.
$ua = $this->config
->get('nagios.ua');
$request_code = $_SERVER['HTTP_USER_AGENT'];
// Check if HTTP GET variable "unique_id" is used and the usage is allowed.
if (isset($_GET['unique_id']) && $this->config
->get('nagios.statuspage.getparam') == TRUE) {
$request_code = $_GET['unique_id'];
}
if ($request_code == $ua || \Drupal::currentUser()
->hasPermission('administer site configuration')) {
// Authorized, so go ahead calling all modules:
$nagios_data = $module_name ? [
$module_name => call_user_func($module_name . '_nagios', $id_for_hook),
] : nagios_invoke_all('nagios');
}
else {
// This is not an authorized unique id or user,
// so just return this default status.
$nagios_data = [
'nagios' => [
'DRUPAL' => [
'status' => NAGIOS_STATUS_UNKNOWN,
'type' => 'state',
'text' => $this
->t('Unauthorized'),
],
],
];
}
[
$output,
] = $this
->getStringFromNagiosData($nagios_data);
$response = new Response($output, Response::HTTP_OK, [
'Content-Type' => 'text/plain',
]);
// Disable browser cache:
$response
->setMaxAge(0);
$response
->setExpires();
return $response;
}