Skip to content

Commit 60a4807

Browse files
Merge pull request #12 from cscaglioned42/D42-31465
D42-31465 - GitHub Freshservice - Asset type not being set correctly for Hosts Fixed host devices from D42 becoming Unix Server and Windows Server asset types in Freshservice instead of the Host asset type. This issue was being caused because we were checking for Unix Server and Windows Server before checking for Host. Updated sync to be able to correct these incorrect asset types.
2 parents a23e92e + c13065f commit 60a4807

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

d42_sd_sync.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
RELATIONSHIPS_JOB_WAIT_SECONDS = int(math.ceil(RELATIONSHIP_BATCH_SIZE / float(RELATIONSHIPS_CREATED_PER_SECOND)))
3030
ASSET_TYPE_BUSINESS_SERVICE = "Business Service"
3131
ASSET_TYPE_SERVER = "Server"
32+
ASSET_TYPE_UNIX_SERVER = "Unix Server"
33+
ASSET_TYPE_WINDOWS_SERVER = "Windows Server"
34+
ASSET_TYPE_HOST = "Host"
3235

3336
parser = argparse.ArgumentParser(description="freshservice")
3437

@@ -227,14 +230,25 @@ def update_objects_from_server(sources, _target, mapping):
227230

228231
asset_type_fields_map = dict()
229232
server_asset_type_id = find_object_id_in_map(asset_types_map, ASSET_TYPE_SERVER)
233+
unix_server_asset_type_id = find_object_id_in_map(asset_types_map, ASSET_TYPE_UNIX_SERVER)
234+
windows_server_asset_type_id = find_object_id_in_map(asset_types_map, ASSET_TYPE_WINDOWS_SERVER)
235+
host_asset_type_id = find_object_id_in_map(asset_types_map, ASSET_TYPE_HOST)
230236

231237
for source in sources:
232238
error_skip = False
233239
while True:
234240
try:
235241
existing_object = find_object_in_map(existing_objects_map, source["name"])
236-
if existing_object is None or existing_object["asset_type_id"] == server_asset_type_id:
237-
asset_type_id = find_object_id_in_map(asset_types_map, source["asset_type"])
242+
source_asset_type_id = find_object_id_in_map(asset_types_map, source["asset_type"])
243+
244+
# If we have an existing asset with an asset type of Windows Server or Unix Server and
245+
# we determined that the asset type should be Host, we will update it to Host since previously
246+
# we were bringing in host devices as Windows Server or Unix Server asset types instead of the
247+
# Host asset type.
248+
if existing_object is None or existing_object["asset_type_id"] == server_asset_type_id or \
249+
(existing_object["asset_type_id"] in [unix_server_asset_type_id, windows_server_asset_type_id] and \
250+
source_asset_type_id == host_asset_type_id):
251+
asset_type_id = source_asset_type_id
238252
else:
239253
asset_type_id = existing_object["asset_type_id"]
240254

@@ -363,6 +377,9 @@ def update_objects_from_server(sources, _target, mapping):
363377
data["agent_id"] = existing_object["agent_id"]
364378
updated_asset_id = freshservice.update_asset(data, existing_object["display_id"])
365379
logger.info("updated existing asset %d" % updated_asset_id)
380+
# If the asset type changed for this asset, update it in the cache.
381+
if existing_object["asset_type_id"] != asset_type_id:
382+
existing_object["asset_type_id"] = asset_type_id
366383

367384
break
368385
except FreshServiceDuplicateValueError:

mapping.xml.sample

+8-8
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@
187187

188188
select view_device_v2.*,
189189
case
190+
WHEN view_device_v2.virtual_host AND lower(view_device_v2.os_name) like '%esxi%' THEN 'VMware VCenter Host'
191+
WHEN view_device_v2.virtual_host THEN 'Host'
190192
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.physicalsubtype) = 'laptop' THEN 'Laptop'
191193
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.physicalsubtype) = 'workstation' THEN 'Desktop'
192194
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.physicalsubtype) = 'network printer' THEN 'Printer'
@@ -198,8 +200,6 @@
198200
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.os_name) similar to '%(unix|z/os|z os|zos|hp-ux|os400|os/400|os 400|linux|amazon|ubuntu|centos|redhat|debian|sles|suse|gentoo|oracle|freebsd|rhel|red hat|fedora|alma|rocky|arch)%' THEN 'Unix Server'
199201
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.os_name) similar to '%(aix)%' THEN 'AIX Server'
200202
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.os_name) similar to '%(solaris|sunos|sun os)%' THEN 'Solaris Server'
201-
WHEN view_device_v2.virtual_host AND lower(view_device_v2.os_name) like '%esxi%' THEN 'VMware VCenter Host'
202-
WHEN view_device_v2.virtual_host THEN 'Host'
203203
WHEN lower(view_device_v2.type) = 'virtual' AND lower(view_device_v2.virtualsubtype) = 'vmware' THEN 'VMware VCenter VM'
204204
WHEN lower(view_device_v2.type) = 'virtual' AND lower(view_device_v2.virtualsubtype) = 'amazon ec2 instance' THEN 'AWS VM'
205205
WHEN lower(view_device_v2.type) = 'virtual' AND lower(view_device_v2.virtualsubtype) = 'azure virtual machine' THEN 'Azure VM'
@@ -716,14 +716,14 @@
716716

717717
select view_device_v1.*,
718718
case
719+
WHEN view_device_v1.virtual_host AND lower(view_device_v1.os_name) like '%esxi%' THEN 'VMware VCenter Host'
720+
WHEN view_device_v1.virtual_host THEN 'Host'
719721
WHEN lower(view_device_v1.os_name) similar to '%(f5|netscaler)%' THEN 'Load Balancer'
720722
WHEN view_device_v1.network_device THEN 'Switch'
721723
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(windows|microsoft)%' AND lower(view_device_v1.os_name) like '%server%' THEN 'Windows Server'
722724
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(unix|z/os|z os|zos|hp-ux|os400|os/400|os 400|linux|amazon|ubuntu|centos|redhat|debian|sles|suse|gentoo|oracle|freebsd|rhel|red hat|fedora|alma|rocky|arch)%' THEN 'Unix Server'
723725
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(aix)%' THEN 'AIX Server'
724726
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(solaris|sunos|sun os)%' THEN 'Solaris Server'
725-
WHEN view_device_v1.virtual_host AND lower(view_device_v1.os_name) like '%esxi%' THEN 'VMware VCenter Host'
726-
WHEN view_device_v1.virtual_host THEN 'Host'
727727
WHEN lower(view_device_v1.type) = 'virtual' AND lower(view_device_v1.virtual_subtype) = 'vmware' THEN 'VMware VCenter VM'
728728
WHEN lower(view_device_v1.type) = 'virtual' AND lower(view_device_v1.virtual_subtype) = 'amazon ec2 instance' THEN 'AWS VM'
729729
WHEN lower(view_device_v1.type) = 'virtual' AND lower(view_device_v1.virtual_subtype) = 'azure virtual machine' THEN 'Azure VM'
@@ -1135,6 +1135,8 @@
11351135
(
11361136
SELECT
11371137
case
1138+
WHEN view_device_v2.virtual_host AND lower(view_device_v2.os_name) like '%esxi%' THEN 'VMware VCenter Host'
1139+
WHEN view_device_v2.virtual_host THEN 'Host'
11381140
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.physicalsubtype) = 'laptop' THEN 'Computer'
11391141
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.physicalsubtype) = 'workstation' THEN 'Computer'
11401142
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.physicalsubtype) = 'network printer' THEN 'Printer'
@@ -1146,8 +1148,6 @@
11461148
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.os_name) similar to '%(unix|z/os|z os|zos|hp-ux|os400|os/400|os 400|linux|amazon|ubuntu|centos|redhat|debian|sles|suse|gentoo|oracle|freebsd|rhel|red hat|fedora|alma|rocky|arch)%' THEN 'Computer'
11471149
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.os_name) similar to '%(aix)%' THEN 'Computer'
11481150
WHEN lower(view_device_v2.type) = 'physical' AND lower(view_device_v2.os_name) similar to '%(solaris|sunos|sun os)%' THEN 'Computer'
1149-
WHEN view_device_v2.virtual_host AND lower(view_device_v2.os_name) like '%esxi%' THEN 'VMware VCenter Host'
1150-
WHEN view_device_v2.virtual_host THEN 'Host'
11511151
WHEN lower(view_device_v2.type) = 'virtual' AND lower(view_device_v2.virtualsubtype) = 'vmware' THEN 'Virtual Machine'
11521152
WHEN lower(view_device_v2.type) = 'virtual' AND lower(view_device_v2.virtualsubtype) = 'amazon ec2 instance' THEN 'Virtual Machine'
11531153
WHEN lower(view_device_v2.type) = 'virtual' AND lower(view_device_v2.virtualsubtype) = 'azure virtual machine' THEN 'Virtual Machine'
@@ -1179,14 +1179,14 @@
11791179
(
11801180
SELECT
11811181
case
1182+
WHEN view_device_v1.virtual_host AND lower(view_device_v1.os_name) like '%esxi%' THEN 'VMware VCenter Host'
1183+
WHEN view_device_v1.virtual_host THEN 'Host'
11821184
WHEN lower(view_device_v1.os_name) similar to '%(f5|netscaler)%' THEN 'Load Balancer'
11831185
WHEN view_device_v1.network_device THEN 'Switch'
11841186
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(windows|microsoft)%' AND lower(view_device_v1.os_name) like '%server%' THEN 'Computer'
11851187
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(unix|z/os|z os|zos|hp-ux|os400|os/400|os 400|linux|amazon|ubuntu|centos|redhat|debian|sles|suse|gentoo|oracle|freebsd|rhel|red hat|fedora|alma|rocky|arch)%' THEN 'Computer'
11861188
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(aix)%' THEN 'Computer'
11871189
WHEN lower(view_device_v1.type) = 'physical' AND lower(view_device_v1.os_name) similar to '%(solaris|sunos|sun os)%' THEN 'Computer'
1188-
WHEN view_device_v1.virtual_host AND lower(view_device_v1.os_name) like '%esxi%' THEN 'VMware VCenter Host'
1189-
WHEN view_device_v1.virtual_host THEN 'Host'
11901190
WHEN lower(view_device_v1.type) = 'virtual' AND lower(view_device_v1.virtual_subtype) = 'vmware' THEN 'Virtual Machine'
11911191
WHEN lower(view_device_v1.type) = 'virtual' AND lower(view_device_v1.virtual_subtype) = 'amazon ec2 instance' THEN 'Virtual Machine'
11921192
WHEN lower(view_device_v1.type) = 'virtual' AND lower(view_device_v1.virtual_subtype) = 'azure virtual machine' THEN 'Virtual Machine'

0 commit comments

Comments
 (0)