Skip to content

Commit 7d98e7e

Browse files
authored
Remove del_dev_attrib (librenms#19418)
* Remove del_dev_attrib * Forgotten one variable * ‎use
1 parent 501d60a commit 7d98e7e

6 files changed

Lines changed: 32 additions & 34 deletions

File tree

includes/common.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ function get_dev_attrib($device, $attrib_type)
200200
return DeviceCache::get((int) $device['device_id'])->getAttrib($attrib_type);
201201
}
202202

203-
function del_dev_attrib($device, $attrib_type)
204-
{
205-
return DeviceCache::get((int) $device['device_id'])->forgetAttrib($attrib_type);
206-
}
207-
208203
/**
209204
* Output using console color if possible
210205
* https://github.com/pear/Console_Color2/blob/master/examples/documentation

includes/html/api_functions.inc.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,10 +1248,13 @@ function update_port_description(Illuminate\Http\Request $request)
12481248
->where([
12491249
'port_id' => $port_id,
12501250
])->first();
1251+
12511252
if (empty($port)) {
12521253
return api_error(400, 'Invalid port ID.');
12531254
}
12541255

1256+
$device = DeviceCache::get($port->device_id);
1257+
12551258
$data = json_decode($request->getContent(), true);
12561259
$field = 'description';
12571260
$description = $data[$field];
@@ -1265,19 +1268,16 @@ function update_port_description(Illuminate\Http\Request $request)
12651268
$port->ifAlias = $description;
12661269
$port->save();
12671270

1268-
$ifName = $port->ifName;
1269-
$device = $port->device_id;
1270-
12711271
if ($description == 'repoll') {
12721272
// No description provided, clear description
1273-
del_dev_attrib($port, 'ifName:' . $ifName); // "port" object has required device_id
1274-
Eventlog::log("$ifName Port ifAlias cleared via API", $device, 'interface', Severity::Notice, $port_id);
1273+
$device->forgetAttrib('ifName:' . $port->ifName);
1274+
Eventlog::log("$port->ifName Port ifAlias cleared via API", $port->device_id, 'interface', Severity::Notice, $port->port_id);
12751275

12761276
return api_success_noresult(200, 'Port description cleared.');
12771277
} else {
12781278
// Prevent poller from overwriting new description
1279-
set_dev_attrib($port, 'ifName:' . $ifName, 1); // see above
1280-
Eventlog::log("$ifName Port ifAlias set via API: $description", $device, 'interface', Severity::Notice, $port_id);
1279+
$device->setAttrib('ifName:' . $port->ifName, 1);
1280+
Eventlog::log("$port->ifName Port ifAlias set via API: $description", $port->device_id, 'interface', Severity::Notice, $port->port_id);
12811281

12821282
return api_success_noresult(200, 'Port description updated.');
12831283
}

includes/html/forms/override-config.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* the source code distribution for details.
1313
*/
1414

15+
use App\Facades\DeviceCache;
1516
use App\Models\Device;
1617
use Illuminate\Support\Facades\Gate;
1718

@@ -38,7 +39,7 @@
3839
if ($state == true) {
3940
set_dev_attrib($device, $attrib, $state);
4041
} else {
41-
del_dev_attrib($device, $attrib);
42+
DeviceCache::get((int) $device['device_id'])->forgetAttrib($attrib);
4243
}
4344
$status = 'ok';
4445
$message = 'Config has been updated';

includes/html/forms/update-ifalias.inc.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Facades\DeviceCache;
34
use App\Models\Eventlog;
45
use App\Models\Port;
56
use LibreNMS\Enum\Severity;
@@ -34,13 +35,13 @@
3435
// Set to repoll so we avoid using ifDescr on port poll
3536
}
3637
if (Port::where('port_id', $port_id)->update(['ifAlias' => $descr]) > 0) {
37-
$device = device_by_id_cache($device_id);
38+
$device = DeviceCache::get($device_id);
3839
if ($descr === 'repoll') {
39-
del_dev_attrib($device, 'ifName:' . $ifName);
40-
Eventlog::log("$ifName Port ifAlias cleared manually", $device['device_id'], 'interface', Severity::Notice, $port_id);
40+
$device->forgetAttrib('ifName:' . $ifName);
41+
Eventlog::log("$ifName Port ifAlias cleared manually", $device->device_id, 'interface', Severity::Notice, $port_id);
4142
} else {
42-
set_dev_attrib($device, 'ifName:' . $ifName, 1);
43-
Eventlog::log("$ifName Port ifAlias set manually: $descr", $device['device_id'], 'interface', Severity::Notice, $port_id);
43+
$device->setAttrib('ifName:' . $ifName, 1);
44+
Eventlog::log("$ifName Port ifAlias set manually: $descr", $device->device_id, 'interface', Severity::Notice, $port_id);
4445
}
4546
$status = 'ok';
4647
} else {

includes/html/pages/device/edit/ipmi.inc.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

3+
use App\Facades\DeviceCache;
34
use Illuminate\Support\Facades\Gate;
45

56
if ($_POST['editing']) {
6-
if (Gate::allows('update', DeviceCache::getPrimary())) {
7+
$device=DeviceCache::getPrimary();
8+
if (Gate::allows('update', $device)) {
79
$ipmi_hostname = $_POST['ipmi_hostname'];
810
$ipmi_port = (int) $_POST['ipmi_port'];
911
$ipmi_username = $_POST['ipmi_username'];
@@ -13,45 +15,45 @@
1315
$ipmi_timeout = $_POST['ipmi_timeout'];
1416

1517
if ($ipmi_hostname != '') {
16-
set_dev_attrib($device, 'ipmi_hostname', $ipmi_hostname);
18+
$device->setAttrib('ipmi_hostname', $ipmi_hostname);
1719
} else {
18-
del_dev_attrib($device, 'ipmi_hostname');
20+
$device->forgetAttrib('ipmi_hostname');
1921
}
2022

2123
if ($ipmi_port != 0) {
22-
set_dev_attrib($device, 'ipmi_port', $ipmi_port);
24+
$device->setAttrib('ipmi_port', $ipmi_port);
2325
} else {
24-
set_dev_attrib($device, 'ipmi_port', '623'); // Default port
26+
$device->setAttrib('ipmi_port', 623); // Default port
2527
}
2628

2729
if ($ipmi_username != '') {
28-
set_dev_attrib($device, 'ipmi_username', $ipmi_username);
30+
$device->setAttrib('ipmi_username', $ipmi_username);
2931
} else {
30-
del_dev_attrib($device, 'ipmi_username');
32+
$device->forgetAttrib('ipmi_username');
3133
}
3234

3335
if ($ipmi_password != '') {
34-
set_dev_attrib($device, 'ipmi_password', $ipmi_password);
36+
$device->setAttrib('ipmi_password', $ipmi_password);
3537
} else {
36-
del_dev_attrib($device, 'ipmi_password');
38+
$device->forgetAttrib('ipmi_password');
3739
}
3840

3941
if ($ipmi_kg_key != '') {
40-
set_dev_attrib($device, 'ipmi_kg_key', $ipmi_kg_key);
42+
$device->setAttrib('ipmi_kg_key', $ipmi_kg_key);
4143
} else {
42-
del_dev_attrib($device, 'ipmi_kg_key');
44+
$device->forgetAttrib('ipmi_kg_key');
4345
}
4446

4547
if ($ipmi_ciphersuite != '') {
46-
set_dev_attrib($device, 'ipmi_ciphersuite', $ipmi_ciphersuite);
48+
$device->setAttrib('ipmi_ciphersuite', $ipmi_ciphersuite);
4749
} else {
48-
del_dev_attrib($device, 'ipmi_ciphersuite');
50+
$device->forgetAttrib('ipmi_ciphersuite');
4951
}
5052

5153
if ($ipmi_timeout != '') {
52-
set_dev_attrib($device, 'ipmi_timeout', $ipmi_timeout);
54+
$device->setAttrib('ipmi_timeout', $ipmi_timeout);
5355
} else {
54-
del_dev_attrib($device, 'ipmi_timeout');
56+
$device->forgetAttrib('ipmi_timeout');
5557
}
5658

5759
$update_message = 'Device IPMI data updated.';

includes/html/pages/device/edit/snmp.inc.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
// update devices_attribs table
6464

6565
// note:
66-
// set_dev_attrib and del_dev_attrib *only* return (bool)
6766
// setAttrib() returns true if it was set and false if it was not (e.g. it didn't change)
6867
// forgetAttrib() returns true if it was deleted and false if it was not (e.g. it didn't exist)
6968
// Symfony throws FatalThrowableError on error

0 commit comments

Comments
 (0)