1 | <?php |
||
2 | |||
3 | namespace App\Models; |
||
4 | |||
5 | use Config; |
||
6 | use Illuminate\Database\Eloquent\Builder; |
||
7 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
||
8 | use Illuminate\Database\Eloquent\Relations\HasOne; |
||
9 | use Illuminate\Support\Str; |
||
10 | use LibreNMS\Util\Html; |
||
11 | use LibreNMS\Util\Number; |
||
12 | use LibreNMS\Util\Rewrite; |
||
13 | |||
14 | class Vminfo extends DeviceRelatedModel |
||
15 | { |
||
16 | use HasFactory; |
||
17 | |||
18 | protected $table = 'vminfo'; |
||
19 | public $timestamps = false; |
||
20 | |||
21 | public function getStateLabelAttribute(): array |
||
22 | { |
||
23 | return Html::powerStateLabel($this->vmwVmState); |
||
24 | } |
||
25 | |||
26 | public function getMemoryFormattedAttribute(): string |
||
27 | { |
||
28 | return Number::formatBi($this->vmwVmMemSize * 1024 * 1024); |
||
29 | } |
||
30 | |||
31 | public function getOperatingSystemAttribute(): string |
||
32 | { |
||
33 | if (Str::contains($this->vmwVmGuestOS, 'tools not installed')) { |
||
34 | return 'Unknown (VMware Tools not installed)'; |
||
35 | } elseif (Str::contains($this->vmwVmGuestOS, 'tools not running')) { |
||
36 | return 'Unknown (VMware Tools not running)'; |
||
37 | } elseif (empty($this->vmwVmGuestOS)) { |
||
38 | return '(Unknown)'; |
||
39 | } else { |
||
40 | return Rewrite::vmwareGuest($this->vmwVmGuestOS); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | public function scopeGuessFromDevice(Builder $query, Device $device): Builder |
||
45 | { |
||
46 | $where = [$device->hostname]; |
||
47 | |||
48 | if (Config::get('mydomain')) { |
||
49 | $where[] = $device->hostname . '.' . Config::get('mydomain'); |
||
50 | } |
||
51 | |||
52 | return $query->whereIn('vmwVmDisplayName', $where); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
53 | } |
||
54 | |||
55 | public function parentDevice(): HasOne |
||
56 | { |
||
57 | return $this->hasOne('App\Models\Device', 'hostname', 'vmwVmDisplayName'); |
||
58 | } |
||
59 | } |
||
60 |