Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Host.php

class Host

Hierarchy

  • class \OpenTelemetry\SDK\Resource\Detectors\Host implements \OpenTelemetry\SDK\Resource\ResourceDetectorInterface

Expanded class hierarchy of Host

See also

https://github.com/open-telemetry/opentelemetry-specification/blob/v1.8…

17 string references to 'Host'
Client::sendAsync in vendor/guzzlehttp/guzzle/src/Client.php
Asynchronously send an HTTP request.
core.data_types.schema.yml in core/config/schema/core.data_types.schema.yml
core/config/schema/core.data_types.schema.yml
CredentialForm::validateForm in core/modules/migrate_drupal_ui/src/Form/CredentialForm.php
Form validation handler.
FileTransfer::getSettingsForm in core/lib/Drupal/Core/FileTransfer/FileTransfer.php
Returns a form to collect connection settings credentials.
Html::transformRootRelativeUrlsToAbsolute in core/lib/Drupal/Component/Utility/Html.php
Converts all root-relative URLs to absolute URLs.

... See full list

File

vendor/open-telemetry/sdk/Resource/Detectors/Host.php, line 16

Namespace

OpenTelemetry\SDK\Resource\Detectors
View source
final class Host implements ResourceDetectorInterface {
    private const PATH_ETC_MACHINEID = 'etc/machine-id';
    private const PATH_VAR_LIB_DBUS_MACHINEID = 'var/lib/dbus/machine-id';
    private const PATH_ETC_HOSTID = 'etc/hostid';
    public function __construct(string $dir = '/', string $os = PHP_OS_FAMILY) {
    }
    public function getResource() : ResourceInfo {
        $attributes = [
            ResourceAttributes::HOST_NAME => php_uname('n'),
            ResourceAttributes::HOST_ARCH => php_uname('m'),
            ResourceAttributes::HOST_ID => $this->getMachineId(),
        ];
        return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL);
    }
    private function getMachineId() : ?string {
        return match ($this->os) {    'Linux' => $this->getLinuxId(),
            'BSD' => $this->getBsdId(),
            'Darwin' => $this->getMacOsId(),
            'Windows' => $this->getWindowsId(),
            default => null,
        
        };
    }
    private function getLinuxId() : ?string {
        $paths = [
            self::PATH_ETC_MACHINEID,
            self::PATH_VAR_LIB_DBUS_MACHINEID,
        ];
        foreach ($paths as $path) {
            $file = $this->dir . $path;
            if (is_file($file) && is_readable($file)) {
                return trim(file_get_contents($file));
            }
        }
        return null;
    }
    private function getBsdId() : ?string {
        $file = $this->dir . self::PATH_ETC_HOSTID;
        if (is_file($file) && is_readable($file)) {
            return trim(file_get_contents($file));
        }
        $out = exec('which kenv && kenv -q smbios.system.uuid');
        if ($out) {
            return $out;
        }
        return null;
    }
    private function getMacOsId() : ?string {
        $out = exec('ioreg -rd1 -c IOPlatformExpertDevice | awk \'/IOPlatformUUID/ { split($0, line, "\\""); printf("%s\\n", line[4]); }\'');
        if ($out !== false) {
            return $out;
        }
        return null;
    }
    private function getWindowsId() : ?string {
        $out = exec('powershell.exe -Command "Get-ItemPropertyValue -Path HKLM:\\SOFTWARE\\Microsoft\\Cryptography -Name MachineGuid"');
        if ($out !== false) {
            return $out;
        }
        return null;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Host::getBsdId private function
Host::getLinuxId private function
Host::getMachineId private function
Host::getMacOsId private function
Host::getResource public function Overrides ResourceDetectorInterface::getResource
Host::getWindowsId private function
Host::PATH_ETC_HOSTID private constant
Host::PATH_ETC_MACHINEID private constant
Host::PATH_VAR_LIB_DBUS_MACHINEID private constant
Host::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal