mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Set ip to null when a device is renamed (#9112)
Oddly this doesn't check if the target hostname exists in the database, so that is left to the caller. (likely the target rrd directory will exist). If we wanted to check that in function this I'd probably covert it to Exception errors so we could signal the different types of failures. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
committed by
Neil Lathwood
parent
0e6b59133e
commit
3268fca4cf
@@ -502,20 +502,16 @@ function getImageName($device, $use_database = true, $dir = 'images/os/')
|
||||
|
||||
function renamehost($id, $new, $source = 'console')
|
||||
{
|
||||
global $config;
|
||||
$host = gethostbyid($id);
|
||||
|
||||
$host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id));
|
||||
if (!is_dir(get_rrd_dir($new)) && rename(get_rrd_dir($host), get_rrd_dir($new)) === true) {
|
||||
dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id));
|
||||
dbUpdate(['hostname' => $new, 'ip' => null], 'devices', 'device_id=?', [$id]);
|
||||
log_event("Hostname changed -> $new ($source)", $id, 'system', 3);
|
||||
} else {
|
||||
log_event("Renaming of $host failed", $id, 'system', 5);
|
||||
if (__FILE__ === $_SERVER['SCRIPT_FILE_NAME']) {
|
||||
echo "Renaming of $host failed\n";
|
||||
} else {
|
||||
return "Renaming of $host failed\n";
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
log_event("Renaming of $host failed", $id, 'system', 5);
|
||||
return "Renaming of $host failed\n";
|
||||
}
|
||||
|
||||
function delete_device($id)
|
||||
|
||||
Reference in New Issue
Block a user