From f62621eb36c51985e74030a58132d2fcec2f879d Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 17 Apr 2019 21:59:49 +0200 Subject: [server/external-backends] Fix for the update client mehtod (unnecessary idoit calls) --- server/lib/external-backends/backendhelper.js | 1 + .../external-backends/backends/idoit-backend.js | 63 ++++++++++++---------- .../external-backends/backends/infoblox-backend.js | 1 + 3 files changed, 36 insertions(+), 29 deletions(-) (limited to 'server/lib') diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js index 5bbde55..87b2696 100644 --- a/server/lib/external-backends/backendhelper.js +++ b/server/lib/external-backends/backendhelper.js @@ -86,6 +86,7 @@ async function updateClient (client) { conflict.createObject({ objectType: 'GROUP', objectId: element.id }) } } else if (elements.length === 1) tmpClient['parentId'] = elements[0].backend_x_group.externalId + else if (elements.length === 0) tmpClient['parentId'] = null } try { let updateClient = await instance.updateClient(backend.credentials, tmpClient) diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js index 7b1db4d..350fc85 100644 --- a/server/lib/external-backends/backends/idoit-backend.js +++ b/server/lib/external-backends/backends/idoit-backend.js @@ -374,17 +374,19 @@ class IdoitBackend extends ExternalBackends { bodies.push(this.getBody('cmdb.category.save', params, 'update_uuid')) } - // Update the object. Location - let paramsLocation = { - 'object': client.id, - 'objID': client.id, - 'category': 'C__CATG__LOCATION', - 'data': { - 'parent': client.parentId ? client.parentId : null - }, - 'apikey': c.apikey + if (client.parentId) { + // Update the object. Location + let paramsLocation = { + 'object': client.id, + 'objID': client.id, + 'category': 'C__CATG__LOCATION', + 'data': { + 'parent': client.parentId + }, + 'apikey': c.apikey + } + bodies.push(this.getBody('cmdb.category.save', paramsLocation, 'update_parent')) } - bodies.push(this.getBody('cmdb.category.save', paramsLocation, 'update_parent')) // Update the object. Model data. if (client.system) { @@ -416,22 +418,23 @@ class IdoitBackend extends ExternalBackends { for (let index in client.networks) { const network = client.networks[index] - - // Update ip addresses - let paramsIp = { - 'object': client.id, - 'objID': client.id, - 'category': 'C__CATG__IP', - 'data': { - 'ipv4_address': network.ip, - 'hostname': network.hostname, - 'domain': network.domain, - 'net': network.net - }, - 'apikey': c.apikey + if (network.ip && network.hostname, network.domain) { + // Update ip addresses + let paramsIp = { + 'object': client.id, + 'objID': client.id, + 'category': 'C__CATG__IP', + 'data': { + 'ipv4_address': network.ip, + 'hostname': network.hostname, + 'domain': network.domain, + 'net': network.net + }, + 'apikey': c.apikey + } + if (ips[0].result.length > index) paramsIp.entry = parseInt(ips[0].result[index].id) + bodies.push(this.getBody('cmdb.category.save', paramsIp, 'update_ip')) } - if (ips[0].result.length > index) paramsIp.entry = parseInt(ips[0].result[index].id) - bodies.push(this.getBody('cmdb.category.save', paramsIp, 'update_ip')) // Update mac addresses if (network.mac) { @@ -553,10 +556,13 @@ class IdoitBackend extends ExternalBackends { } } - const requestUpdate = await this.axiosRequest(c.url, bodies, headers) - requestResults.push(requestUpdate) + if (bodies.length > 0) { + const requestUpdate = await this.axiosRequest(c.url, bodies, headers) + requestResults.push(requestUpdate) + + if (requestUpdate.error) return requestUpdate + } - if (requestUpdate.error) return requestUpdate // 10 is the idoit object id for clients. // 5 is the idoit object id for servers. let type = 0 @@ -567,7 +573,6 @@ class IdoitBackend extends ExternalBackends { success: true, id: client.id, type: type, - // response: requestUpdate response: requestResults } diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js index d32936b..cc7f149 100644 --- a/server/lib/external-backends/backends/infoblox-backend.js +++ b/server/lib/external-backends/backends/infoblox-backend.js @@ -305,6 +305,7 @@ class InfobloxBackend extends ExternalBackends { 'name': 'zeft9043.public.ads.uni-freiburg.de' }) */ + return result } } -- cgit v1.2.3-55-g7522