summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends
diff options
context:
space:
mode:
authorJannik Schönartz2019-04-01 02:43:48 +0200
committerJannik Schönartz2019-04-01 02:43:48 +0200
commitc10e0aab20ce8d49e6f7a8e31f1c4a3b4c86260d (patch)
treeffc41a353b03919a1ac148fa3e17931ebf68856d /server/lib/external-backends
parent[server/ipxeconfigs] add more responses (diff)
downloadbas-c10e0aab20ce8d49e6f7a8e31f1c4a3b4c86260d.tar.gz
bas-c10e0aab20ce8d49e6f7a8e31f1c4a3b4c86260d.tar.xz
bas-c10e0aab20ce8d49e6f7a8e31f1c4a3b4c86260d.zip
[server/external-backends] Add direct sync in idoit for some functions (create client, add/remove client to/from groups)
Diffstat (limited to 'server/lib/external-backends')
-rw-r--r--server/lib/external-backends/backendhelper.js2
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js69
2 files changed, 59 insertions, 12 deletions
diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js
index a088074..d8d4b24 100644
--- a/server/lib/external-backends/backendhelper.js
+++ b/server/lib/external-backends/backendhelper.js
@@ -43,7 +43,7 @@ async function addClient (client) {
backend.addMappedClients(clientDb, { through: { externalId: addClient.id, externalType: addClient.type } })
}
- if (addClient.error && addClient.error !== 'NOT_IMPLEMENTED_EXCEPTION') log({ category: 'BACKEND_ERROR', description: `[${addClient.backendId}] ${addClient.error}: ${addClient.message}`, clientId: client.id })
+ if (addClient.error && addClient.error !== 'NOT_IMPLEMENTED_EXCEPTION') log({ category: 'ERROR_BACKEND', description: `[${addClient.backendId}] ${addClient.error}: ${addClient.message}`, clientId: client.id })
result.push(addClient)
}
return result
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 601c9f9..833c9b3 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -374,18 +374,17 @@ class IdoitBackend extends ExternalBackends {
}
// Update the object. Location
- if (client.parentId) {
- let params = {
- 'object': client.id,
- 'objID': client.id,
- 'category': 'C__CATG__LOCATION',
- 'data': {
- 'parent': client.parentId
- },
- 'apikey': c.apikey
- }
- bodies.push(this.getBody('cmdb.category.save', params, 'update_parent'))
+ let paramsLocation = {
+ 'object': client.id,
+ 'objID': client.id,
+ 'category': 'C__CATG__LOCATION',
+ 'data': {
+ 'parent': client.parentId ? client.parentId : null
+ },
+ 'apikey': c.apikey
}
+ console.log(paramsLocation)
+ bodies.push(this.getBody('cmdb.category.save', paramsLocation, 'update_parent'))
// Update the object. Model data.
if (client.system) {
@@ -403,6 +402,54 @@ class IdoitBackend extends ExternalBackends {
bodies.push(this.getBody('cmdb.category.save', params, 'update_model'))
}
+ // Update networks
+ if (client.networks) {
+ let parmReadNetwork = {
+ 'object': client.id,
+ 'objID': client.id,
+ 'category': 'C__CATG__IP',
+ 'apikey': c.apikey
+ }
+ const ips = await this.axiosRequest(c.url, [this.getBody('cmdb.category.read', parmReadNetwork, 'read_ips')], headers)
+ parmReadNetwork.category = 'C__CATG__NETWORK_PORT'
+ const macs = await this.axiosRequest(c.url, [this.getBody('cmdb.category.read', parmReadNetwork, 'read_macs')], headers)
+
+ 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 (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) {
+ let paramsMac = {
+ 'object': client.id,
+ 'objID': client.id,
+ 'category': 'C__CATG__NETWORK_PORT',
+ 'data': {
+ 'mac': network.mac
+ },
+ 'apikey': c.apikey
+ }
+ if (macs[0].result.length > index) paramsMac.entry = parseInt(macs[0].result[index].id)
+ bodies.push(this.getBody('cmdb.category.save', paramsMac, 'update_mac'))
+ }
+ }
+ }
+
// Update the object. CPU data.
// TODO: Delete cpu if exists?
if (client.cpus) {