You are here

function _nagios_update_os_user in Nagios Monitoring 8

Same name and namespace in other branches
  1. 7 nagios.module \_nagios_update_os_user()

Update the information under which operating system user PHP is currently running. This helps to detect permission problems when CLI and web users differ.

Return value

array<string, string>

4 calls to _nagios_update_os_user()
NagiosCommands::nagios in src/Commands/NagiosCommands.php
Allows querying Drupal's health. Useful for NRPE.
nagios_check in ./nagios.drush.inc
Helper function for drush_nagios_check().
SettingsForm::buildForm in src/Form/SettingsForm.php
Form constructor.
StatuspageController::__construct in src/Controller/StatuspageController.php

File

./nagios.module, line 69
Main file for Nagios service monitoring.

Code

function _nagios_update_os_user() : array {
  $state = Drupal::state();
  $os_user = $state
    ->get('nagios.os_user', []);
  if (function_exists('posix_getpwuid')) {
    $current_user = posix_getpwuid(posix_geteuid())['name'];
  }
  if (empty($current_user)) {
    $current_user = getenv('UID') ?: getenv('USERNAME');
  }
  if (isset($os_user[PHP_SAPI]) && $os_user[PHP_SAPI] == $current_user) {

    // Already up-to-date
    return $os_user;
  }
  $os_user[PHP_SAPI] = $current_user;
  $state
    ->set('nagios.os_user', $os_user);
  return $os_user;
}