@itentialopensource/adapter-datadog 0.5.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +1947 -0
  4. package/CHANGELOG.md +48 -22
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +3 -148
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +239 -507
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +380 -261
  14. package/adapterBase.js +843 -397
  15. package/changelogs/CHANGELOG.md +86 -0
  16. package/entities/.generic/action.json +110 -5
  17. package/entities/.generic/schema.json +6 -1
  18. package/error.json +12 -0
  19. package/metadata.json +49 -0
  20. package/package.json +30 -23
  21. package/pronghorn.json +1277 -674
  22. package/propertiesDecorators.json +14 -0
  23. package/propertiesSchema.json +842 -6
  24. package/refs?service=git-upload-pack +0 -0
  25. package/report/adapterInfo.json +10 -0
  26. package/report/updateReport1653677151204.json +120 -0
  27. package/report/updateReport1691508986112.json +120 -0
  28. package/report/updateReport1692202301848.json +120 -0
  29. package/report/updateReport1692203389397.json +120 -0
  30. package/report/updateReport1694469996136.json +120 -0
  31. package/report/updateReport1698423169409.json +120 -0
  32. package/sampleProperties.json +157 -4
  33. package/test/integration/adapterTestBasicGet.js +4 -6
  34. package/test/integration/adapterTestConnectivity.js +91 -42
  35. package/test/integration/adapterTestIntegration.js +158 -104
  36. package/test/unit/adapterBaseTestUnit.js +393 -310
  37. package/test/unit/adapterTestUnit.js +918 -164
  38. package/utils/adapterInfo.js +206 -0
  39. package/utils/addAuth.js +94 -0
  40. package/utils/artifactize.js +1 -1
  41. package/utils/basicGet.js +1 -14
  42. package/utils/checkMigrate.js +1 -1
  43. package/utils/entitiesToDB.js +179 -0
  44. package/utils/findPath.js +1 -1
  45. package/utils/methodDocumentor.js +273 -0
  46. package/utils/modify.js +14 -16
  47. package/utils/packModificationScript.js +2 -2
  48. package/utils/patches2bundledDeps.js +90 -0
  49. package/utils/pre-commit.sh +5 -0
  50. package/utils/removeHooks.js +20 -0
  51. package/utils/taskMover.js +309 -0
  52. package/utils/tbScript.js +129 -53
  53. package/utils/tbUtils.js +152 -35
  54. package/utils/testRunner.js +17 -17
  55. package/utils/troubleshootingAdapter.js +10 -31
  56. package/workflows/README.md +0 -3
package/adapter.js CHANGED
@@ -82,10 +82,15 @@ class Datadog extends AdapterBaseCl {
82
82
  }
83
83
 
84
84
  /**
85
- * @getWorkflowFunctions
86
- */
87
- getWorkflowFunctions(inIgnore) {
88
- let myIgnore = [];
85
+ * @iapGetAdapterWorkflowFunctions
86
+ */
87
+ iapGetAdapterWorkflowFunctions(inIgnore) {
88
+ let myIgnore = [
89
+ 'healthCheck',
90
+ 'iapGetAdapterWorkflowFunctions',
91
+ 'hasEntities',
92
+ 'getAuthorization'
93
+ ];
89
94
  if (!inIgnore && Array.isArray(inIgnore)) {
90
95
  myIgnore = inIgnore;
91
96
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -96,52 +101,44 @@ class Datadog extends AdapterBaseCl {
96
101
  // you can add specific methods that you do not want to be workflow functions to ignore like below
97
102
  // myIgnore.push('myMethodNotInWorkflow');
98
103
 
99
- return super.getWorkflowFunctions(myIgnore);
104
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
100
105
  }
101
106
 
102
107
  /**
103
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
108
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
104
109
  * allows customers to make changes to adapter configuration without having to be on the
105
110
  * file system.
106
111
  *
107
- * @function updateAdapterConfiguration
112
+ * @function iapUpdateAdapterConfiguration
108
113
  * @param {string} configFile - the name of the file being updated (required)
109
114
  * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
110
115
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
111
116
  * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
112
117
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
118
+ * @param {boolean} replace - true to replace entire mock data, false to merge/append
113
119
  * @param {Callback} callback - The results of the call
114
120
  */
115
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
116
- const origin = `${this.id}-adapter-updateAdapterConfiguration`;
121
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
122
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
123
+ const origin = `${this.id}-${meth}`;
117
124
  log.trace(origin);
118
- super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
119
- }
120
125
 
121
- /**
122
- * See if the API path provided is found in this adapter
123
- *
124
- * @function findPath
125
- * @param {string} apiPath - the api path to check on
126
- * @param {Callback} callback - The results of the call
127
- */
128
- findPath(apiPath, callback) {
129
- const origin = `${this.id}-adapter-findPath`;
130
- log.trace(origin);
131
- super.findPath(apiPath, callback);
126
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
132
127
  }
133
128
 
134
129
  /**
135
130
  * @summary Suspends adapter
136
131
  *
137
- * @function suspend
132
+ * @function iapSuspendAdapter
138
133
  * @param {Callback} callback - callback function
139
134
  */
140
- suspend(mode, callback) {
141
- const origin = `${this.id}-adapter-suspend`;
135
+ iapSuspendAdapter(mode, callback) {
136
+ const meth = 'adapter-iapSuspendAdapter';
137
+ const origin = `${this.id}-${meth}`;
142
138
  log.trace(origin);
139
+
143
140
  try {
144
- return super.suspend(mode, callback);
141
+ return super.iapSuspendAdapter(mode, callback);
145
142
  } catch (error) {
146
143
  log.error(`${origin}: ${error}`);
147
144
  return callback(null, error);
@@ -151,14 +148,16 @@ class Datadog extends AdapterBaseCl {
151
148
  /**
152
149
  * @summary Unsuspends adapter
153
150
  *
154
- * @function unsuspend
151
+ * @function iapUnsuspendAdapter
155
152
  * @param {Callback} callback - callback function
156
153
  */
157
- unsuspend(callback) {
158
- const origin = `${this.id}-adapter-unsuspend`;
154
+ iapUnsuspendAdapter(callback) {
155
+ const meth = 'adapter-iapUnsuspendAdapter';
156
+ const origin = `${this.id}-${meth}`;
159
157
  log.trace(origin);
158
+
160
159
  try {
161
- return super.unsuspend(callback);
160
+ return super.iapUnsuspendAdapter(callback);
162
161
  } catch (error) {
163
162
  log.error(`${origin}: ${error}`);
164
163
  return callback(null, error);
@@ -166,31 +165,51 @@ class Datadog extends AdapterBaseCl {
166
165
  }
167
166
 
168
167
  /**
169
- * @summary Get the Adaoter Queue
168
+ * @summary Get the Adapter Queue
170
169
  *
171
- * @function getQueue
170
+ * @function iapGetAdapterQueue
172
171
  * @param {Callback} callback - callback function
173
172
  */
174
- getQueue(callback) {
175
- const origin = `${this.id}-adapter-getQueue`;
173
+ iapGetAdapterQueue(callback) {
174
+ const meth = 'adapter-iapGetAdapterQueue';
175
+ const origin = `${this.id}-${meth}`;
176
176
  log.trace(origin);
177
- return super.getQueue(callback);
177
+
178
+ return super.iapGetAdapterQueue(callback);
179
+ }
180
+
181
+ /* SCRIPT CALLS */
182
+ /**
183
+ * See if the API path provided is found in this adapter
184
+ *
185
+ * @function iapFindAdapterPath
186
+ * @param {string} apiPath - the api path to check on
187
+ * @param {Callback} callback - The results of the call
188
+ */
189
+ iapFindAdapterPath(apiPath, callback) {
190
+ const meth = 'adapter-iapFindAdapterPath';
191
+ const origin = `${this.id}-${meth}`;
192
+ log.trace(origin);
193
+
194
+ super.iapFindAdapterPath(apiPath, callback);
178
195
  }
179
196
 
180
197
  /**
181
198
  * @summary Runs troubleshoot scripts for adapter
182
199
  *
183
- * @function troubleshoot
200
+ * @function iapTroubleshootAdapter
184
201
  * @param {Object} props - the connection, healthcheck and authentication properties
185
202
  *
186
203
  * @param {boolean} persistFlag - whether the adapter properties should be updated
187
204
  * @param {Callback} callback - The results of the call
188
205
  */
189
- troubleshoot(props, persistFlag, callback) {
190
- const origin = `${this.id}-adapter-troubleshoot`;
206
+ iapTroubleshootAdapter(props, persistFlag, callback) {
207
+ const meth = 'adapter-iapTroubleshootAdapter';
208
+ const origin = `${this.id}-${meth}`;
191
209
  log.trace(origin);
210
+
192
211
  try {
193
- return super.troubleshoot(props, persistFlag, this, callback);
212
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
194
213
  } catch (error) {
195
214
  log.error(`${origin}: ${error}`);
196
215
  return callback(null, error);
@@ -200,15 +219,17 @@ class Datadog extends AdapterBaseCl {
200
219
  /**
201
220
  * @summary runs healthcheck script for adapter
202
221
  *
203
- * @function runHealthcheck
222
+ * @function iapRunAdapterHealthcheck
204
223
  * @param {Adapter} adapter - adapter instance to troubleshoot
205
224
  * @param {Callback} callback - callback function
206
225
  */
207
- runHealthcheck(callback) {
208
- const origin = `${this.id}-adapter-runHealthcheck`;
226
+ iapRunAdapterHealthcheck(callback) {
227
+ const meth = 'adapter-iapRunAdapterHealthcheck';
228
+ const origin = `${this.id}-${meth}`;
209
229
  log.trace(origin);
230
+
210
231
  try {
211
- return super.runHealthcheck(this, callback);
232
+ return super.iapRunAdapterHealthcheck(this, callback);
212
233
  } catch (error) {
213
234
  log.error(`${origin}: ${error}`);
214
235
  return callback(null, error);
@@ -218,14 +239,16 @@ class Datadog extends AdapterBaseCl {
218
239
  /**
219
240
  * @summary runs connectivity check script for adapter
220
241
  *
221
- * @function runConnectivity
242
+ * @function iapRunAdapterConnectivity
222
243
  * @param {Callback} callback - callback function
223
244
  */
224
- runConnectivity(callback) {
225
- const origin = `${this.id}-adapter-runConnectivity`;
245
+ iapRunAdapterConnectivity(callback) {
246
+ const meth = 'adapter-iapRunAdapterConnectivity';
247
+ const origin = `${this.id}-${meth}`;
226
248
  log.trace(origin);
249
+
227
250
  try {
228
- return super.runConnectivity(callback);
251
+ return super.iapRunAdapterConnectivity(callback);
229
252
  } catch (error) {
230
253
  log.error(`${origin}: ${error}`);
231
254
  return callback(null, error);
@@ -235,14 +258,16 @@ class Datadog extends AdapterBaseCl {
235
258
  /**
236
259
  * @summary runs basicGet script for adapter
237
260
  *
238
- * @function runBasicGet
261
+ * @function iapRunAdapterBasicGet
239
262
  * @param {Callback} callback - callback function
240
263
  */
241
- runBasicGet(callback) {
242
- const origin = `${this.id}-adapter-runBasicGet`;
264
+ iapRunAdapterBasicGet(callback) {
265
+ const meth = 'adapter-iapRunAdapterBasicGet';
266
+ const origin = `${this.id}-${meth}`;
243
267
  log.trace(origin);
268
+
244
269
  try {
245
- return super.runBasicGet(callback);
270
+ return super.iapRunAdapterBasicGet(callback);
246
271
  } catch (error) {
247
272
  log.error(`${origin}: ${error}`);
248
273
  return callback(null, error);
@@ -250,171 +275,275 @@ class Datadog extends AdapterBaseCl {
250
275
  }
251
276
 
252
277
  /**
253
- * @summary Determines if this adapter supports the specific entity
254
- *
255
- * @function hasEntity
256
- * @param {String} entityType - the entity type to check for
257
- * @param {String/Array} entityId - the specific entity we are looking for
278
+ * @summary moves entites into Mongo DB
258
279
  *
259
- * @param {Callback} callback - An array of whether the adapter can has the
260
- * desired capability or an error
280
+ * @function iapMoveAdapterEntitiesToDB
281
+ * @param {getCallback} callback - a callback function to return the result (Generics)
282
+ * or the error
261
283
  */
262
- hasEntity(entityType, entityId, callback) {
263
- const origin = `${this.id}-adapter-hasEntity`;
284
+ iapMoveAdapterEntitiesToDB(callback) {
285
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
286
+ const origin = `${this.id}-${meth}`;
264
287
  log.trace(origin);
265
288
 
266
- // Make the call -
267
- // verifyCapability(entityType, actionType, entityId, callback)
268
- return this.verifyCapability(entityType, null, entityId, callback);
289
+ try {
290
+ return super.iapMoveAdapterEntitiesToDB(callback);
291
+ } catch (err) {
292
+ log.error(`${origin}: ${err}`);
293
+ return callback(null, err);
294
+ }
269
295
  }
270
296
 
271
297
  /**
272
- * @summary Provides a way for the adapter to tell north bound integrations
273
- * whether the adapter supports type, action and specific entity
298
+ * @summary Deactivate adapter tasks
274
299
  *
275
- * @function verifyCapability
276
- * @param {String} entityType - the entity type to check for
277
- * @param {String} actionType - the action type to check for
278
- * @param {String/Array} entityId - the specific entity we are looking for
279
- *
280
- * @param {Callback} callback - An array of whether the adapter can has the
281
- * desired capability or an error
282
- */
283
- verifyCapability(entityType, actionType, entityId, callback) {
284
- const meth = 'adapterBase-verifyCapability';
285
- const origin = `${this.id}-${meth}`;
286
- log.trace(origin);
287
-
288
- // if caching
289
- if (this.caching) {
290
- // Make the call - verifyCapability(entityType, actionType, entityId, callback)
291
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
292
- if (error) {
293
- return callback(null, error);
294
- }
300
+ * @function iapDeactivateTasks
301
+ *
302
+ * @param {Array} tasks - List of tasks to deactivate
303
+ * @param {Callback} callback
304
+ */
305
+ iapDeactivateTasks(tasks, callback) {
306
+ const meth = 'adapter-iapDeactivateTasks';
307
+ const origin = `${this.id}-${meth}`;
308
+ log.trace(origin);
295
309
 
296
- // if the cache needs to be updated, update and try again
297
- if (results && results[0] === 'needupdate') {
298
- switch (entityType) {
299
- case 'template_entity': {
300
- // if the cache is invalid, update the cache
301
- return this.getEntities(null, null, null, null, (data, err) => {
302
- if (err) {
303
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
304
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
305
- return callback(null, errorObj);
306
- }
310
+ try {
311
+ return super.iapDeactivateTasks(tasks, callback);
312
+ } catch (err) {
313
+ log.error(`${origin}: ${err}`);
314
+ return callback(null, err);
315
+ }
316
+ }
307
317
 
308
- // need to check the cache again since it has been updated
309
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
310
- if (verror) {
311
- return callback(null, verror);
312
- }
318
+ /**
319
+ * @summary Activate adapter tasks that have previously been deactivated
320
+ *
321
+ * @function iapActivateTasks
322
+ *
323
+ * @param {Array} tasks - List of tasks to activate
324
+ * @param {Callback} callback
325
+ */
326
+ iapActivateTasks(tasks, callback) {
327
+ const meth = 'adapter-iapActivateTasks';
328
+ const origin = `${this.id}-${meth}`;
329
+ log.trace(origin);
313
330
 
314
- return this.capabilityResults(vcapable, callback);
315
- });
316
- });
317
- }
318
- default: {
319
- // unsupported entity type
320
- const result = [false];
331
+ try {
332
+ return super.iapActivateTasks(tasks, callback);
333
+ } catch (err) {
334
+ log.error(`${origin}: ${err}`);
335
+ return callback(null, err);
336
+ }
337
+ }
338
+
339
+ /* CACHE CALLS */
340
+ /**
341
+ * @summary Populate the cache for the given entities
342
+ *
343
+ * @function iapPopulateEntityCache
344
+ * @param {String/Array of Strings} entityType - the entity type(s) to populate
345
+ * @param {Callback} callback - whether the cache was updated or not for each entity type
346
+ *
347
+ * @returns status of the populate
348
+ */
349
+ iapPopulateEntityCache(entityTypes, callback) {
350
+ const meth = 'adapter-iapPopulateEntityCache';
351
+ const origin = `${this.id}-${meth}`;
352
+ log.trace(origin);
321
353
 
322
- // put false in array for all entities
323
- if (Array.isArray(entityId)) {
324
- for (let e = 1; e < entityId.length; e += 1) {
325
- result.push(false);
326
- }
327
- }
354
+ try {
355
+ return super.iapPopulateEntityCache(entityTypes, callback);
356
+ } catch (err) {
357
+ log.error(`${origin}: ${err}`);
358
+ return callback(null, err);
359
+ }
360
+ }
328
361
 
329
- return callback(result);
330
- }
331
- }
332
- }
362
+ /**
363
+ * @summary Retrieves data from cache for specified entity type
364
+ *
365
+ * @function iapRetrieveEntitiesCache
366
+ * @param {String} entityType - entity of which to retrieve
367
+ * @param {Object} options - settings of which data to return and how to return it
368
+ * @param {Callback} callback - the data if it was retrieved
369
+ */
370
+ iapRetrieveEntitiesCache(entityType, options, callback) {
371
+ const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
372
+ const origin = `${this.id}-${meth}`;
373
+ log.trace(origin);
333
374
 
334
- // return the results
335
- return this.capabilityResults(results, callback);
336
- });
375
+ try {
376
+ return super.iapRetrieveEntitiesCache(entityType, options, callback);
377
+ } catch (err) {
378
+ log.error(`${origin}: ${err}`);
379
+ return callback(null, err);
337
380
  }
381
+ }
338
382
 
339
- // if no entity id
340
- if (!entityId) {
341
- // need to check the cache again since it has been updated
342
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
343
- if (verror) {
344
- return callback(null, verror);
345
- }
383
+ /* BROKER CALLS */
384
+ /**
385
+ * @summary Determines if this adapter supports any in a list of entities
386
+ *
387
+ * @function hasEntities
388
+ * @param {String} entityType - the entity type to check for
389
+ * @param {Array} entityList - the list of entities we are looking for
390
+ *
391
+ * @param {Callback} callback - A map where the entity is the key and the
392
+ * value is true or false
393
+ */
394
+ hasEntities(entityType, entityList, callback) {
395
+ const meth = 'adapter-hasEntities';
396
+ const origin = `${this.id}-${meth}`;
397
+ log.trace(origin);
346
398
 
347
- return this.capabilityResults(vcapable, callback);
348
- });
399
+ try {
400
+ return super.hasEntities(entityType, entityList, callback);
401
+ } catch (err) {
402
+ log.error(`${origin}: ${err}`);
403
+ return callback(null, err);
349
404
  }
405
+ }
350
406
 
351
- // if not caching
352
- switch (entityType) {
353
- case 'template_entity': {
354
- // need to get the entities to check
355
- return this.getEntities(null, null, null, null, (data, err) => {
356
- if (err) {
357
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
358
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
359
- return callback(null, errorObj);
360
- }
407
+ /**
408
+ * @summary Get Appliance that match the deviceName
409
+ *
410
+ * @function getDevice
411
+ * @param {String} deviceName - the deviceName to find (required)
412
+ *
413
+ * @param {getCallback} callback - a callback function to return the result
414
+ * (appliance) or the error
415
+ */
416
+ getDevice(deviceName, callback) {
417
+ const meth = 'adapter-getDevice';
418
+ const origin = `${this.id}-${meth}`;
419
+ log.trace(origin);
361
420
 
362
- // need to check the cache again since it has been updated
363
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
364
- if (verror) {
365
- return callback(null, verror);
366
- }
421
+ try {
422
+ return super.getDevice(deviceName, callback);
423
+ } catch (err) {
424
+ log.error(`${origin}: ${err}`);
425
+ return callback(null, err);
426
+ }
427
+ }
367
428
 
368
- // is the entity in the list?
369
- const isEntity = this.entityInList(entityId, data.response, callback);
370
- const res = [];
429
+ /**
430
+ * @summary Get Appliances that match the filter
431
+ *
432
+ * @function getDevicesFiltered
433
+ * @param {Object} options - the data to use to filter the appliances (optional)
434
+ *
435
+ * @param {getCallback} callback - a callback function to return the result
436
+ * (appliances) or the error
437
+ */
438
+ getDevicesFiltered(options, callback) {
439
+ const meth = 'adapter-getDevicesFiltered';
440
+ const origin = `${this.id}-${meth}`;
441
+ log.trace(origin);
371
442
 
372
- // not found
373
- for (let i = 0; i < isEntity.length; i += 1) {
374
- if (vcapable) {
375
- res.push(isEntity[i]);
376
- } else {
377
- res.push(false);
378
- }
379
- }
443
+ try {
444
+ return super.getDevicesFiltered(options, callback);
445
+ } catch (err) {
446
+ log.error(`${origin}: ${err}`);
447
+ return callback(null, err);
448
+ }
449
+ }
380
450
 
381
- return callback(res);
382
- });
383
- });
384
- }
385
- default: {
386
- // unsupported entity type
387
- const result = [false];
451
+ /**
452
+ * @summary Gets the status for the provided appliance
453
+ *
454
+ * @function isAlive
455
+ * @param {String} deviceName - the deviceName of the appliance. (required)
456
+ *
457
+ * @param {configCallback} callback - callback function to return the result
458
+ * (appliance isAlive) or the error
459
+ */
460
+ isAlive(deviceName, callback) {
461
+ const meth = 'adapter-isAlive';
462
+ const origin = `${this.id}-${meth}`;
463
+ log.trace(origin);
388
464
 
389
- // put false in array for all entities
390
- if (Array.isArray(entityId)) {
391
- for (let e = 1; e < entityId.length; e += 1) {
392
- result.push(false);
393
- }
394
- }
465
+ try {
466
+ return super.isAlive(deviceName, callback);
467
+ } catch (err) {
468
+ log.error(`${origin}: ${err}`);
469
+ return callback(null, err);
470
+ }
471
+ }
395
472
 
396
- return callback(result);
397
- }
473
+ /**
474
+ * @summary Gets a config for the provided Appliance
475
+ *
476
+ * @function getConfig
477
+ * @param {String} deviceName - the deviceName of the appliance. (required)
478
+ * @param {String} format - the desired format of the config. (optional)
479
+ *
480
+ * @param {configCallback} callback - callback function to return the result
481
+ * (appliance config) or the error
482
+ */
483
+ getConfig(deviceName, format, callback) {
484
+ const meth = 'adapter-getConfig';
485
+ const origin = `${this.id}-${meth}`;
486
+ log.trace(origin);
487
+
488
+ try {
489
+ return super.getConfig(deviceName, format, callback);
490
+ } catch (err) {
491
+ log.error(`${origin}: ${err}`);
492
+ return callback(null, err);
398
493
  }
399
494
  }
400
495
 
401
496
  /**
402
- * @summary Updates the cache for all entities by call the get All entity method
497
+ * @summary Gets the device count from the system
403
498
  *
404
- * @function updateEntityCache
499
+ * @function iapGetDeviceCount
405
500
  *
501
+ * @param {getCallback} callback - callback function to return the result
502
+ * (count) or the error
406
503
  */
407
- updateEntityCache() {
408
- const origin = `${this.id}-adapter-updateEntityCache`;
504
+ iapGetDeviceCount(callback) {
505
+ const meth = 'adapter-iapGetDeviceCount';
506
+ const origin = `${this.id}-${meth}`;
409
507
  log.trace(origin);
410
508
 
411
- if (this.caching) {
412
- // if the cache is invalid, update the cache
413
- this.getEntities(null, null, null, null, (data, err) => {
414
- if (err) {
415
- log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
416
- }
417
- });
509
+ try {
510
+ return super.iapGetDeviceCount(callback);
511
+ } catch (err) {
512
+ log.error(`${origin}: ${err}`);
513
+ return callback(null, err);
514
+ }
515
+ }
516
+
517
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
518
+ /**
519
+ * Makes the requested generic call
520
+ *
521
+ * @function iapExpandedGenericAdapterRequest
522
+ * @param {Object} metadata - metadata for the call (optional).
523
+ * Can be a stringified Object.
524
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
525
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
526
+ * @param {Object} pathVars - the parameters to be put within the url path (optional).
527
+ * Can be a stringified Object.
528
+ * @param {Object} queryData - the parameters to be put on the url (optional).
529
+ * Can be a stringified Object.
530
+ * @param {Object} requestBody - the body to add to the request (optional).
531
+ * Can be a stringified Object.
532
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
533
+ * Can be a stringified Object.
534
+ * @param {getCallback} callback - a callback function to return the result (Generics)
535
+ * or the error
536
+ */
537
+ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
538
+ const meth = 'adapter-iapExpandedGenericAdapterRequest';
539
+ const origin = `${this.id}-${meth}`;
540
+ log.trace(origin);
541
+
542
+ try {
543
+ return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
544
+ } catch (err) {
545
+ log.error(`${origin}: ${err}`);
546
+ return callback(null, err);
418
547
  }
419
548
  }
420
549
 
@@ -438,94 +567,84 @@ class Datadog extends AdapterBaseCl {
438
567
  const origin = `${this.id}-${meth}`;
439
568
  log.trace(origin);
440
569
 
441
- if (this.suspended && this.suspendMode === 'error') {
442
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
443
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
444
- return callback(null, errorObj);
570
+ try {
571
+ return super.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
572
+ } catch (err) {
573
+ log.error(`${origin}: ${err}`);
574
+ return callback(null, err);
445
575
  }
576
+ }
446
577
 
447
- /* HERE IS WHERE YOU VALIDATE DATA */
448
- if (uriPath === undefined || uriPath === null || uriPath === '') {
449
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
450
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
451
- return callback(null, errorObj);
452
- }
453
- if (restMethod === undefined || restMethod === null || restMethod === '') {
454
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
455
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
456
- return callback(null, errorObj);
457
- }
578
+ /**
579
+ * Makes the requested generic call with no base path or version
580
+ *
581
+ * @function genericAdapterRequestNoBasePath
582
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
583
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
584
+ * @param {Object} queryData - the parameters to be put on the url (optional).
585
+ * Can be a stringified Object.
586
+ * @param {Object} requestBody - the body to add to the request (optional).
587
+ * Can be a stringified Object.
588
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
589
+ * Can be a stringified Object.
590
+ * @param {getCallback} callback - a callback function to return the result (Generics)
591
+ * or the error
592
+ */
593
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
594
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
595
+ const origin = `${this.id}-${meth}`;
596
+ log.trace(origin);
458
597
 
459
- /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
460
- // remove any leading / and split the uripath into path variables
461
- let myPath = uriPath;
462
- while (myPath.indexOf('/') === 0) {
463
- myPath = myPath.substring(1);
598
+ try {
599
+ return super.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
600
+ } catch (err) {
601
+ log.error(`${origin}: ${err}`);
602
+ return callback(null, err);
464
603
  }
465
- const pathVars = myPath.split('/');
466
- const queryParamsAvailable = queryData;
467
- const queryParams = {};
468
- const bodyVars = requestBody;
604
+ }
469
605
 
470
- // loop in template. long callback arg name to avoid identifier conflicts
471
- Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
472
- if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
473
- && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
474
- queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
475
- }
476
- });
606
+ /* INVENTORY CALLS */
607
+ /**
608
+ * @summary run the adapter lint script to return the results.
609
+ *
610
+ * @function iapRunAdapterLint
611
+ * @param {Callback} callback - callback function
612
+ */
613
+ iapRunAdapterLint(callback) {
614
+ const meth = 'adapter-iapRunAdapterLint';
615
+ const origin = `${this.id}-${meth}`;
616
+ log.trace(origin);
477
617
 
478
- // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
479
- const reqObj = {
480
- payload: bodyVars,
481
- uriPathVars: pathVars,
482
- uriQuery: queryParams,
483
- uriOptions: {}
484
- };
485
- // add headers if provided
486
- if (addlHeaders) {
487
- reqObj.addlHeaders = addlHeaders;
488
- }
618
+ return super.iapRunAdapterLint(callback);
619
+ }
489
620
 
490
- // determine the call and return flag
491
- let action = 'getGenerics';
492
- let returnF = true;
493
- if (restMethod.toUpperCase() === 'POST') {
494
- action = 'createGeneric';
495
- } else if (restMethod.toUpperCase() === 'PUT') {
496
- action = 'updateGeneric';
497
- } else if (restMethod.toUpperCase() === 'PATCH') {
498
- action = 'patchGeneric';
499
- } else if (restMethod.toUpperCase() === 'DELETE') {
500
- action = 'deleteGeneric';
501
- returnF = false;
502
- }
621
+ /**
622
+ * @summary run the adapter test scripts (baseunit and unit) to return the results.
623
+ * can not run integration as there can be implications with that.
624
+ *
625
+ * @function iapRunAdapterTests
626
+ * @param {Callback} callback - callback function
627
+ */
628
+ iapRunAdapterTests(callback) {
629
+ const meth = 'adapter-iapRunAdapterTests';
630
+ const origin = `${this.id}-${meth}`;
631
+ log.trace(origin);
503
632
 
504
- try {
505
- // Make the call -
506
- // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
507
- return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
508
- // if we received an error or their is no response on the results
509
- // return an error
510
- if (irReturnError) {
511
- /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
512
- return callback(null, irReturnError);
513
- }
514
- if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
515
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
516
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
517
- return callback(null, errorObj);
518
- }
633
+ return super.iapRunAdapterTests(callback);
634
+ }
519
635
 
520
- /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
521
- // return the response
522
- return callback(irReturnData, null);
523
- });
524
- } catch (ex) {
525
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
526
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
527
- return callback(null, errorObj);
528
- }
636
+ /**
637
+ * @summary provide inventory information abbout the adapter
638
+ *
639
+ * @function iapGetAdapterInventory
640
+ * @param {Callback} callback - callback function
641
+ */
642
+ iapGetAdapterInventory(callback) {
643
+ const meth = 'adapter-iapGetAdapterInventory';
644
+ const origin = `${this.id}-${meth}`;
645
+ log.trace(origin);
646
+
647
+ return super.iapGetAdapterInventory(callback);
529
648
  }
530
649
 
531
650
  /**