Skip to content

Commit

Permalink
Merge pull request #8 from stranden/feature/no-region-support
Browse files Browse the repository at this point in the history
Added support for sites without a region
  • Loading branch information
patrickfnielsen committed Jul 24, 2024
2 parents 18409b3 + 0fefe02 commit 46669eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ session:
# Set default credentials; they should be defined in SecureCRT beforehand under "Preferences -> General -> Credentials"
credential: <username>
# Set a firewall; supports templates and expressions
firewall: "{{ FindTag(device.Tags, 'connection_firewall') ?? null }}"
firewall: "{{ FindTag(device.Tags, 'connection_firewall') ?? ''None'' }}"
# Overrides based on conditions
# target can be one of: path, device_name, description, connection_protocol, credential, firewall
Expand All @@ -117,7 +117,7 @@ session:
value: _Stores/{region_name}/{site_name}
- target: path
condition: "{{ type == 'virtual_machine' }}"
condition: "{{ device_type == 'virtual_machine' }}"
value: _Servers/{region_name}
# device_name override use cases include removing domain names, extra values like .1, and so on
Expand Down
13 changes: 11 additions & 2 deletions internal/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ func (i *InventorySync) getSite(sites []*models.Site, siteID int64) (*models.Sit
return nil, ErrorFailedToFindSite
}

func (i *InventorySync) getRegionName(site *models.Site) string {
if site.Region != nil && site.Region.Name != nil {
return *site.Region.Name
}
return "No Region"
}

func (i *InventorySync) getTenant(device interface{}) string {
nd, ok := device.(*models.DeviceWithConfigContext)
if ok && nd != nil && nd.Tenant != nil {
Expand Down Expand Up @@ -94,6 +101,7 @@ func (i *InventorySync) getDeviceSessions(devices []*models.DeviceWithConfigCont
}

tenant := i.getTenant(device)
regionName := i.getRegionName(site)
ipAddress := strings.Split(*device.PrimaryIp4.Address, "/")[0]
siteAddress := strings.ReplaceAll(site.PhysicalAddress, "\r\n", ", ")
deviceType := device.DeviceType.Display
Expand All @@ -108,7 +116,7 @@ func (i *InventorySync) getDeviceSessions(devices []*models.DeviceWithConfigCont
env.DeviceRole = *device.DeviceRole.Name
env.DeviceType = deviceType
env.DeviceIP = ipAddress
env.RegionName = *site.Region.Name
env.RegionName = regionName
env.TenantName = tenant
env.Site = site
env.SiteName = site.Display
Expand Down Expand Up @@ -141,6 +149,7 @@ func (i *InventorySync) getVirtualMachineSessions(devices []*models.VirtualMachi
}

tenant := i.getTenant(device)
regionName := i.getRegionName(site)
ipAddress := strings.Split(*device.PrimaryIp4.Address, "/")[0]
siteAddress := strings.ReplaceAll(site.PhysicalAddress, "\r\n", ", ")
deviceType := ""
Expand All @@ -159,7 +168,7 @@ func (i *InventorySync) getVirtualMachineSessions(devices []*models.VirtualMachi
env.DeviceRole = "Virtual Machine"
env.DeviceType = deviceType
env.DeviceIP = ipAddress
env.RegionName = *site.Region.Name
env.RegionName = regionName
env.TenantName = tenant
env.Site = site
env.SiteName = site.Display
Expand Down

0 comments on commit 46669eb

Please sign in to comment.