forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vminfo.php
59 lines (48 loc) · 1.61 KB
/
Vminfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?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', 'hostname', 'vmwVmDisplayName');
}
}