Auto-IPAM: laitteen hallintaosoite varataan automaattisesti
Kun laitteelle tallennetaan hallintaosoite (IP), IPAM:iin luodaan automaattisesti varattu IP-merkintä laitteen nimellä ja sijainnilla. Jos IP on jo IPAM:issa, päivitetään se varatuksi laitteelle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
42
api.php
42
api.php
@@ -1750,6 +1750,48 @@ switch ($action) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dbSaveDevice($companyId, $device);
|
dbSaveDevice($companyId, $device);
|
||||||
|
// Auto-IPAM: varaa hallintaosoite laitteelle IPAM:iin
|
||||||
|
$mgmtIp = $device['hallintaosoite'];
|
||||||
|
if ($mgmtIp) {
|
||||||
|
// Normalisoi: poista mahdollinen /32 suffix
|
||||||
|
$cleanIp = explode('/', $mgmtIp)[0];
|
||||||
|
// Etsi löytyykö jo IPAM:ista
|
||||||
|
$ipamEntries = dbLoadIpam($companyId);
|
||||||
|
$existing = null;
|
||||||
|
foreach ($ipamEntries as $ie) {
|
||||||
|
$ieClean = explode('/', $ie['verkko'])[0];
|
||||||
|
if ($ieClean === $cleanIp && $ie['tyyppi'] === 'ip') {
|
||||||
|
$existing = $ie;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($existing) {
|
||||||
|
// Päivitä olemassa oleva: merkitse varatuksi laitteelle
|
||||||
|
$existing['tila'] = 'varattu';
|
||||||
|
$existing['nimi'] = $device['nimi'];
|
||||||
|
$existing['site_id'] = $device['site_id'];
|
||||||
|
$existing['muokattu'] = date('Y-m-d H:i:s');
|
||||||
|
$existing['muokkaaja'] = currentUser();
|
||||||
|
dbSaveIpam($companyId, $existing);
|
||||||
|
} else {
|
||||||
|
// Luo uusi IPAM-merkintä
|
||||||
|
$newIpam = [
|
||||||
|
'id' => generateId(),
|
||||||
|
'tyyppi' => 'ip',
|
||||||
|
'nimi' => $device['nimi'],
|
||||||
|
'verkko' => $cleanIp,
|
||||||
|
'vlan_id' => null,
|
||||||
|
'site_id' => $device['site_id'],
|
||||||
|
'tila' => 'varattu',
|
||||||
|
'asiakas' => '',
|
||||||
|
'lisatiedot' => 'Automaattinen varaus laitteelta: ' . $device['nimi'],
|
||||||
|
'luotu' => date('Y-m-d H:i:s'),
|
||||||
|
'muokattu' => null,
|
||||||
|
'muokkaaja' => currentUser(),
|
||||||
|
];
|
||||||
|
dbSaveIpam($companyId, $newIpam);
|
||||||
|
}
|
||||||
|
}
|
||||||
dbAddLog($companyId, currentUser(), $isNew ? 'device_create' : 'device_update', $device['id'], $device['nimi'], ($isNew ? 'Lisäsi' : 'Muokkasi') . ' laitteen');
|
dbAddLog($companyId, currentUser(), $isNew ? 'device_create' : 'device_update', $device['id'], $device['nimi'], ($isNew ? 'Lisäsi' : 'Muokkasi') . ' laitteen');
|
||||||
echo json_encode($device);
|
echo json_encode($device);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user