You are here

private function SettingsForm::getUserAgentRadioDesc in Nagios Monitoring 8

Builds the description.

Return value

string Dynamic help text

1 call to SettingsForm::getUserAgentRadioDesc()
SettingsForm::buildForm in src/Form/SettingsForm.php
Form constructor.

File

src/Form/SettingsForm.php, line 256

Class

SettingsForm
Allows admins to configure the Nagios module.

Namespace

Drupal\nagios\Form

Code

private function getUserAgentRadioDesc() {
  $config = $this
    ->config('nagios.settings');
  $getParam = (int) $config
    ->get('nagios.statuspage.getparam');
  $uniqueId = $config
    ->get('nagios.ua');
  $routeParameters = $getParam ? [
    'unique_id' => $uniqueId,
  ] : [];
  $aUrlInfo = [
    ':url' => Url::fromRoute('nagios.statuspage', $routeParameters, [
      'absolute' => TRUE,
    ])
      ->toString(),
  ];
  $aUrlInfo += parse_url(reset($aUrlInfo));
  $urlForCli = "'" . reset($aUrlInfo) . "'";
  $commands[] = 'curl --no-progress-meter --url ' . $urlForCli . ($getParam ? '' : " --user-agent '{$uniqueId}'");
  $commands[] = 'wget --no-verbose -O -' . ($getParam ? '' : " -U '{$uniqueId}'") . ' ' . $urlForCli;
  $commands[] = realpath(__DIR__ . '/../../nagios-plugin/check_drupal') . ' -H ' . $aUrlInfo['host'] . ' -P ' . $config
    ->get('nagios.statuspage.path') . ($getParam ? '?' . $aUrlInfo['query'] : " -U '{$uniqueId}'") . ($aUrlInfo['scheme'] == 'https' ? ' -S' : '');
  $commands[] = 'drush nagios # ' . $this
    ->t('no HTTP status page needed');
  return $this
    ->t('If enabled the $_GET variable "unique_id" is used for checking the correct Unique ID instead of "User Agent" ($_SERVER[\'HTTP_USER_AGENT\']).') . ' ' . ($getParam ? $this
    ->t('You need to call the following URL from Nagios / Icinga / cURL: <a href=":url">:url</a>.', $aUrlInfo) . ' ' : '') . $this
    ->t('This feature is useful to avoid webserver stats with the Unique ID as "User Agent" and helpful for human testing.') . '<br><br>' . $this
    ->t('Here are a few example Bash commands you can use to query the status:') . '<ul><li>' . join('<li>', $commands) . '</ul>';
}