@itentialopensource/adapter-servicenow 2.3.0 → 2.4.1

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 (44) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +169 -0
  4. package/CHANGELOG.md +56 -42
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +88 -74
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +225 -502
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +29 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +349 -58
  14. package/adapterBase.js +1022 -246
  15. package/entities/.generic/action.json +110 -5
  16. package/entities/.generic/schema.json +6 -1
  17. package/entities/.system/action.json +3 -2
  18. package/error.json +12 -0
  19. package/package.json +20 -13
  20. package/pronghorn.json +642 -378
  21. package/propertiesDecorators.json +14 -0
  22. package/propertiesSchema.json +436 -0
  23. package/refs?service=git-upload-pack +0 -0
  24. package/report/adapterInfo.json +10 -0
  25. package/report/updateReport1653406010548.json +120 -0
  26. package/sampleProperties.json +94 -2
  27. package/storage/metrics.json +2205 -0
  28. package/test/integration/adapterTestBasicGet.js +2 -2
  29. package/test/integration/adapterTestIntegration.js +29 -103
  30. package/test/unit/adapterBaseTestUnit.js +35 -27
  31. package/test/unit/adapterTestUnit.js +641 -113
  32. package/utils/adapterInfo.js +206 -0
  33. package/utils/addAuth.js +94 -0
  34. package/utils/basicGet.js +1 -14
  35. package/utils/entitiesToDB.js +179 -0
  36. package/utils/modify.js +1 -1
  37. package/utils/packModificationScript.js +1 -1
  38. package/utils/patches2bundledDeps.js +90 -0
  39. package/utils/pre-commit.sh +3 -0
  40. package/utils/removeHooks.js +20 -0
  41. package/utils/tbScript.js +43 -22
  42. package/utils/tbUtils.js +126 -29
  43. package/utils/testRunner.js +16 -16
  44. package/utils/troubleshootingAdapter.js +2 -26
package/SUMMARY.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Overview
2
+
3
+ This adapter is used to integrate the Itential Automation Platform (IAP) with the Servicenow System. The API that was used to build the adapter for Servicenow is usually available in the report directory of this adapter. The adapter utilizes the Servicenow API to provide the integrations that are deemed pertinent to IAP. The ReadMe file is intended to provide information on this adapter it is generated from various other Markdown files.
4
+
5
+ >**Note**: It is possible that some integrations will be supported through the Servicenow adapter while other integrations will not. If you need additional API calls, you can use the Update capabilities provided by the Adapter Builder or request Itential to add them if the Adapter is an Itential opensourced adapter.
6
+
7
+ Itential provides information on all of its product adapters in the Customer Knowledge Base. Information in the <a href="https://itential.atlassian.net/servicedesk/customer/portals" target="_blank">Customer Knowledge Base</a> is consistently maintained and goes through documentation reviews. As a result, it should be the first place to go for information.
8
+
9
+ For opensourced and custom built adapters, the ReadMe is a starting point to understand what you have built, provide the information for you to be able to update the adapter, and assist you with deploying the adapter into IAP.
package/SYSTEMINFO.md ADDED
@@ -0,0 +1,29 @@
1
+ # Adapter for ServiceNow
2
+
3
+ Vendor: ServiceNow
4
+ Homepage: https://www.servicenow.com/
5
+
6
+ Product: ServiceNow
7
+ Product Page: https://www.servicenow.com/
8
+
9
+ ## Introduction
10
+
11
+ ## Additional Product Documentation
12
+
13
+ The ServiceNow adapter from Itential is used to integrate the Itential Automation Platform (IAP) with the ServiceNow API, enabling you to use the ServiceNow database via Table API. Along with Table API, there are several other REST API endpoints that provide the ability to interact and integrate with ServiceNow. ServiceNow is a platform that provides IT Service Management (ITSM) and IT Asset Management (ITAM) for IT services, operations and business management to improve SLAs and automate IT service applications and processes.
14
+
15
+ With this adapter you have the ability to perform operations with Service Now’s Databases such as:
16
+
17
+ - Create, Modify Permissions for, and Complete Change Requests: Prior to IAP, making a change requires approval and scheduling. Itential can automatically create a change request in ServiceNow to go through the Change Management process. Itential can verify that the change request has been approved. If the change is not approved Itential will wait and check again at a later time. Once Itential has finished making the change, it can complete the change request in ServiceNow.
18
+
19
+ - Open and Close Tickets: When there is a failure or error in the Itential job that needs to be addressed by a ServiceNow team, Itential can automatically create the ticket in ServiceNow. When Itential successfully completes a job resolving a ServiceNow ticket, it can automatically close that ticket.
20
+
21
+ - Add, Manage, and Remove Inventory Devices: When Itential turns up a new device on the network, it can add the device to the ServiceNow CMDB, request that ServiceNow discover the new device, or remove the device from the ServiceNow CMDB.
22
+
23
+ - Update and Close a Service Catalog Request: Once an Itential job is created from a ServiceNow Service Catalog Request or Request Item, Itential can update that request with information as the job is being worked. Once an Itential job is created from a ServiceNow Service Catalog Request or Request Item, Itential can close that request when the job is completed.
24
+
25
+ - Send Notifications to ServiceNow Assignees and Approvers: When pertinent actions or activities occur in a job on the Itential platform, Itential can send notifications to assignees on related ServiceNow tickets.
26
+
27
+ - Change ServiceNow Assignees: Itential can change the assignees of a ServiceNow ticket (e.g. Incident, Problem, Change, Request, etc.) based on what has occurred in the Itential job.
28
+
29
+ - Create and Retrieve Knowledge Base Articles: For any IAP job that is related to a ServiceNow ticket (e.g. Incident, Problem, etc.), Itential can create a knowledge base article with information on what was done in the job to resolve that particular issue. When an Itential job has an issue, IAP can retrieve knowledge base articles that may help to resolve the issue.
@@ -0,0 +1,47 @@
1
+ ## Troubleshoot
2
+
3
+ Run `npm run troubleshoot` to start the interactive troubleshooting process. The command allows you to verify and update connection, authentication as well as healthcheck configuration. After that it will test these properties by sending HTTP request to the endpoint. If the tests pass, it will persist these changes into IAP.
4
+
5
+ You also have the option to run individual commands to perform specific test:
6
+
7
+ - `npm run healthcheck` will perform a healthcheck request of with current setting.
8
+ - `npm run basicget` will perform some non-parameter GET request with current setting.
9
+ - `npm run connectivity` will perform networking diagnostics of the adatper endpoint.
10
+
11
+ ### Connectivity Issues
12
+
13
+ 1. You can run the adapter troubleshooting script which will check connectivity, run the healthcheck and run basic get calls.
14
+
15
+ ```bash
16
+ npm run troubleshoot
17
+ ```
18
+
19
+ 2. Verify the adapter properties are set up correctly.
20
+
21
+ ```text
22
+ Go into the Itential Platform GUI and verify/update the properties
23
+ ```
24
+
25
+ 3. Verify there is connectivity between the Itential Platform Server and Servicenow Server.
26
+
27
+ ```text
28
+ ping the ip address of Servicenow server
29
+ try telnet to the ip address port of Servicenow
30
+ execute a curl command to the other system
31
+ ```
32
+
33
+ 4. Verify the credentials provided for Servicenow.
34
+
35
+ ```text
36
+ login to Servicenow using the provided credentials
37
+ ```
38
+
39
+ 5. Verify the API of the call utilized for Servicenow Healthcheck.
40
+
41
+ ```text
42
+ Go into the Itential Platform GUI and verify/update the properties
43
+ ```
44
+
45
+ ### Functional Issues
46
+
47
+ Adapter logs are located in `/var/log/pronghorn`. In older releases of the Itential Platform, there is a `pronghorn.log` file which contains logs for all of the Itential Platform. In newer versions, adapters can be configured to log into their own files.
package/adapter.js CHANGED
@@ -82,10 +82,18 @@ class Servicenow 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
+ 'iapHasAdapterEntity',
92
+ 'iapVerifyAdapterCapability',
93
+ 'iapUpdateAdapterEntityCache',
94
+ 'hasEntities',
95
+ 'getAuthorization'
96
+ ];
89
97
  if (!inIgnore && Array.isArray(inIgnore)) {
90
98
  myIgnore = inIgnore;
91
99
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -96,15 +104,15 @@ class Servicenow extends AdapterBaseCl {
96
104
  // you can add specific methods that you do not want to be workflow functions to ignore like below
97
105
  // myIgnore.push('myMethodNotInWorkflow');
98
106
 
99
- return super.getWorkflowFunctions(myIgnore);
107
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
100
108
  }
101
109
 
102
110
  /**
103
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
111
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
104
112
  * allows customers to make changes to adapter configuration without having to be on the
105
113
  * file system.
106
114
  *
107
- * @function updateAdapterConfiguration
115
+ * @function iapUpdateAdapterConfiguration
108
116
  * @param {string} configFile - the name of the file being updated (required)
109
117
  * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
110
118
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
@@ -112,36 +120,42 @@ class Servicenow extends AdapterBaseCl {
112
120
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
113
121
  * @param {Callback} callback - The results of the call
114
122
  */
115
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
116
- const origin = `${this.id}-adapter-updateAdapterConfiguration`;
123
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
124
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
125
+ const origin = `${this.id}-${meth}`;
117
126
  log.trace(origin);
118
- super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
127
+
128
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
119
129
  }
120
130
 
121
131
  /**
122
132
  * See if the API path provided is found in this adapter
123
133
  *
124
- * @function findPath
134
+ * @function iapFindAdapterPath
125
135
  * @param {string} apiPath - the api path to check on
126
136
  * @param {Callback} callback - The results of the call
127
137
  */
128
- findPath(apiPath, callback) {
129
- const origin = `${this.id}-adapter-findPath`;
138
+ iapFindAdapterPath(apiPath, callback) {
139
+ const meth = 'adapter-iapFindAdapterPath';
140
+ const origin = `${this.id}-${meth}`;
130
141
  log.trace(origin);
131
- super.findPath(apiPath, callback);
142
+
143
+ super.iapFindAdapterPath(apiPath, callback);
132
144
  }
133
145
 
134
146
  /**
135
147
  * @summary Suspends adapter
136
148
  *
137
- * @function suspend
149
+ * @function iapSuspendAdapter
138
150
  * @param {Callback} callback - callback function
139
151
  */
140
- suspend(mode, callback) {
141
- const origin = `${this.id}-adapter-suspend`;
152
+ iapSuspendAdapter(mode, callback) {
153
+ const meth = 'adapter-iapSuspendAdapter';
154
+ const origin = `${this.id}-${meth}`;
142
155
  log.trace(origin);
156
+
143
157
  try {
144
- return super.suspend(mode, callback);
158
+ return super.iapSuspendAdapter(mode, callback);
145
159
  } catch (error) {
146
160
  log.error(`${origin}: ${error}`);
147
161
  return callback(null, error);
@@ -151,14 +165,16 @@ class Servicenow extends AdapterBaseCl {
151
165
  /**
152
166
  * @summary Unsuspends adapter
153
167
  *
154
- * @function unsuspend
168
+ * @function iapUnsuspendAdapter
155
169
  * @param {Callback} callback - callback function
156
170
  */
157
- unsuspend(callback) {
158
- const origin = `${this.id}-adapter-unsuspend`;
171
+ iapUnsuspendAdapter(callback) {
172
+ const meth = 'adapter-iapUnsuspendAdapter';
173
+ const origin = `${this.id}-${meth}`;
159
174
  log.trace(origin);
175
+
160
176
  try {
161
- return super.unsuspend(callback);
177
+ return super.iapUnsuspendAdapter(callback);
162
178
  } catch (error) {
163
179
  log.error(`${origin}: ${error}`);
164
180
  return callback(null, error);
@@ -168,29 +184,33 @@ class Servicenow extends AdapterBaseCl {
168
184
  /**
169
185
  * @summary Get the Adaoter Queue
170
186
  *
171
- * @function getQueue
187
+ * @function iapGetAdapterQueue
172
188
  * @param {Callback} callback - callback function
173
189
  */
174
- getQueue(callback) {
175
- const origin = `${this.id}-adapter-getQueue`;
190
+ iapGetAdapterQueue(callback) {
191
+ const meth = 'adapter-iapGetAdapterQueue';
192
+ const origin = `${this.id}-${meth}`;
176
193
  log.trace(origin);
177
- return super.getQueue(callback);
194
+
195
+ return super.iapGetAdapterQueue(callback);
178
196
  }
179
197
 
180
198
  /**
181
199
  * @summary Runs troubleshoot scripts for adapter
182
200
  *
183
- * @function troubleshoot
201
+ * @function iapTroubleshootAdapter
184
202
  * @param {Object} props - the connection, healthcheck and authentication properties
185
203
  *
186
204
  * @param {boolean} persistFlag - whether the adapter properties should be updated
187
205
  * @param {Callback} callback - The results of the call
188
206
  */
189
- troubleshoot(props, persistFlag, callback) {
190
- const origin = `${this.id}-adapter-troubleshoot`;
207
+ iapTroubleshootAdapter(props, persistFlag, callback) {
208
+ const meth = 'adapter-iapTroubleshootAdapter';
209
+ const origin = `${this.id}-${meth}`;
191
210
  log.trace(origin);
211
+
192
212
  try {
193
- return super.troubleshoot(props, persistFlag, this, callback);
213
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
194
214
  } catch (error) {
195
215
  log.error(`${origin}: ${error}`);
196
216
  return callback(null, error);
@@ -200,15 +220,17 @@ class Servicenow extends AdapterBaseCl {
200
220
  /**
201
221
  * @summary runs healthcheck script for adapter
202
222
  *
203
- * @function runHealthcheck
223
+ * @function iapRunAdapterHealthcheck
204
224
  * @param {Adapter} adapter - adapter instance to troubleshoot
205
225
  * @param {Callback} callback - callback function
206
226
  */
207
- runHealthcheck(callback) {
208
- const origin = `${this.id}-adapter-runHealthcheck`;
227
+ iapRunAdapterHealthcheck(callback) {
228
+ const meth = 'adapter-iapRunAdapterHealthcheck';
229
+ const origin = `${this.id}-${meth}`;
209
230
  log.trace(origin);
231
+
210
232
  try {
211
- return super.runHealthcheck(this, callback);
233
+ return super.iapRunAdapterHealthcheck(this, callback);
212
234
  } catch (error) {
213
235
  log.error(`${origin}: ${error}`);
214
236
  return callback(null, error);
@@ -218,14 +240,16 @@ class Servicenow extends AdapterBaseCl {
218
240
  /**
219
241
  * @summary runs connectivity check script for adapter
220
242
  *
221
- * @function runConnectivity
243
+ * @function iapRunAdapterConnectivity
222
244
  * @param {Callback} callback - callback function
223
245
  */
224
- runConnectivity(callback) {
225
- const origin = `${this.id}-adapter-runConnectivity`;
246
+ iapRunAdapterConnectivity(callback) {
247
+ const meth = 'adapter-iapRunAdapterConnectivity';
248
+ const origin = `${this.id}-${meth}`;
226
249
  log.trace(origin);
250
+
227
251
  try {
228
- return super.runConnectivity(callback);
252
+ return super.iapRunAdapterConnectivity(callback);
229
253
  } catch (error) {
230
254
  log.error(`${origin}: ${error}`);
231
255
  return callback(null, error);
@@ -235,44 +259,67 @@ class Servicenow extends AdapterBaseCl {
235
259
  /**
236
260
  * @summary runs basicGet script for adapter
237
261
  *
238
- * @function runBasicGet
262
+ * @function iapRunAdapterBasicGet
239
263
  * @param {Callback} callback - callback function
240
264
  */
241
- runBasicGet(callback) {
242
- const origin = `${this.id}-adapter-runBasicGet`;
265
+ iapRunAdapterBasicGet(callback) {
266
+ const meth = 'adapter-iapRunAdapterBasicGet';
267
+ const origin = `${this.id}-${meth}`;
243
268
  log.trace(origin);
269
+
244
270
  try {
245
- return super.runBasicGet(callback);
271
+ return super.iapRunAdapterBasicGet(callback);
246
272
  } catch (error) {
247
273
  log.error(`${origin}: ${error}`);
248
274
  return callback(null, error);
249
275
  }
250
276
  }
251
277
 
278
+ /**
279
+ * @summary moves entites into Mongo DB
280
+ *
281
+ * @function iapMoveAdapterEntitiesToDB
282
+ * @param {getCallback} callback - a callback function to return the result (Generics)
283
+ * or the error
284
+ */
285
+ iapMoveAdapterEntitiesToDB(callback) {
286
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
287
+ const origin = `${this.id}-${meth}`;
288
+ log.trace(origin);
289
+
290
+ try {
291
+ return super.iapMoveAdapterEntitiesToDB(callback);
292
+ } catch (err) {
293
+ log.error(`${origin}: ${err}`);
294
+ return callback(null, err);
295
+ }
296
+ }
297
+
298
+ /* BROKER CALLS */
252
299
  /**
253
300
  * @summary Determines if this adapter supports the specific entity
254
301
  *
255
- * @function hasEntity
302
+ * @function iapHasAdapterEntity
256
303
  * @param {String} entityType - the entity type to check for
257
304
  * @param {String/Array} entityId - the specific entity we are looking for
258
305
  *
259
306
  * @param {Callback} callback - An array of whether the adapter can has the
260
307
  * desired capability or an error
261
308
  */
262
- hasEntity(entityType, entityId, callback) {
263
- const origin = `${this.id}-adapter-hasEntity`;
309
+ iapHasAdapterEntity(entityType, entityId, callback) {
310
+ const origin = `${this.id}-adapter-iapHasAdapterEntity`;
264
311
  log.trace(origin);
265
312
 
266
313
  // Make the call -
267
- // verifyCapability(entityType, actionType, entityId, callback)
268
- return this.verifyCapability(entityType, null, entityId, callback);
314
+ // iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
315
+ return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
269
316
  }
270
317
 
271
318
  /**
272
319
  * @summary Provides a way for the adapter to tell north bound integrations
273
320
  * whether the adapter supports type, action and specific entity
274
321
  *
275
- * @function verifyCapability
322
+ * @function iapVerifyAdapterCapability
276
323
  * @param {String} entityType - the entity type to check for
277
324
  * @param {String} actionType - the action type to check for
278
325
  * @param {String/Array} entityId - the specific entity we are looking for
@@ -280,15 +327,15 @@ class Servicenow extends AdapterBaseCl {
280
327
  * @param {Callback} callback - An array of whether the adapter can has the
281
328
  * desired capability or an error
282
329
  */
283
- verifyCapability(entityType, actionType, entityId, callback) {
284
- const meth = 'adapterBase-verifyCapability';
330
+ iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
331
+ const meth = 'adapterBase-iapVerifyAdapterCapability';
285
332
  const origin = `${this.id}-${meth}`;
286
333
  log.trace(origin);
287
334
 
288
335
  // if caching
289
336
  if (this.caching) {
290
- // Make the call - verifyCapability(entityType, actionType, entityId, callback)
291
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
337
+ // Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
338
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
292
339
  if (error) {
293
340
  return callback(null, error);
294
341
  }
@@ -306,7 +353,7 @@ class Servicenow extends AdapterBaseCl {
306
353
  }
307
354
 
308
355
  // need to check the cache again since it has been updated
309
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
356
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
310
357
  if (verror) {
311
358
  return callback(null, verror);
312
359
  }
@@ -339,7 +386,7 @@ class Servicenow extends AdapterBaseCl {
339
386
  // if no entity id
340
387
  if (!entityId) {
341
388
  // need to check the cache again since it has been updated
342
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
389
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
343
390
  if (verror) {
344
391
  return callback(null, verror);
345
392
  }
@@ -360,7 +407,7 @@ class Servicenow extends AdapterBaseCl {
360
407
  }
361
408
 
362
409
  // need to check the cache again since it has been updated
363
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
410
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
364
411
  if (verror) {
365
412
  return callback(null, verror);
366
413
  }
@@ -401,11 +448,11 @@ class Servicenow extends AdapterBaseCl {
401
448
  /**
402
449
  * @summary Updates the cache for all entities by call the get All entity method
403
450
  *
404
- * @function updateEntityCache
451
+ * @function iapUpdateAdapterEntityCache
405
452
  *
406
453
  */
407
- updateEntityCache() {
408
- const origin = `${this.id}-adapter-updateEntityCache`;
454
+ iapUpdateAdapterEntityCache() {
455
+ const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
409
456
  log.trace(origin);
410
457
 
411
458
  if (this.caching) {
@@ -418,6 +465,140 @@ class Servicenow extends AdapterBaseCl {
418
465
  }
419
466
  }
420
467
 
468
+ /**
469
+ * @summary Determines if this adapter supports any in a list of entities
470
+ *
471
+ * @function hasEntities
472
+ * @param {String} entityType - the entity type to check for
473
+ * @param {Array} entityList - the list of entities we are looking for
474
+ *
475
+ * @param {Callback} callback - A map where the entity is the key and the
476
+ * value is true or false
477
+ */
478
+ hasEntities(entityType, entityList, callback) {
479
+ const meth = 'adapter-hasEntities';
480
+ const origin = `${this.id}-${meth}`;
481
+ log.trace(origin);
482
+
483
+ try {
484
+ return super.hasEntities(entityType, entityList, callback);
485
+ } catch (err) {
486
+ log.error(`${origin}: ${err}`);
487
+ return callback(null, err);
488
+ }
489
+ }
490
+
491
+ /**
492
+ * @summary Get Appliance that match the deviceName
493
+ *
494
+ * @function getDevice
495
+ * @param {String} deviceName - the deviceName to find (required)
496
+ *
497
+ * @param {getCallback} callback - a callback function to return the result
498
+ * (appliance) or the error
499
+ */
500
+ getDevice(deviceName, callback) {
501
+ const meth = 'adapter-getDevice';
502
+ const origin = `${this.id}-${meth}`;
503
+ log.trace(origin);
504
+
505
+ try {
506
+ return super.getDevice(deviceName, callback);
507
+ } catch (err) {
508
+ log.error(`${origin}: ${err}`);
509
+ return callback(null, err);
510
+ }
511
+ }
512
+
513
+ /**
514
+ * @summary Get Appliances that match the filter
515
+ *
516
+ * @function getDevicesFiltered
517
+ * @param {Object} options - the data to use to filter the appliances (optional)
518
+ *
519
+ * @param {getCallback} callback - a callback function to return the result
520
+ * (appliances) or the error
521
+ */
522
+ getDevicesFiltered(options, callback) {
523
+ const meth = 'adapter-getDevicesFiltered';
524
+ const origin = `${this.id}-${meth}`;
525
+ log.trace(origin);
526
+
527
+ try {
528
+ return super.getDevicesFiltered(options, callback);
529
+ } catch (err) {
530
+ log.error(`${origin}: ${err}`);
531
+ return callback(null, err);
532
+ }
533
+ }
534
+
535
+ /**
536
+ * @summary Gets the status for the provided appliance
537
+ *
538
+ * @function isAlive
539
+ * @param {String} deviceName - the deviceName of the appliance. (required)
540
+ *
541
+ * @param {configCallback} callback - callback function to return the result
542
+ * (appliance isAlive) or the error
543
+ */
544
+ isAlive(deviceName, callback) {
545
+ const meth = 'adapter-isAlive';
546
+ const origin = `${this.id}-${meth}`;
547
+ log.trace(origin);
548
+
549
+ try {
550
+ return super.isAlive(deviceName, callback);
551
+ } catch (err) {
552
+ log.error(`${origin}: ${err}`);
553
+ return callback(null, err);
554
+ }
555
+ }
556
+
557
+ /**
558
+ * @summary Gets a config for the provided Appliance
559
+ *
560
+ * @function getConfig
561
+ * @param {String} deviceName - the deviceName of the appliance. (required)
562
+ * @param {String} format - the desired format of the config. (optional)
563
+ *
564
+ * @param {configCallback} callback - callback function to return the result
565
+ * (appliance config) or the error
566
+ */
567
+ getConfig(deviceName, format, callback) {
568
+ const meth = 'adapter-getConfig';
569
+ const origin = `${this.id}-${meth}`;
570
+ log.trace(origin);
571
+
572
+ try {
573
+ return super.getConfig(deviceName, format, callback);
574
+ } catch (err) {
575
+ log.error(`${origin}: ${err}`);
576
+ return callback(null, err);
577
+ }
578
+ }
579
+
580
+ /**
581
+ * @summary Gets the device count from the system
582
+ *
583
+ * @function iapGetDeviceCount
584
+ *
585
+ * @param {getCallback} callback - callback function to return the result
586
+ * (count) or the error
587
+ */
588
+ iapGetDeviceCount(callback) {
589
+ const meth = 'adapter-iapGetDeviceCount';
590
+ const origin = `${this.id}-${meth}`;
591
+ log.trace(origin);
592
+
593
+ try {
594
+ return super.iapGetDeviceCount(callback);
595
+ } catch (err) {
596
+ log.error(`${origin}: ${err}`);
597
+ return callback(null, err);
598
+ }
599
+ }
600
+
601
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
421
602
  /**
422
603
  * Makes the requested generic call
423
604
  *
@@ -528,6 +709,116 @@ class Servicenow extends AdapterBaseCl {
528
709
  }
529
710
  }
530
711
 
712
+ /**
713
+ * Makes the requested generic call with no base path or version
714
+ *
715
+ * @function genericAdapterRequestNoBasePath
716
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
717
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
718
+ * @param {Object} queryData - the parameters to be put on the url (optional).
719
+ * Can be a stringified Object.
720
+ * @param {Object} requestBody - the body to add to the request (optional).
721
+ * Can be a stringified Object.
722
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
723
+ * Can be a stringified Object.
724
+ * @param {getCallback} callback - a callback function to return the result (Generics)
725
+ * or the error
726
+ */
727
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
728
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
729
+ const origin = `${this.id}-${meth}`;
730
+ log.trace(origin);
731
+
732
+ if (this.suspended && this.suspendMode === 'error') {
733
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
734
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
735
+ return callback(null, errorObj);
736
+ }
737
+
738
+ /* HERE IS WHERE YOU VALIDATE DATA */
739
+ if (uriPath === undefined || uriPath === null || uriPath === '') {
740
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
741
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
742
+ return callback(null, errorObj);
743
+ }
744
+ if (restMethod === undefined || restMethod === null || restMethod === '') {
745
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
746
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
747
+ return callback(null, errorObj);
748
+ }
749
+
750
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
751
+ // remove any leading / and split the uripath into path variables
752
+ let myPath = uriPath;
753
+ while (myPath.indexOf('/') === 0) {
754
+ myPath = myPath.substring(1);
755
+ }
756
+ const pathVars = myPath.split('/');
757
+ const queryParamsAvailable = queryData;
758
+ const queryParams = {};
759
+ const bodyVars = requestBody;
760
+
761
+ // loop in template. long callback arg name to avoid identifier conflicts
762
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
763
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
764
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
765
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
766
+ }
767
+ });
768
+
769
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
770
+ const reqObj = {
771
+ payload: bodyVars,
772
+ uriPathVars: pathVars,
773
+ uriQuery: queryParams,
774
+ uriOptions: {}
775
+ };
776
+ // add headers if provided
777
+ if (addlHeaders) {
778
+ reqObj.addlHeaders = addlHeaders;
779
+ }
780
+
781
+ // determine the call and return flag
782
+ let action = 'getGenericsNoBase';
783
+ let returnF = true;
784
+ if (restMethod.toUpperCase() === 'POST') {
785
+ action = 'createGenericNoBase';
786
+ } else if (restMethod.toUpperCase() === 'PUT') {
787
+ action = 'updateGenericNoBase';
788
+ } else if (restMethod.toUpperCase() === 'PATCH') {
789
+ action = 'patchGenericNoBase';
790
+ } else if (restMethod.toUpperCase() === 'DELETE') {
791
+ action = 'deleteGenericNoBase';
792
+ returnF = false;
793
+ }
794
+
795
+ try {
796
+ // Make the call -
797
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
798
+ return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
799
+ // if we received an error or their is no response on the results
800
+ // return an error
801
+ if (irReturnError) {
802
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
803
+ return callback(null, irReturnError);
804
+ }
805
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
806
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
807
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
808
+ return callback(null, errorObj);
809
+ }
810
+
811
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
812
+ // return the response
813
+ return callback(irReturnData, null);
814
+ });
815
+ } catch (ex) {
816
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
817
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
818
+ return callback(null, errorObj);
819
+ }
820
+ }
821
+
531
822
  /**
532
823
  * @callback healthCallback
533
824
  * @param {Object} result - the result of the get request (contains an id and a status)