From 55d60a323b0e228133ae4d6f261b8fb4f3637e38 Mon Sep 17 00:00:00 2001 From: bl4ko Date: Tue, 16 Apr 2024 15:24:10 +0200 Subject: [PATCH] fix: adding vlan tenant relation for fortigate and paloalto, also prefix have same tenant as vlan --- README.md | 8 +++++++- internal/source/fortigate/fortigate_sync.go | 6 ++++++ internal/source/paloalto/paloalto_sync.go | 13 ++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 619cb048..8b4ff9a3 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,9 @@ source: hostTenantRelations: - .* = MyTenant hostSiteRelations: - - .* = MySite + - .* = MyTenant + hostTenantRelations: + - .* = MyTenant - name: pa-uk type: paloalto @@ -151,6 +153,10 @@ source: password: passw0rd hostTenantRelations: - .* = MyTenant + hostSiteRelations: + - .* = MySite + vlanTenantRelations: + - .* = MyTenant - name: dnacenter type: dnac diff --git a/internal/source/fortigate/fortigate_sync.go b/internal/source/fortigate/fortigate_sync.go index 5d43546d..03afbc83 100644 --- a/internal/source/fortigate/fortigate_sync.go +++ b/internal/source/fortigate/fortigate_sync.go @@ -174,6 +174,10 @@ func (fs *FortigateSource) SyncInterfaces(nbi *inventory.NetboxInventory) error if err != nil { return fmt.Errorf("match vlan to group: %s", err) } + vlanTenant, err := common.MatchVlanToTenant(fs.Ctx, nbi, vlanName, fs.VlanTenantRelations) + if err != nil { + return fmt.Errorf("match vlan to tenant: %s", err) + } NBVlan, err := nbi.AddVlan(fs.Ctx, &objects.Vlan{ NetboxObject: objects.NetboxObject{ Tags: fs.SourceTags, @@ -181,6 +185,7 @@ func (fs *FortigateSource) SyncInterfaces(nbi *inventory.NetboxInventory) error Status: &objects.VlanStatusActive, Name: vlanName, Vid: vlanID, + Tenant: vlanTenant, Group: vlanGroup, }) if err != nil { @@ -196,6 +201,7 @@ func (fs *FortigateSource) SyncInterfaces(nbi *inventory.NetboxInventory) error } _, err = nbi.AddPrefix(fs.Ctx, &objects.Prefix{ Prefix: prefix, + Tenant: NBVlan.Tenant, Vlan: NBVlan, }) if err != nil { diff --git a/internal/source/paloalto/paloalto_sync.go b/internal/source/paloalto/paloalto_sync.go index e5465f91..31f135e3 100644 --- a/internal/source/paloalto/paloalto_sync.go +++ b/internal/source/paloalto/paloalto_sync.go @@ -156,10 +156,15 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error var subifaceMode *objects.InterfaceMode if subIface.Tag != 0 { // Extract Vlan - vlanGroup, err := common.MatchVlanToGroup(pas.Ctx, nbi, fmt.Sprintf("Vlan%d", subIface.Tag), pas.VlanGroupRelations) + vlanName := fmt.Sprintf("Vlan%d", subIface.Tag) + vlanGroup, err := common.MatchVlanToGroup(pas.Ctx, nbi, vlanName, pas.VlanGroupRelations) if err != nil { return fmt.Errorf("match vlan to group: %s", err) } + vlanTenant, err := common.MatchVlanToTenant(pas.Ctx, nbi, vlanName, pas.VlanTenantRelations) + if err != nil { + return fmt.Errorf("match vlan to tenant: %s", err) + } subIfaceVlan, err = nbi.AddVlan(pas.Ctx, &objects.Vlan{ NetboxObject: objects.NetboxObject{ Tags: pas.SourceTags, @@ -168,6 +173,7 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error Status: &objects.VlanStatusActive, Name: fmt.Sprintf("Vlan%d", subIface.Tag), Vid: subIface.Tag, + Tenant: vlanTenant, Group: vlanGroup, }) if err != nil { @@ -228,8 +234,13 @@ func (pas *PaloAltoSource) syncIPs(nbi *inventory.NetboxInventory, nbIface *obje if err != nil { pas.Logger.Warningf(pas.Ctx, "extract prefix from address: %s", err) } else { + var prefixTenant *objects.Tenant + if prefixVlan != nil { + prefixTenant = prefixVlan.Tenant + } _, err = nbi.AddPrefix(pas.Ctx, &objects.Prefix{ Prefix: prefix, + Tenant: prefixTenant, Vlan: prefixVlan, }) if err != nil {