mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Update renamehost include more logging (#15280)
Added logging output to renamehost() if an RRD Folder already exists for the new hostname. Before: NOT renamed: Renaming of 10.4.0.146 failed Now: NOT renamed: Renaming of 10.4.0.146 failed due to existing RRD folder forDEVICE
This commit is contained in:
@@ -108,8 +108,15 @@ function getImageName($device, $use_database = true, $dir = 'images/os/')
|
||||
function renamehost($id, $new, $source = 'console')
|
||||
{
|
||||
$host = gethostbyid($id);
|
||||
$new_rrd_dir = Rrd::dirFromHost($new);
|
||||
|
||||
if (! is_dir(Rrd::dirFromHost($new)) && rename(Rrd::dirFromHost($host), Rrd::dirFromHost($new)) === true) {
|
||||
if (is_dir($new_rrd_dir)) {
|
||||
log_event("Renaming of $host failed due to existing RRD folder for $new", $id, 'system', 5);
|
||||
|
||||
return "Renaming of $host failed due to existing RRD folder for $new\n";
|
||||
}
|
||||
|
||||
if (! is_dir($new_rrd_dir) && rename(Rrd::dirFromHost($host), $new_rrd_dir) === true) {
|
||||
dbUpdate(['hostname' => $new, 'ip' => null], 'devices', 'device_id=?', [$id]);
|
||||
log_event("Hostname changed -> $new ($source)", $id, 'system', 3);
|
||||
|
||||
|
Reference in New Issue
Block a user