Files
librenms-librenms/app/Models/Vminfo.php
Jellyfrog 44578b2935 Convert string references to ::class (#14508)
PHP 5.5.9 adds the new static `class` property which provides the fully qualified class name. This is preferred over using strings for class names since the `class` property references are checked by PHP.

Co-authored-by: Shift <shift@laravelshift.com>
2022-10-25 08:31:46 -05:00

60 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Config;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Str;
use LibreNMS\Util\Html;
use LibreNMS\Util\Number;
use LibreNMS\Util\Rewrite;
class Vminfo extends DeviceRelatedModel
{
use HasFactory;
protected $table = 'vminfo';
public $timestamps = false;
public function getStateLabelAttribute(): array
{
return Html::powerStateLabel($this->vmwVmState);
}
public function getMemoryFormattedAttribute(): string
{
return Number::formatBi($this->vmwVmMemSize * 1024 * 1024);
}
public function getOperatingSystemAttribute(): string
{
if (Str::contains($this->vmwVmGuestOS, 'tools not installed')) {
return 'Unknown (VMware Tools not installed)';
} elseif (Str::contains($this->vmwVmGuestOS, 'tools not running')) {
return 'Unknown (VMware Tools not running)';
} elseif (empty($this->vmwVmGuestOS)) {
return '(Unknown)';
} else {
return Rewrite::vmwareGuest($this->vmwVmGuestOS);
}
}
public function scopeGuessFromDevice(Builder $query, Device $device): Builder
{
$where = [$device->hostname];
if (Config::get('mydomain')) {
$where[] = $device->hostname . '.' . Config::get('mydomain');
}
return $query->whereIn('vmwVmDisplayName', $where);
}
public function parentDevice(): HasOne
{
return $this->hasOne(\App\Models\Device::class, 'hostname', 'vmwVmDisplayName');
}
}