From f7771e4612c3f5a44b5cd3b85eda791a5d4c7935 Mon Sep 17 00:00:00 2001 From: bl4ko Date: Fri, 15 Mar 2024 10:55:24 +0100 Subject: [PATCH] fix: create default site if it doesn't exist yet --- internal/constants/constants.go | 1 + internal/source/common/utils.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/constants/constants.go b/internal/constants/constants.go index cd4d78b..b801be2 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -18,6 +18,7 @@ const ( DefaultOSVersion string = "Generic Version" DefaultManufacturer string = "Generic Manufacturer" DefaultModel string = "Generic Model" + DefaultSite string = "DefaultSite" ) // Default mappings of sources to colors (for tags). diff --git a/internal/source/common/utils.go b/internal/source/common/utils.go index f5ef49d..1a568bc 100644 --- a/internal/source/common/utils.go +++ b/internal/source/common/utils.go @@ -128,7 +128,7 @@ func MatchVlanToTenant(ctx context.Context, nbi *inventory.NetboxInventory, vlan // Function that matches Host from hostName to Site using hostSiteRelations. // -// In case that there is not match or hostSiteRelations is nil, it will return nil. +// In case that there is not match or hostSiteRelations is nil, it will return default site. func MatchHostToSite(ctx context.Context, nbi *inventory.NetboxInventory, hostName string, hostSiteRelations map[string]string) (*objects.Site, error) { if hostSiteRelations == nil { return nil, nil @@ -151,7 +151,7 @@ func MatchHostToSite(ctx context.Context, nbi *inventory.NetboxInventory, hostNa } return site, nil } - return nil, nil + return nbi.SitesIndexByName[constants.DefaultSite], nil } // Function that matches Host from hostName to Tenant using hostTenantRelations.