summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/backends/idoit-backend.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/external-backends/backends/idoit-backend.js')
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js63
1 files changed, 34 insertions, 29 deletions
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
}