Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2019-06-03 19:15:13 -05:00
<?php
namespace App\Models;
use Config;
use Illuminate\Database\Eloquent\Builder;
2020-11-03 17:18:31 +01:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Str;
2023-10-05 19:49:26 -05:00
use LibreNMS\Interfaces\Models\Keyable;
use LibreNMS\Util\Html;
2020-11-23 15:35:35 -06:00
use LibreNMS\Util\Number;
use LibreNMS\Util\Rewrite;
2020-11-03 17:18:31 +01:00
2023-10-05 19:49:26 -05:00
class Vminfo extends DeviceRelatedModel implements Keyable
2019-06-03 19:15:13 -05:00
{
2020-11-03 17:18:31 +01:00
use HasFactory;
2019-06-03 19:15:13 -05:00
protected $table = 'vminfo';
public $timestamps = false;
2023-10-05 19:49:26 -05:00
protected $fillable = [
'vm_type',
'vmwVmVMID',
'vmwVmDisplayName',
'vmwVmGuestOS',
'vmwVmMemSize',
'vmwVmCpus',
'vmwVmState',
];
2020-11-24 00:16:41 +01:00
public function getStateLabelAttribute(): array
{
return Html::powerStateLabel($this->vmwVmState);
}
public function getMemoryFormattedAttribute(): string
{
2020-11-23 15:35:35 -06:00
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');
}
2023-10-05 19:49:26 -05:00
public function getCompositeKey()
{
return $this->vm_type . $this->vmwVmVMID;
}
2019-06-03 19:15:13 -05:00
}