mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
hrsystem write fix (#13314)
This commit is contained in:
@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@@ -631,9 +632,9 @@ class Device extends BaseModel
|
|||||||
return $this->hasMany(HrDevice::class, 'device_id');
|
return $this->hasMany(HrDevice::class, 'device_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hostResourceValues(): HasMany
|
public function hostResourceValues(): HasOne
|
||||||
{
|
{
|
||||||
return $this->hasMany(HrSystem::class, 'device_id');
|
return $this->hasOne(HrSystem::class, 'device_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entityPhysical(): HasMany
|
public function entityPhysical(): HasMany
|
||||||
|
@@ -6,7 +6,7 @@ class HrSystem extends DeviceRelatedModel
|
|||||||
{
|
{
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
protected $table = 'hrSystem';
|
protected $table = 'hrSystem';
|
||||||
protected $fillable = ['hrSystemNumUsers', 'hrSystemProcesses', 'hrSystemMaxProcesses'];
|
protected $fillable = ['device_id', 'hrSystemNumUsers', 'hrSystemProcesses', 'hrSystemMaxProcesses'];
|
||||||
|
|
||||||
protected $primaryKey = 'hrSystem_id';
|
protected $primaryKey = 'hrSystem_id';
|
||||||
}
|
}
|
||||||
|
@@ -3,14 +3,12 @@
|
|||||||
// HOST-RESOURCES-MIB
|
// HOST-RESOURCES-MIB
|
||||||
// Generic System Statistics
|
// Generic System Statistics
|
||||||
|
|
||||||
use App\Models\Device;
|
use App\Models\HrSystem;
|
||||||
use LibreNMS\RRD\RrdDefinition;
|
use LibreNMS\RRD\RrdDefinition;
|
||||||
|
|
||||||
$oid_list = ['hrSystemMaxProcesses.0', 'hrSystemProcesses.0', 'hrSystemNumUsers.0'];
|
$oid_list = ['hrSystemMaxProcesses.0', 'hrSystemProcesses.0', 'hrSystemNumUsers.0'];
|
||||||
$hrSystem = snmp_get_multi($device, $oid_list, '-OUQs', 'HOST-RESOURCES-MIB');
|
$hrSystem = snmp_get_multi($device, $oid_list, '-OUQs', 'HOST-RESOURCES-MIB');
|
||||||
|
|
||||||
$current_device = Device::find($device['device_id']);
|
|
||||||
|
|
||||||
if (is_numeric($hrSystem[0]['hrSystemProcesses'])) {
|
if (is_numeric($hrSystem[0]['hrSystemProcesses'])) {
|
||||||
$tags = [
|
$tags = [
|
||||||
'rrd_def' => RrdDefinition::make()->addDataset('procs', 'GAUGE', 0),
|
'rrd_def' => RrdDefinition::make()->addDataset('procs', 'GAUGE', 0),
|
||||||
@@ -35,10 +33,11 @@ if (is_numeric($hrSystem[0]['hrSystemNumUsers'])) {
|
|||||||
|
|
||||||
data_update($device, 'hr_users', $tags, $fields);
|
data_update($device, 'hr_users', $tags, $fields);
|
||||||
|
|
||||||
$current_device->hostResourceValues()->updateOrCreate(['device_id' => $current_device->id, 'key' => 'num_users'],
|
HrSystem::updateOrCreate(['device_id' => $device['device_id']],
|
||||||
['hrSystemNumUsers' => $hrSystem[0]['hrSystemNumUsers'],
|
['hrSystemNumUsers' => $hrSystem[0]['hrSystemNumUsers'],
|
||||||
'hrSystemProcesses' => $hrSystem[0]['hrSystemProcesses'],
|
'hrSystemProcesses' => $hrSystem[0]['hrSystemProcesses'],
|
||||||
'hrSystemMaxProcesses' => $hrSystem[0]['hrSystemMaxProcesses'], ]);
|
'hrSystemMaxProcesses' => $hrSystem[0]['hrSystemMaxProcesses'], ]);
|
||||||
|
|
||||||
$os->enableGraph('hr_users');
|
$os->enableGraph('hr_users');
|
||||||
echo ' Users';
|
echo ' Users';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user