summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/backends
diff options
context:
space:
mode:
authorJannik Schönartz2019-03-20 05:22:50 +0100
committerJannik Schönartz2019-03-20 05:22:50 +0100
commit67d1402c75e562af34058d0021cf6a14b5588d22 (patch)
treed977ee4fce3adbf0de27b4372c5589ece81e54d9 /server/lib/external-backends/backends
parent[server/registration] Add client with json instead of parameters (ipxe) (diff)
downloadbas-67d1402c75e562af34058d0021cf6a14b5588d22.tar.gz
bas-67d1402c75e562af34058d0021cf6a14b5588d22.tar.xz
bas-67d1402c75e562af34058d0021cf6a14b5588d22.zip
[server/registration/backends] Rework addClient and updateClient to receive json
Add idoit workaround for saving floats again Rework the grepSystemInfo bash script to match the new api
Diffstat (limited to 'server/lib/external-backends/backends')
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js132
1 files changed, 81 insertions, 51 deletions
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 8c1a4c3..ce7680a 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -170,7 +170,7 @@ class IdoitBackend extends ExternalBackends {
if (headers.error) return headers
let params = {
'apikey': c.apikey,
- 'title': client.title,
+ 'title': client.name,
'purpose': client.purpose === 'Pool PC' ? 7 : undefined,
'categories': {}
}
@@ -218,7 +218,7 @@ class IdoitBackend extends ExternalBackends {
'apikey': c.apikey
}
const bodyMac = this.getBody('cmdb.category.save', paramsMac, 'add_mac_address')
- const requestMac = await this.axiosRequest(c.url, [bodyMac], headers)
+ await this.axiosRequest(c.url, [bodyMac], headers)
}
// Purpose for Clients:
@@ -247,9 +247,11 @@ class IdoitBackend extends ExternalBackends {
if (headers.error) return headers
let bodies = []
+ // workaround for the fucking idoit shit. -.-
+ let requestResults = []
// Update title of the object
- if (client.title) bodies.push(this.getBody('cmdb.object.update', { 'id': client.id, 'title': client.title, 'apikey': c.apikey }, 'update_title'))
+ if (client.name) bodies.push(this.getBody('cmdb.object.update', { 'id': client.id, 'title': client.name, 'apikey': c.apikey }, 'update_title'))
// 'object' should be 'objID' but there is a fucking bug in the idoit api. Soo let's add both parameters because else it will break when they fix it.
// Update the productid to the uuid.
@@ -298,95 +300,123 @@ class IdoitBackend extends ExternalBackends {
// Update the object. CPU data.
// TODO: Delete cpu if exists?
- if (client.cpu) {
- let params = {
- 'object': client.id,
- 'objID': client.id,
- 'category': 'C__CATG__CPU',
- 'data': {
- 'category_id': 1,
- 'manufacturer': client.cpu.manufacturer,
- 'title': client.cpu.model,
- 'type': client.cpu.type,
- 'frequency': client.cpu.frequency,
- 'frequency_unit': 3,
- 'cores': client.cpu.cores
- },
- 'apikey': c.apikey
+ if (client.cpus) {
+ let counter = 1
+ for (let cpu of client.cpus) {
+ // Add KB and TB
+ if (cpu.unit === 'MB') cpu.unit = 2
+ else if (cpu.unit === 'GB') cpu.unit = 3
+
+ let params = {
+ 'object': client.id,
+ 'objID': client.id,
+ 'category': 'C__CATG__CPU',
+ 'data': {
+ 'manufacturer': cpu.manufacturer,
+ 'title': cpu.model,
+ 'type': cpu.type,
+ 'frequency': parseFloat(cpu.frequency),
+ 'frequency_unit': 3,
+ 'cores': parseInt(cpu.cores)
+ },
+ 'apikey': c.apikey
+ }
+
+ counter++
+ // WORKAROUND
+ // bodies.push(this.getBody('cmdb.category.save', params, 'create_cpu_' + counter))
+ const a = await this.axiosRequest(c.url, [this.getBody('cmdb.category.save', params, 'create_cpu_' + counter)], headers)
+ requestResults.push(a)
}
- bodies.push(this.getBody('cmdb.category.save', params, 'update_cpu'))
}
// Update the object. Ram data.
if (client.ram) {
let counter = 1
- for (var memory in client.ram) {
- var mem = client.ram[memory]
- var ramId = 'create_memory_' + counter
- if (mem.unit === 'MB') mem.capacity = mem.capacity / 1024
+ for (let module of client.ram.modules) {
+ // Add KB and TB
+ if (module.unit === 'MB') module.unit = 2
+ else if (module.unit === 'GB') module.unit = 3
- // 2 = MB
- // 3 = GB
let params = {
'object': client.id,
'objID': client.id,
'category': 'C__CATG__MEMORY',
'data': {
- 'title': mem.title,
- 'manufacturer': mem.manufacturer,
- 'type': mem.type,
- 'capacity': mem.capacity,
- 'unit': 3
+ 'title': module.type,
+ 'manufacturer': module.manufacturer,
+ 'type': module.type,
+ 'capacity': parseFloat(module.capacity),
+ 'unit': module.unit
},
'apikey': c.apikey
}
counter++
- bodies.push(this.getBody('cmdb.category.save', params, ramId))
+ // WORKAROUND
+ // bodies.push(this.getBody('cmdb.category.save', params, 'create_memory_' + counter))
+ const a = await this.axiosRequest(c.url, [this.getBody('cmdb.category.save', params, 'create_memory_' + counter)], headers)
+ requestResults.push(a)
}
}
// Update the object. Drive data.
if (client.drives) {
let counter = 1
- for (var drive in client.drives) {
- var d = client.drives[drive]
- var driveId = 'create_drive_' + counter
-
+ for (let drive of client.drives) {
// UNIT
- var unit = 0
- if (d.unit === 'GB') unit = 3
- else if (d.unit === 'TB') unit = 4
- else if (d.unit === 'MB') unit = 2
- else if (d.unit === 'KB') unit = 1
- else if (d.unit === 'B') unit = 0
+ if (drive.unit === 'GB') drive.unit = 3
+ else if (drive.unit === 'MB') drive.unit = 2
+ else if (drive.unit === 'TB') drive.unit = 4
+ else if (drive.unit === 'KB') drive.unit = 1
+ else if (drive.unit === 'B') drive.unit = 0
+
+ if (drive.type === 'Solid State Device') drive.type = 'SSD'
+ else if (drive.type === '5400 rpm') drive.type = 'Hard disk'
+ else if (drive.type === '7200 rpm') drive.type = 'Hard disk'
+ else if (drive.type === '') drive.type = 'Hard disk'
let params = {
'object': client.id,
'objID': client.id,
'category': 'C__CATG__STORAGE_DEVICE',
'data': {
- 'title': d.model,
- 'type': d.type,
+ 'category_id': counter,
+ 'title': drive.model,
+ 'type': drive.type,
// 'manufacturer': ,
// 'model': ,
- 'capacity': d.capacity,
- 'unit': unit,
- 'serial': d.serial,
- 'connected': d.connection
+ 'capacity': parseFloat(drive.capacity),
+ 'unit': drive.unit,
+ 'serial': drive.serial,
+ 'connected': drive.connection
},
'apikey': c.apikey
}
- bodies.push(this.getBody('cmdb.category.save', params, driveId))
+
+ counter++
+ // WORKAROUND
+ // bodies.push(this.getBody('cmdb.category.save', params, 'create_drive_' + counter))
+ const a = await this.axiosRequest(c.url, [this.getBody('cmdb.category.save', params, 'create_drive_' + counter)], headers)
+ requestResults.push(a)
}
}
const requestUpdate = await this.axiosRequest(c.url, bodies, headers)
+ requestResults.push(requestUpdate)
+
+ if (requestUpdate.error) return requestUpdate
// 10 is the idoit object id for clients.
- var result = {
+ // 5 is the idoit object id for servers.
+ let type = 0
+ if (client.type === 'CLIENT') type = 10
+ else if (client.type === 'SERVER') type = 5
+
+ const result = {
success: true,
id: client.id,
- type: 10,
- response: requestUpdate
+ type: type,
+ // response: requestUpdate
+ response: requestResults
}
return result