@itentialopensource/adapter-meraki 0.8.0 → 0.8.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.
- package/AUTH.md +40 -0
- package/CALLS.md +100 -0
- package/CHANGELOG.md +8 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +247 -0
- package/README.md +112 -542
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +583 -204
- package/adapterBase.js +291 -290
- package/error.json +6 -0
- package/package.json +1 -1
- package/pronghorn.json +106 -113
- package/propertiesSchema.json +223 -0
- package/refs?service=git-upload-pack +0 -0
- package/test/integration/adapterTestIntegration.js +1 -0
- package/test/unit/adapterBaseTestUnit.js +22 -24
- package/test/unit/adapterTestUnit.js +57 -51
package/adapter.js
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
/* eslint import/no-dynamic-require: warn */
|
4
4
|
/* eslint object-curly-newline: warn */
|
5
|
-
/* eslint no-underscore-dangle: warn */
|
6
|
-
/* eslint camelcase: warn */
|
7
5
|
|
8
6
|
// Set globals
|
9
7
|
/* global log */
|
@@ -82,9 +80,9 @@ class Meraki extends AdapterBaseCl {
|
|
82
80
|
}
|
83
81
|
|
84
82
|
/**
|
85
|
-
* @
|
83
|
+
* @iapGetAdapterWorkflowFunctions
|
86
84
|
*/
|
87
|
-
|
85
|
+
iapGetAdapterWorkflowFunctions(inIgnore) {
|
88
86
|
let myIgnore = ['hasEntities', 'hasDevices'];
|
89
87
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
90
88
|
myIgnore = inIgnore;
|
@@ -96,15 +94,15 @@ class Meraki extends AdapterBaseCl {
|
|
96
94
|
// you can add specific methods that you do not want to be workflow functions to ignore like below
|
97
95
|
// myIgnore.push('myMethodNotInWorkflow');
|
98
96
|
|
99
|
-
return super.
|
97
|
+
return super.iapGetAdapterWorkflowFunctions(myIgnore);
|
100
98
|
}
|
101
99
|
|
102
100
|
/**
|
103
|
-
*
|
101
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
104
102
|
* allows customers to make changes to adapter configuration without having to be on the
|
105
103
|
* file system.
|
106
104
|
*
|
107
|
-
* @function
|
105
|
+
* @function iapUpdateAdapterConfiguration
|
108
106
|
* @param {string} configFile - the name of the file being updated (required)
|
109
107
|
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
110
108
|
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
@@ -112,36 +110,36 @@ class Meraki extends AdapterBaseCl {
|
|
112
110
|
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
113
111
|
* @param {Callback} callback - The results of the call
|
114
112
|
*/
|
115
|
-
|
116
|
-
const origin = `${this.id}-adapter-
|
113
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
114
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterConfiguration`;
|
117
115
|
log.trace(origin);
|
118
|
-
super.
|
116
|
+
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
119
117
|
}
|
120
118
|
|
121
119
|
/**
|
122
120
|
* See if the API path provided is found in this adapter
|
123
121
|
*
|
124
|
-
* @function
|
122
|
+
* @function iapFindAdapterPath
|
125
123
|
* @param {string} apiPath - the api path to check on
|
126
124
|
* @param {Callback} callback - The results of the call
|
127
125
|
*/
|
128
|
-
|
129
|
-
const origin = `${this.id}-adapter-
|
126
|
+
iapFindAdapterPath(apiPath, callback) {
|
127
|
+
const origin = `${this.id}-adapter-iapFindAdapterPath`;
|
130
128
|
log.trace(origin);
|
131
|
-
super.
|
129
|
+
super.iapFindAdapterPath(apiPath, callback);
|
132
130
|
}
|
133
131
|
|
134
132
|
/**
|
135
133
|
* @summary Suspends adapter
|
136
134
|
*
|
137
|
-
* @function
|
135
|
+
* @function iapSuspendAdapter
|
138
136
|
* @param {Callback} callback - callback function
|
139
137
|
*/
|
140
|
-
|
141
|
-
const origin = `${this.id}-adapter-
|
138
|
+
iapSuspendAdapter(mode, callback) {
|
139
|
+
const origin = `${this.id}-adapter-iapSuspendAdapter`;
|
142
140
|
log.trace(origin);
|
143
141
|
try {
|
144
|
-
return super.
|
142
|
+
return super.iapSuspendAdapter(mode, callback);
|
145
143
|
} catch (error) {
|
146
144
|
log.error(`${origin}: ${error}`);
|
147
145
|
return callback(null, error);
|
@@ -151,14 +149,14 @@ class Meraki extends AdapterBaseCl {
|
|
151
149
|
/**
|
152
150
|
* @summary Unsuspends adapter
|
153
151
|
*
|
154
|
-
* @function
|
152
|
+
* @function iapUnsuspendAdapter
|
155
153
|
* @param {Callback} callback - callback function
|
156
154
|
*/
|
157
|
-
|
158
|
-
const origin = `${this.id}-adapter-
|
155
|
+
iapUnsuspendAdapter(callback) {
|
156
|
+
const origin = `${this.id}-adapter-iapUnsuspendAdapter`;
|
159
157
|
log.trace(origin);
|
160
158
|
try {
|
161
|
-
return super.
|
159
|
+
return super.iapUnsuspendAdapter(callback);
|
162
160
|
} catch (error) {
|
163
161
|
log.error(`${origin}: ${error}`);
|
164
162
|
return callback(null, error);
|
@@ -168,29 +166,29 @@ class Meraki extends AdapterBaseCl {
|
|
168
166
|
/**
|
169
167
|
* @summary Get the Adaoter Queue
|
170
168
|
*
|
171
|
-
* @function
|
169
|
+
* @function iapGetAdapterQueue
|
172
170
|
* @param {Callback} callback - callback function
|
173
171
|
*/
|
174
|
-
|
175
|
-
const origin = `${this.id}-adapter-
|
172
|
+
iapGetAdapterQueue(callback) {
|
173
|
+
const origin = `${this.id}-adapter-iapGetAdapterQueue`;
|
176
174
|
log.trace(origin);
|
177
|
-
return super.
|
175
|
+
return super.iapGetAdapterQueue(callback);
|
178
176
|
}
|
179
177
|
|
180
178
|
/**
|
181
179
|
* @summary Runs troubleshoot scripts for adapter
|
182
180
|
*
|
183
|
-
* @function
|
181
|
+
* @function iapTroubleshootAdapter
|
184
182
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
185
183
|
*
|
186
184
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
187
185
|
* @param {Callback} callback - The results of the call
|
188
186
|
*/
|
189
|
-
|
190
|
-
const origin = `${this.id}-adapter-
|
187
|
+
iapTroubleshootAdapter(props, persistFlag, callback) {
|
188
|
+
const origin = `${this.id}-adapter-iapTroubleshootAdapter`;
|
191
189
|
log.trace(origin);
|
192
190
|
try {
|
193
|
-
return super.
|
191
|
+
return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
|
194
192
|
} catch (error) {
|
195
193
|
log.error(`${origin}: ${error}`);
|
196
194
|
return callback(null, error);
|
@@ -200,15 +198,15 @@ class Meraki extends AdapterBaseCl {
|
|
200
198
|
/**
|
201
199
|
* @summary runs healthcheck script for adapter
|
202
200
|
*
|
203
|
-
* @function
|
201
|
+
* @function iapRunAdapterHealthcheck
|
204
202
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
205
203
|
* @param {Callback} callback - callback function
|
206
204
|
*/
|
207
|
-
|
208
|
-
const origin = `${this.id}-adapter-
|
205
|
+
iapRunAdapterHealthcheck(callback) {
|
206
|
+
const origin = `${this.id}-adapter-iapRunAdapterHealthcheck`;
|
209
207
|
log.trace(origin);
|
210
208
|
try {
|
211
|
-
return super.
|
209
|
+
return super.iapRunAdapterHealthcheck(this, callback);
|
212
210
|
} catch (error) {
|
213
211
|
log.error(`${origin}: ${error}`);
|
214
212
|
return callback(null, error);
|
@@ -218,14 +216,14 @@ class Meraki extends AdapterBaseCl {
|
|
218
216
|
/**
|
219
217
|
* @summary runs connectivity check script for adapter
|
220
218
|
*
|
221
|
-
* @function
|
219
|
+
* @function iapRunAdapterConnectivity
|
222
220
|
* @param {Callback} callback - callback function
|
223
221
|
*/
|
224
|
-
|
225
|
-
const origin = `${this.id}-adapter-
|
222
|
+
iapRunAdapterConnectivity(callback) {
|
223
|
+
const origin = `${this.id}-adapter-iapRunAdapterConnectivity`;
|
226
224
|
log.trace(origin);
|
227
225
|
try {
|
228
|
-
return super.
|
226
|
+
return super.iapRunAdapterConnectivity(callback);
|
229
227
|
} catch (error) {
|
230
228
|
log.error(`${origin}: ${error}`);
|
231
229
|
return callback(null, error);
|
@@ -235,14 +233,14 @@ class Meraki extends AdapterBaseCl {
|
|
235
233
|
/**
|
236
234
|
* @summary runs basicGet script for adapter
|
237
235
|
*
|
238
|
-
* @function
|
236
|
+
* @function iapRunAdapterBasicGet
|
239
237
|
* @param {Callback} callback - callback function
|
240
238
|
*/
|
241
|
-
|
242
|
-
const origin = `${this.id}-adapter-
|
239
|
+
iapRunAdapterBasicGet(callback) {
|
240
|
+
const origin = `${this.id}-adapter-iapRunAdapterBasicGet`;
|
243
241
|
log.trace(origin);
|
244
242
|
try {
|
245
|
-
return super.
|
243
|
+
return super.iapRunAdapterBasicGet(callback);
|
246
244
|
} catch (error) {
|
247
245
|
log.error(`${origin}: ${error}`);
|
248
246
|
return callback(null, error);
|
@@ -252,45 +250,46 @@ class Meraki extends AdapterBaseCl {
|
|
252
250
|
/**
|
253
251
|
* @summary moves entites into Mongo DB
|
254
252
|
*
|
255
|
-
* @function
|
253
|
+
* @function iapMoveAdapterEntitiesToDB
|
256
254
|
* @param {getCallback} callback - a callback function to return the result (Generics)
|
257
255
|
* or the error
|
258
256
|
*/
|
259
|
-
|
260
|
-
const origin = `${this.id}-adapter-
|
257
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
258
|
+
const origin = `${this.id}-adapter-iapMoveAdapterEntitiesToDB`;
|
261
259
|
log.trace(origin);
|
262
260
|
try {
|
263
|
-
return super.
|
261
|
+
return super.iapMoveAdapterEntitiesToDB(callback);
|
264
262
|
} catch (err) {
|
265
263
|
log.error(`${origin}: ${err}`);
|
266
264
|
return callback(null, err);
|
267
265
|
}
|
268
266
|
}
|
269
267
|
|
268
|
+
/* BROKER CALLS */
|
270
269
|
/**
|
271
270
|
* @summary Determines if this adapter supports the specific entity
|
272
271
|
*
|
273
|
-
* @function
|
272
|
+
* @function iapHasAdapterEntity
|
274
273
|
* @param {String} entityType - the entity type to check for
|
275
274
|
* @param {String/Array} entityId - the specific entity we are looking for
|
276
275
|
*
|
277
276
|
* @param {Callback} callback - An array of whether the adapter can has the
|
278
277
|
* desired capability or an error
|
279
278
|
*/
|
280
|
-
|
281
|
-
const origin = `${this.id}-adapter-
|
279
|
+
iapHasAdapterEntity(entityType, entityId, callback) {
|
280
|
+
const origin = `${this.id}-adapter-iapHasAdapterEntity`;
|
282
281
|
log.trace(origin);
|
283
282
|
|
284
283
|
// Make the call -
|
285
|
-
//
|
286
|
-
return this.
|
284
|
+
// iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
285
|
+
return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
|
287
286
|
}
|
288
287
|
|
289
288
|
/**
|
290
289
|
* @summary Provides a way for the adapter to tell north bound integrations
|
291
290
|
* whether the adapter supports type, action and specific entity
|
292
291
|
*
|
293
|
-
* @function
|
292
|
+
* @function iapVerifyAdapterCapability
|
294
293
|
* @param {String} entityType - the entity type to check for
|
295
294
|
* @param {String} actionType - the action type to check for
|
296
295
|
* @param {String/Array} entityId - the specific entity we are looking for
|
@@ -298,15 +297,15 @@ class Meraki extends AdapterBaseCl {
|
|
298
297
|
* @param {Callback} callback - An array of whether the adapter can has the
|
299
298
|
* desired capability or an error
|
300
299
|
*/
|
301
|
-
|
302
|
-
const meth = 'adapterBase-
|
300
|
+
iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
|
301
|
+
const meth = 'adapterBase-iapVerifyAdapterCapability';
|
303
302
|
const origin = `${this.id}-${meth}`;
|
304
303
|
log.trace(origin);
|
305
304
|
|
306
305
|
// if caching
|
307
306
|
if (this.caching) {
|
308
|
-
// Make the call -
|
309
|
-
return this.requestHandlerInst.
|
307
|
+
// Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
308
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
|
310
309
|
if (error) {
|
311
310
|
return callback(null, error);
|
312
311
|
}
|
@@ -324,7 +323,7 @@ class Meraki extends AdapterBaseCl {
|
|
324
323
|
}
|
325
324
|
|
326
325
|
// need to check the cache again since it has been updated
|
327
|
-
return this.requestHandlerInst.
|
326
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
|
328
327
|
if (verror) {
|
329
328
|
return callback(null, verror);
|
330
329
|
}
|
@@ -357,7 +356,7 @@ class Meraki extends AdapterBaseCl {
|
|
357
356
|
// if no entity id
|
358
357
|
if (!entityId) {
|
359
358
|
// need to check the cache again since it has been updated
|
360
|
-
return this.requestHandlerInst.
|
359
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
361
360
|
if (verror) {
|
362
361
|
return callback(null, verror);
|
363
362
|
}
|
@@ -378,7 +377,7 @@ class Meraki extends AdapterBaseCl {
|
|
378
377
|
}
|
379
378
|
|
380
379
|
// need to check the cache again since it has been updated
|
381
|
-
return this.requestHandlerInst.
|
380
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
382
381
|
if (verror) {
|
383
382
|
return callback(null, verror);
|
384
383
|
}
|
@@ -419,11 +418,11 @@ class Meraki extends AdapterBaseCl {
|
|
419
418
|
/**
|
420
419
|
* @summary Updates the cache for all entities by call the get All entity method
|
421
420
|
*
|
422
|
-
* @function
|
421
|
+
* @function iapUpdateAdapterEntityCache
|
423
422
|
*
|
424
423
|
*/
|
425
|
-
|
426
|
-
const origin = `${this.id}-adapter-
|
424
|
+
iapUpdateAdapterEntityCache() {
|
425
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
|
427
426
|
log.trace(origin);
|
428
427
|
|
429
428
|
if (this.caching) {
|
@@ -436,117 +435,6 @@ class Meraki extends AdapterBaseCl {
|
|
436
435
|
}
|
437
436
|
}
|
438
437
|
|
439
|
-
/**
|
440
|
-
* Makes the requested generic call
|
441
|
-
*
|
442
|
-
* @function genericAdapterRequest
|
443
|
-
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
444
|
-
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
445
|
-
* @param {Object} queryData - the parameters to be put on the url (optional).
|
446
|
-
* Can be a stringified Object.
|
447
|
-
* @param {Object} requestBody - the body to add to the request (optional).
|
448
|
-
* Can be a stringified Object.
|
449
|
-
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
450
|
-
* Can be a stringified Object.
|
451
|
-
* @param {getCallback} callback - a callback function to return the result (Generics)
|
452
|
-
* or the error
|
453
|
-
*/
|
454
|
-
genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
455
|
-
const meth = 'adapter-genericAdapterRequest';
|
456
|
-
const origin = `${this.id}-${meth}`;
|
457
|
-
log.trace(origin);
|
458
|
-
|
459
|
-
if (this.suspended && this.suspendMode === 'error') {
|
460
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
461
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
462
|
-
return callback(null, errorObj);
|
463
|
-
}
|
464
|
-
|
465
|
-
/* HERE IS WHERE YOU VALIDATE DATA */
|
466
|
-
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
467
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
468
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
469
|
-
return callback(null, errorObj);
|
470
|
-
}
|
471
|
-
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
472
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
473
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
474
|
-
return callback(null, errorObj);
|
475
|
-
}
|
476
|
-
|
477
|
-
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
478
|
-
// remove any leading / and split the uripath into path variables
|
479
|
-
let myPath = uriPath;
|
480
|
-
while (myPath.indexOf('/') === 0) {
|
481
|
-
myPath = myPath.substring(1);
|
482
|
-
}
|
483
|
-
const pathVars = myPath.split('/');
|
484
|
-
const queryParamsAvailable = queryData;
|
485
|
-
const queryParams = {};
|
486
|
-
const bodyVars = requestBody;
|
487
|
-
|
488
|
-
// loop in template. long callback arg name to avoid identifier conflicts
|
489
|
-
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
490
|
-
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
491
|
-
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
492
|
-
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
493
|
-
}
|
494
|
-
});
|
495
|
-
|
496
|
-
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
497
|
-
const reqObj = {
|
498
|
-
payload: bodyVars,
|
499
|
-
uriPathVars: pathVars,
|
500
|
-
uriQuery: queryParams,
|
501
|
-
uriOptions: {}
|
502
|
-
};
|
503
|
-
// add headers if provided
|
504
|
-
if (addlHeaders) {
|
505
|
-
reqObj.addlHeaders = addlHeaders;
|
506
|
-
}
|
507
|
-
|
508
|
-
// determine the call and return flag
|
509
|
-
let action = 'getGenerics';
|
510
|
-
let returnF = true;
|
511
|
-
if (restMethod.toUpperCase() === 'POST') {
|
512
|
-
action = 'createGeneric';
|
513
|
-
} else if (restMethod.toUpperCase() === 'PUT') {
|
514
|
-
action = 'updateGeneric';
|
515
|
-
} else if (restMethod.toUpperCase() === 'PATCH') {
|
516
|
-
action = 'patchGeneric';
|
517
|
-
} else if (restMethod.toUpperCase() === 'DELETE') {
|
518
|
-
action = 'deleteGeneric';
|
519
|
-
returnF = false;
|
520
|
-
}
|
521
|
-
|
522
|
-
try {
|
523
|
-
// Make the call -
|
524
|
-
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
525
|
-
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
526
|
-
// if we received an error or their is no response on the results
|
527
|
-
// return an error
|
528
|
-
if (irReturnError) {
|
529
|
-
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
530
|
-
return callback(null, irReturnError);
|
531
|
-
}
|
532
|
-
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
533
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
|
534
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
535
|
-
return callback(null, errorObj);
|
536
|
-
}
|
537
|
-
|
538
|
-
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
539
|
-
// return the response
|
540
|
-
return callback(irReturnData, null);
|
541
|
-
});
|
542
|
-
} catch (ex) {
|
543
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
544
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
545
|
-
return callback(null, errorObj);
|
546
|
-
}
|
547
|
-
}
|
548
|
-
|
549
|
-
/* BROKER CALLS */
|
550
438
|
/**
|
551
439
|
* @summary Determines if this adapter supports any in a list of entities
|
552
440
|
*
|
@@ -622,8 +510,9 @@ class Meraki extends AdapterBaseCl {
|
|
622
510
|
const origin = `${this.id}-${meth}`;
|
623
511
|
log.trace(origin);
|
624
512
|
|
625
|
-
|
626
|
-
|
513
|
+
// make sure we are set up for device broker getDevice
|
514
|
+
if (!this.props.devicebroker || !this.props.devicebroker.getDevice || !this.props.devicebroker.getDevice.path) {
|
515
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevice.path'], null, null, null);
|
627
516
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
628
517
|
return callback(null, errorObj);
|
629
518
|
}
|
@@ -658,13 +547,74 @@ class Meraki extends AdapterBaseCl {
|
|
658
547
|
|
659
548
|
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
660
549
|
// !! you can also replace with a specific call if that is easier
|
661
|
-
|
662
|
-
|
550
|
+
let uriPath = '';
|
551
|
+
let uriMethod = 'GET';
|
552
|
+
let callQuery = {};
|
553
|
+
let callBody = {};
|
554
|
+
let callHeaders = {};
|
555
|
+
let nameField = 'name';
|
556
|
+
let nameArray = ['name'];
|
557
|
+
let ostypeField = 'ostype';
|
558
|
+
let ostypeArray = ['ostype'];
|
559
|
+
let ostypePrefix = '';
|
560
|
+
let portField = 'port';
|
561
|
+
let portArray = ['port'];
|
562
|
+
let ipField = 'ipaddress';
|
563
|
+
let ipArray = ['ipaddress'];
|
564
|
+
if (this.props.devicebroker.getDevice.path) {
|
565
|
+
uriPath = `${this.props.devicebroker.getDevice.path}`;
|
566
|
+
uriPath = uriPath.replace('{deviceid}', uuid);
|
567
|
+
}
|
568
|
+
if (this.props.devicebroker.getDevice.method) {
|
569
|
+
uriMethod = this.props.devicebroker.getDevice.method;
|
570
|
+
}
|
571
|
+
if (this.props.devicebroker.getDevice.query) {
|
572
|
+
try {
|
573
|
+
callQuery = JSON.parse(this.props.devicebroker.getDevice.query);
|
574
|
+
} catch (e) {
|
575
|
+
log.warn('Could not parse query parameter for getDevice call');
|
576
|
+
}
|
577
|
+
}
|
578
|
+
if (this.props.devicebroker.getDevice.body) {
|
579
|
+
try {
|
580
|
+
callBody = this.props.devicebroker.getDevice.body;
|
581
|
+
} catch (e) {
|
582
|
+
log.warn('Could not parse body for getDevice call');
|
583
|
+
}
|
584
|
+
}
|
585
|
+
if (this.props.devicebroker.getDevice.headers) {
|
586
|
+
try {
|
587
|
+
callHeaders = this.props.devicebroker.getDevice.headers;
|
588
|
+
} catch (e) {
|
589
|
+
log.warn('Could not parse headers for getDevice call');
|
590
|
+
}
|
591
|
+
}
|
592
|
+
if (this.props.devicebroker.getDevice.name_field) {
|
593
|
+
nameField = this.props.devicebroker.getDevice.name_field;
|
594
|
+
nameArray = nameField.split('.');
|
595
|
+
}
|
596
|
+
if (this.props.devicebroker.getDevice.ostype_field) {
|
597
|
+
ostypeField = this.props.devicebroker.getDevice.ostype_field;
|
598
|
+
ostypeArray = ostypeField.split('.');
|
599
|
+
}
|
600
|
+
if (this.props.devicebroker.getDevice.ostype_prefix) {
|
601
|
+
ostypePrefix = this.props.devicebroker.getDevice.ostype_prefix;
|
602
|
+
}
|
603
|
+
if (this.props.devicebroker.getDevice.port_field) {
|
604
|
+
portField = this.props.devicebroker.getDevice.port_field;
|
605
|
+
portArray = portField.split('.');
|
606
|
+
}
|
607
|
+
if (this.props.devicebroker.getDevice.ip_field) {
|
608
|
+
ipField = this.props.devicebroker.getDevice.ip_field;
|
609
|
+
ipArray = ipField.split('.');
|
610
|
+
}
|
611
|
+
|
612
|
+
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
663
613
|
// if we received an error or their is no response on the results return an error
|
664
614
|
if (error) {
|
665
615
|
return callback(null, error);
|
666
616
|
}
|
667
|
-
if (!result.response
|
617
|
+
if (!result.response) {
|
668
618
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
|
669
619
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
670
620
|
return callback(null, errorObj);
|
@@ -674,10 +624,46 @@ class Meraki extends AdapterBaseCl {
|
|
674
624
|
// !! format the data we send back
|
675
625
|
// !! these fields are config manager fields you need to map to the data we receive
|
676
626
|
const thisDevice = result.response;
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
627
|
+
let thisName = thisDevice;
|
628
|
+
for (let i = 0; i < nameArray.length; i += 1) {
|
629
|
+
if (!Object.hasOwnProperty.call(thisName, nameArray[i])) {
|
630
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
631
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
632
|
+
return callback(null, errorObj);
|
633
|
+
}
|
634
|
+
thisName = thisName[nameArray[i]];
|
635
|
+
}
|
636
|
+
thisDevice.name = thisName;
|
637
|
+
let thisOstype = thisDevice;
|
638
|
+
for (let i = 0; i < ostypeArray.length; i += 1) {
|
639
|
+
if (!Object.hasOwnProperty.call(thisOstype, ostypeArray[i])) {
|
640
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
641
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
642
|
+
return callback(null, errorObj);
|
643
|
+
}
|
644
|
+
thisOstype = thisOstype[ostypeArray[i]];
|
645
|
+
}
|
646
|
+
thisDevice.ostype = ostypePrefix + thisOstype;
|
647
|
+
let thisPort = thisDevice;
|
648
|
+
for (let i = 0; i < portArray.length; i += 1) {
|
649
|
+
if (!Object.hasOwnProperty.call(thisPort, portArray[i])) {
|
650
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
651
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
652
|
+
return callback(null, errorObj);
|
653
|
+
}
|
654
|
+
thisPort = thisPort[portArray[i]];
|
655
|
+
}
|
656
|
+
thisDevice.port = thisPort;
|
657
|
+
let thisIp = thisDevice;
|
658
|
+
for (let i = 0; i < ipArray.length; i += 1) {
|
659
|
+
if (!Object.hasOwnProperty.call(thisIp, ipArray[i])) {
|
660
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
661
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
662
|
+
return callback(null, errorObj);
|
663
|
+
}
|
664
|
+
thisIp = thisIp[ipArray[i]];
|
665
|
+
}
|
666
|
+
thisDevice.ipaddress = thisIp;
|
681
667
|
return callback(thisDevice);
|
682
668
|
});
|
683
669
|
});
|
@@ -702,6 +688,13 @@ class Meraki extends AdapterBaseCl {
|
|
702
688
|
const origin = `${this.id}-${meth}`;
|
703
689
|
log.trace(origin);
|
704
690
|
|
691
|
+
// make sure we are set up for device broker getDevicesFiltered
|
692
|
+
if (!this.props.devicebroker || !this.props.devicebroker.getDevicesFiltered || !this.props.devicebroker.getDevicesFiltered.path) {
|
693
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevicesFiltered.path'], null, null, null);
|
694
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
695
|
+
return callback(null, errorObj);
|
696
|
+
}
|
697
|
+
|
705
698
|
// verify the required fields have been provided
|
706
699
|
if (options === undefined || options === null || options === '' || options.length === 0) {
|
707
700
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
@@ -738,8 +731,68 @@ class Meraki extends AdapterBaseCl {
|
|
738
731
|
try {
|
739
732
|
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
740
733
|
// !! you can also replace with a specific call if that is easier
|
741
|
-
|
742
|
-
|
734
|
+
let uriPath = '';
|
735
|
+
let uriMethod = 'GET';
|
736
|
+
let callQuery = {};
|
737
|
+
let callBody = {};
|
738
|
+
let callHeaders = {};
|
739
|
+
let nameField = 'name';
|
740
|
+
let nameArray = ['name'];
|
741
|
+
let ostypeField = 'ostype';
|
742
|
+
let ostypeArray = ['ostype'];
|
743
|
+
let ostypePrefix = '';
|
744
|
+
let portField = 'port';
|
745
|
+
let portArray = ['port'];
|
746
|
+
let ipField = 'ipaddress';
|
747
|
+
let ipArray = ['ipaddress'];
|
748
|
+
if (this.props.devicebroker.getDevicesFiltered.path) {
|
749
|
+
uriPath = this.props.devicebroker.getDevicesFiltered.path;
|
750
|
+
}
|
751
|
+
if (this.props.devicebroker.getDevicesFiltered.method) {
|
752
|
+
uriMethod = this.props.devicebroker.getDevicesFiltered.method;
|
753
|
+
}
|
754
|
+
if (this.props.devicebroker.getDevicesFiltered.query) {
|
755
|
+
try {
|
756
|
+
callQuery = this.props.devicebroker.getDevicesFiltered.query;
|
757
|
+
} catch (e) {
|
758
|
+
log.warn('Could not parse query parameter for getDevicesFiltered call');
|
759
|
+
}
|
760
|
+
}
|
761
|
+
if (this.props.devicebroker.getDevicesFiltered.body) {
|
762
|
+
try {
|
763
|
+
callBody = this.props.devicebroker.getDevicesFiltered.body;
|
764
|
+
} catch (e) {
|
765
|
+
log.warn('Could not parse body for getDevicesFiltered call');
|
766
|
+
}
|
767
|
+
}
|
768
|
+
if (this.props.devicebroker.getDevicesFiltered.headers) {
|
769
|
+
try {
|
770
|
+
callHeaders = this.props.devicebroker.getDevicesFiltered.headers;
|
771
|
+
} catch (e) {
|
772
|
+
log.warn('Could not parse headers for getDevicesFiltered call');
|
773
|
+
}
|
774
|
+
}
|
775
|
+
if (this.props.devicebroker.getDevicesFiltered.name_field) {
|
776
|
+
nameField = this.props.devicebroker.getDevicesFiltered.name_field;
|
777
|
+
nameArray = nameField.split('.');
|
778
|
+
}
|
779
|
+
if (this.props.devicebroker.getDevicesFiltered.ostype_field) {
|
780
|
+
ostypeField = this.props.devicebroker.getDevicesFiltered.ostype_field;
|
781
|
+
ostypeArray = ostypeField.split('.');
|
782
|
+
}
|
783
|
+
if (this.props.devicebroker.getDevicesFiltered.ostype_prefix) {
|
784
|
+
ostypePrefix = this.props.devicebroker.getDevicesFiltered.ostype_prefix;
|
785
|
+
}
|
786
|
+
if (this.props.devicebroker.getDevicesFiltered.port_field) {
|
787
|
+
portField = this.props.devicebroker.getDevicesFiltered.port_field;
|
788
|
+
portArray = portField.split('.');
|
789
|
+
}
|
790
|
+
if (this.props.devicebroker.getDevicesFiltered.ip_field) {
|
791
|
+
ipField = this.props.devicebroker.getDevicesFiltered.ip_field;
|
792
|
+
ipArray = ipField.split('.');
|
793
|
+
}
|
794
|
+
|
795
|
+
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
743
796
|
// if we received an error or their is no response on the results return an error
|
744
797
|
if (error) {
|
745
798
|
return callback(null, error);
|
@@ -759,10 +812,46 @@ class Meraki extends AdapterBaseCl {
|
|
759
812
|
// !! format the data we send back
|
760
813
|
// !! these fields are config manager fields you need to map to the data we receive
|
761
814
|
const thisDevice = result.response;
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
815
|
+
let thisName = thisDevice;
|
816
|
+
for (let i = 0; i < nameArray.length; i += 1) {
|
817
|
+
if (!Object.hasOwnProperty.call(thisName, nameArray[i])) {
|
818
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
819
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
820
|
+
return callback(null, errorObj);
|
821
|
+
}
|
822
|
+
thisName = thisName[nameArray[i]];
|
823
|
+
}
|
824
|
+
thisDevice.name = thisName;
|
825
|
+
let thisOstype = thisDevice;
|
826
|
+
for (let i = 0; i < ostypeArray.length; i += 1) {
|
827
|
+
if (!Object.hasOwnProperty.call(thisOstype, ostypeArray[i])) {
|
828
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
829
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
830
|
+
return callback(null, errorObj);
|
831
|
+
}
|
832
|
+
thisOstype = thisOstype[ostypeArray[i]];
|
833
|
+
}
|
834
|
+
thisDevice.ostype = ostypePrefix + thisOstype;
|
835
|
+
let thisPort = thisDevice;
|
836
|
+
for (let i = 0; i < portArray.length; i += 1) {
|
837
|
+
if (!Object.hasOwnProperty.call(thisPort, portArray[i])) {
|
838
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
839
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
840
|
+
return callback(null, errorObj);
|
841
|
+
}
|
842
|
+
thisPort = thisPort[portArray[i]];
|
843
|
+
}
|
844
|
+
thisDevice.port = thisPort;
|
845
|
+
let thisIp = thisDevice;
|
846
|
+
for (let i = 0; i < ipArray.length; i += 1) {
|
847
|
+
if (!Object.hasOwnProperty.call(thisIp, ipArray[i])) {
|
848
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
849
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
850
|
+
return callback(null, errorObj);
|
851
|
+
}
|
852
|
+
thisIp = thisIp[ipArray[i]];
|
853
|
+
}
|
854
|
+
thisDevice.ipaddress = thisIp;
|
766
855
|
|
767
856
|
// if there is no filter - return the device
|
768
857
|
if (filterName.length === 0) {
|
@@ -790,10 +879,46 @@ class Meraki extends AdapterBaseCl {
|
|
790
879
|
// !! format the data we send back
|
791
880
|
// !! these fields are config manager fields you need to map to the data we receive
|
792
881
|
const thisDevice = result.response;
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
882
|
+
let thisName = thisDevice;
|
883
|
+
for (let i = 0; i < nameArray.length; i += 1) {
|
884
|
+
if (!Object.hasOwnProperty.call(thisName, nameArray[i])) {
|
885
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
886
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
887
|
+
return callback(null, errorObj);
|
888
|
+
}
|
889
|
+
thisName = thisName[nameArray[i]];
|
890
|
+
}
|
891
|
+
thisDevice.name = thisName;
|
892
|
+
let thisOstype = thisDevice;
|
893
|
+
for (let i = 0; i < ostypeArray.length; i += 1) {
|
894
|
+
if (!Object.hasOwnProperty.call(thisOstype, ostypeArray[i])) {
|
895
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
896
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
897
|
+
return callback(null, errorObj);
|
898
|
+
}
|
899
|
+
thisOstype = thisOstype[ostypeArray[i]];
|
900
|
+
}
|
901
|
+
thisDevice.ostype = ostypePrefix + thisOstype;
|
902
|
+
let thisPort = thisDevice;
|
903
|
+
for (let i = 0; i < portArray.length; i += 1) {
|
904
|
+
if (!Object.hasOwnProperty.call(thisPort, portArray[i])) {
|
905
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
906
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
907
|
+
return callback(null, errorObj);
|
908
|
+
}
|
909
|
+
thisPort = thisPort[portArray[i]];
|
910
|
+
}
|
911
|
+
thisDevice.port = thisPort;
|
912
|
+
let thisIp = thisDevice;
|
913
|
+
for (let i = 0; i < ipArray.length; i += 1) {
|
914
|
+
if (!Object.hasOwnProperty.call(thisIp, ipArray[i])) {
|
915
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
916
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
917
|
+
return callback(null, errorObj);
|
918
|
+
}
|
919
|
+
thisIp = thisIp[ipArray[i]];
|
920
|
+
}
|
921
|
+
thisDevice.ipaddress = thisIp;
|
797
922
|
|
798
923
|
// if there is no filter - return the device
|
799
924
|
if (filterName.length === 0) {
|
@@ -841,6 +966,13 @@ class Meraki extends AdapterBaseCl {
|
|
841
966
|
const origin = `${this.id}-${meth}`;
|
842
967
|
log.trace(origin);
|
843
968
|
|
969
|
+
// make sure we are set up for device broker isAlive
|
970
|
+
if (!this.props.devicebroker || !this.props.devicebroker.isAlive || !this.props.devicebroker.isAlive.path) {
|
971
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.isAlive.path'], null, null, null);
|
972
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
973
|
+
return callback(null, errorObj);
|
974
|
+
}
|
975
|
+
|
844
976
|
// verify the required fields have been provided
|
845
977
|
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
846
978
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
@@ -871,21 +1003,78 @@ class Meraki extends AdapterBaseCl {
|
|
871
1003
|
|
872
1004
|
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
873
1005
|
// !! you can also replace with a specific call if that is easier
|
874
|
-
|
875
|
-
|
1006
|
+
let uriPath = '';
|
1007
|
+
let uriMethod = 'GET';
|
1008
|
+
let callQuery = {};
|
1009
|
+
let callBody = {};
|
1010
|
+
let callHeaders = {};
|
1011
|
+
let statusField = 'status';
|
1012
|
+
let statusArray = ['status'];
|
1013
|
+
let statusValue = 'true';
|
1014
|
+
if (this.props.devicebroker.isAlive.path) {
|
1015
|
+
uriPath = `${this.props.devicebroker.isAlive.path}`;
|
1016
|
+
uriPath = uriPath.replace('{deviceid}', uuid);
|
1017
|
+
}
|
1018
|
+
if (this.props.devicebroker.isAlive.method) {
|
1019
|
+
uriMethod = this.props.devicebroker.isAlive.method;
|
1020
|
+
}
|
1021
|
+
if (this.props.devicebroker.isAlive.query) {
|
1022
|
+
try {
|
1023
|
+
callQuery = this.props.devicebroker.isAlive.query;
|
1024
|
+
} catch (e) {
|
1025
|
+
log.warn('Could not parse query parameter for isAlive call');
|
1026
|
+
}
|
1027
|
+
}
|
1028
|
+
if (this.props.devicebroker.isAlive.body) {
|
1029
|
+
try {
|
1030
|
+
callBody = this.props.devicebroker.isAlive.body;
|
1031
|
+
} catch (e) {
|
1032
|
+
log.warn('Could not parse body for isAlive call');
|
1033
|
+
}
|
1034
|
+
}
|
1035
|
+
if (this.props.devicebroker.isAlive.headers) {
|
1036
|
+
try {
|
1037
|
+
callHeaders = this.props.devicebroker.isAlive.headers;
|
1038
|
+
} catch (e) {
|
1039
|
+
log.warn('Could not parse headers for isAlive call');
|
1040
|
+
}
|
1041
|
+
}
|
1042
|
+
if (this.props.devicebroker.isAlive.response && this.props.devicebroker.isAlive.status_field) {
|
1043
|
+
statusField = this.props.devicebroker.isAlive.status_field;
|
1044
|
+
statusArray = statusField.split('.');
|
1045
|
+
}
|
1046
|
+
if (this.props.devicebroker.isAlive.response && this.props.devicebroker.isAlive.status_value) {
|
1047
|
+
statusValue = this.props.devicebroker.isAlive.response.status_value;
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
876
1051
|
// if we received an error or their is no response on the results return an error
|
877
1052
|
if (error) {
|
878
1053
|
return callback(null, error);
|
879
1054
|
}
|
1055
|
+
|
880
1056
|
// !! should update this to make sure we are checking for the appropriate object/field
|
881
|
-
if (!result.response || !result.response.returnObj
|
1057
|
+
if (!result.response || !result.response.returnObj) {
|
882
1058
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
|
883
1059
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
884
1060
|
return callback(null, errorObj);
|
885
1061
|
}
|
1062
|
+
let thisObj = result.response.returnObj;
|
1063
|
+
for (let i = 0; i < statusArray.length; i += 1) {
|
1064
|
+
if (!Object.hasOwnProperty.call(thisObj, statusArray[i])) {
|
1065
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
|
1066
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1067
|
+
return callback(null, errorObj);
|
1068
|
+
}
|
1069
|
+
thisObj = thisObj[statusArray[i]];
|
1070
|
+
}
|
886
1071
|
|
887
1072
|
// !! return the response - Update to the appropriate object/field
|
888
|
-
|
1073
|
+
let response = true;
|
1074
|
+
if (thisObj.toString() !== statusValue) {
|
1075
|
+
response = false;
|
1076
|
+
}
|
1077
|
+
return callback(response);
|
889
1078
|
});
|
890
1079
|
});
|
891
1080
|
} catch (ex) {
|
@@ -910,6 +1099,13 @@ class Meraki extends AdapterBaseCl {
|
|
910
1099
|
const origin = `${this.id}-${meth}`;
|
911
1100
|
log.trace(origin);
|
912
1101
|
|
1102
|
+
// make sure we are set up for device broker getConfig
|
1103
|
+
if (!this.props.devicebroker || !this.props.devicebroker.getConfig || !this.props.devicebroker.getConfig.path) {
|
1104
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getConfig.path'], null, null, null);
|
1105
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1106
|
+
return callback(null, errorObj);
|
1107
|
+
}
|
1108
|
+
|
913
1109
|
// verify the required fields have been provided
|
914
1110
|
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
915
1111
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
@@ -940,8 +1136,41 @@ class Meraki extends AdapterBaseCl {
|
|
940
1136
|
|
941
1137
|
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
942
1138
|
// !! you can also replace with a specific call if that is easier
|
943
|
-
|
944
|
-
|
1139
|
+
let uriPath = '';
|
1140
|
+
let uriMethod = 'GET';
|
1141
|
+
let callQuery = {};
|
1142
|
+
let callBody = {};
|
1143
|
+
let callHeaders = {};
|
1144
|
+
if (this.props.devicebroker.getConfig.path) {
|
1145
|
+
uriPath = `${this.props.devicebroker.getConfig.path}`;
|
1146
|
+
uriPath = uriPath.replace('{deviceid}', uuid);
|
1147
|
+
}
|
1148
|
+
if (this.props.devicebroker.getConfig.method) {
|
1149
|
+
uriMethod = this.props.devicebroker.getConfig.method;
|
1150
|
+
}
|
1151
|
+
if (this.props.devicebroker.getConfig.query) {
|
1152
|
+
try {
|
1153
|
+
callQuery = this.props.devicebroker.getConfig.query;
|
1154
|
+
} catch (e) {
|
1155
|
+
log.warn('Could not parse query parameter for getConfig call');
|
1156
|
+
}
|
1157
|
+
}
|
1158
|
+
if (this.props.devicebroker.getConfig.body) {
|
1159
|
+
try {
|
1160
|
+
callBody = this.props.devicebroker.getConfig.body;
|
1161
|
+
} catch (e) {
|
1162
|
+
log.warn('Could not parse body for getConfig call');
|
1163
|
+
}
|
1164
|
+
}
|
1165
|
+
if (this.props.devicebroker.getConfig.headers) {
|
1166
|
+
try {
|
1167
|
+
callHeaders = this.props.devicebroker.getConfig.headers;
|
1168
|
+
} catch (e) {
|
1169
|
+
log.warn('Could not parse headers for getConfig call');
|
1170
|
+
}
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
945
1174
|
// if we received an error or their is no response on the results return an error
|
946
1175
|
if (error) {
|
947
1176
|
return callback(null, error);
|
@@ -964,23 +1193,62 @@ class Meraki extends AdapterBaseCl {
|
|
964
1193
|
/**
|
965
1194
|
* @summary Gets the device count from the system
|
966
1195
|
*
|
967
|
-
* @function
|
1196
|
+
* @function iapGetDeviceCount
|
968
1197
|
*
|
969
1198
|
* @param {getCallback} callback - callback function to return the result
|
970
1199
|
* (count) or the error
|
971
1200
|
*/
|
972
|
-
|
973
|
-
const meth = 'adapter-
|
1201
|
+
iapGetDeviceCount(callback) {
|
1202
|
+
const meth = 'adapter-iapGetDeviceCount';
|
974
1203
|
const origin = `${this.id}-${meth}`;
|
975
1204
|
log.trace(origin);
|
976
1205
|
|
1206
|
+
// make sure we are set up for device broker getCount
|
1207
|
+
if (!this.props.devicebroker || !this.props.devicebroker.getCount || !this.props.devicebroker.getCount.path) {
|
1208
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getCount.path'], null, null, null);
|
1209
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1210
|
+
return callback(null, errorObj);
|
1211
|
+
}
|
1212
|
+
|
977
1213
|
// verify the required fields have been provided
|
978
1214
|
|
979
1215
|
try {
|
980
|
-
// !! using Generic makes it easier on the Adapter Builder (just need to
|
1216
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to set the path or call in properties)
|
981
1217
|
// !! you can also replace with a specific call if that is easier
|
982
|
-
|
983
|
-
|
1218
|
+
let uriPath = '';
|
1219
|
+
let uriMethod = 'GET';
|
1220
|
+
let callQuery = {};
|
1221
|
+
let callBody = {};
|
1222
|
+
let callHeaders = {};
|
1223
|
+
if (this.props.devicebroker.getCount.path) {
|
1224
|
+
uriPath = this.props.devicebroker.getCount.path;
|
1225
|
+
}
|
1226
|
+
if (this.props.devicebroker.getCount.method) {
|
1227
|
+
uriMethod = this.props.devicebroker.getCount.method;
|
1228
|
+
}
|
1229
|
+
if (this.props.devicebroker.getCount.query) {
|
1230
|
+
try {
|
1231
|
+
callQuery = this.props.devicebroker.getCount.query;
|
1232
|
+
} catch (e) {
|
1233
|
+
log.warn('Could not parse query parameter for getCount call');
|
1234
|
+
}
|
1235
|
+
}
|
1236
|
+
if (this.props.devicebroker.getCount.body) {
|
1237
|
+
try {
|
1238
|
+
callBody = this.props.devicebroker.getCount.body;
|
1239
|
+
} catch (e) {
|
1240
|
+
log.warn('Could not parse body for getCount call');
|
1241
|
+
}
|
1242
|
+
}
|
1243
|
+
if (this.props.devicebroker.getCount.headers) {
|
1244
|
+
try {
|
1245
|
+
callHeaders = this.props.devicebroker.getCount.headers;
|
1246
|
+
} catch (e) {
|
1247
|
+
log.warn('Could not parse headers for getCount call');
|
1248
|
+
}
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
984
1252
|
// if we received an error or their is no response on the results return an error
|
985
1253
|
if (error) {
|
986
1254
|
return callback(null, error);
|
@@ -996,6 +1264,117 @@ class Meraki extends AdapterBaseCl {
|
|
996
1264
|
}
|
997
1265
|
}
|
998
1266
|
|
1267
|
+
/* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
|
1268
|
+
/**
|
1269
|
+
* Makes the requested generic call
|
1270
|
+
*
|
1271
|
+
* @function genericAdapterRequest
|
1272
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
1273
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
1274
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
1275
|
+
* Can be a stringified Object.
|
1276
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
1277
|
+
* Can be a stringified Object.
|
1278
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
1279
|
+
* Can be a stringified Object.
|
1280
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
1281
|
+
* or the error
|
1282
|
+
*/
|
1283
|
+
genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
1284
|
+
const meth = 'adapter-genericAdapterRequest';
|
1285
|
+
const origin = `${this.id}-${meth}`;
|
1286
|
+
log.trace(origin);
|
1287
|
+
|
1288
|
+
if (this.suspended && this.suspendMode === 'error') {
|
1289
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
1290
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1291
|
+
return callback(null, errorObj);
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
1295
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
1296
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
1297
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1298
|
+
return callback(null, errorObj);
|
1299
|
+
}
|
1300
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
1301
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
1302
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1303
|
+
return callback(null, errorObj);
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
1307
|
+
// remove any leading / and split the uripath into path variables
|
1308
|
+
let myPath = uriPath;
|
1309
|
+
while (myPath.indexOf('/') === 0) {
|
1310
|
+
myPath = myPath.substring(1);
|
1311
|
+
}
|
1312
|
+
const pathVars = myPath.split('/');
|
1313
|
+
const queryParamsAvailable = queryData;
|
1314
|
+
const queryParams = {};
|
1315
|
+
const bodyVars = requestBody;
|
1316
|
+
|
1317
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
1318
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
1319
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
1320
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
1321
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
1322
|
+
}
|
1323
|
+
});
|
1324
|
+
|
1325
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
1326
|
+
const reqObj = {
|
1327
|
+
payload: bodyVars,
|
1328
|
+
uriPathVars: pathVars,
|
1329
|
+
uriQuery: queryParams,
|
1330
|
+
uriOptions: {}
|
1331
|
+
};
|
1332
|
+
// add headers if provided
|
1333
|
+
if (addlHeaders) {
|
1334
|
+
reqObj.addlHeaders = addlHeaders;
|
1335
|
+
}
|
1336
|
+
|
1337
|
+
// determine the call and return flag
|
1338
|
+
let action = 'getGenerics';
|
1339
|
+
let returnF = true;
|
1340
|
+
if (restMethod.toUpperCase() === 'POST') {
|
1341
|
+
action = 'createGeneric';
|
1342
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
1343
|
+
action = 'updateGeneric';
|
1344
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
1345
|
+
action = 'patchGeneric';
|
1346
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
1347
|
+
action = 'deleteGeneric';
|
1348
|
+
returnF = false;
|
1349
|
+
}
|
1350
|
+
|
1351
|
+
try {
|
1352
|
+
// Make the call -
|
1353
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
1354
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
1355
|
+
// if we received an error or their is no response on the results
|
1356
|
+
// return an error
|
1357
|
+
if (irReturnError) {
|
1358
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
1359
|
+
return callback(null, irReturnError);
|
1360
|
+
}
|
1361
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
1362
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
|
1363
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1364
|
+
return callback(null, errorObj);
|
1365
|
+
}
|
1366
|
+
|
1367
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
1368
|
+
// return the response
|
1369
|
+
return callback(irReturnData, null);
|
1370
|
+
});
|
1371
|
+
} catch (ex) {
|
1372
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
1373
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1374
|
+
return callback(null, errorObj);
|
1375
|
+
}
|
1376
|
+
}
|
1377
|
+
|
999
1378
|
/**
|
1000
1379
|
* @callback healthCallback
|
1001
1380
|
* @param {Object} result - the result of the get request (contains an id and a status)
|