@itentialopensource/adapter-meraki 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- package/AUTH.md +14 -15
- package/BROKER.md +195 -0
- package/CALLS.md +158 -89
- package/CHANGELOG.md +8 -0
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +88 -74
- package/ENHANCE.md +14 -14
- package/PROPERTIES.md +483 -89
- package/README.md +131 -51
- package/SUMMARY.md +2 -2
- package/TROUBLESHOOT.md +4 -3
- package/adapter.js +175 -394
- package/adapterBase.js +607 -157
- package/entities/.generic/action.json +105 -0
- package/entities/.generic/schema.json +6 -1
- package/package.json +3 -2
- package/pronghorn.json +79 -0
- package/propertiesSchema.json +13 -0
- package/refs?service=git-upload-pack +0 -0
- package/sampleProperties.json +82 -0
- package/test/unit/adapterBaseTestUnit.js +10 -3
- package/test/unit/adapterTestUnit.js +4 -14
- package/utils/adapterInfo.js +206 -0
- package/utils/pre-commit.sh +3 -0
package/adapter.js
CHANGED
@@ -83,7 +83,14 @@ class Meraki extends AdapterBaseCl {
|
|
83
83
|
* @iapGetAdapterWorkflowFunctions
|
84
84
|
*/
|
85
85
|
iapGetAdapterWorkflowFunctions(inIgnore) {
|
86
|
-
let myIgnore = [
|
86
|
+
let myIgnore = [
|
87
|
+
'healthCheck',
|
88
|
+
'iapGetAdapterWorkflowFunctions',
|
89
|
+
'iapHasAdapterEntity',
|
90
|
+
'iapVerifyAdapterCapability',
|
91
|
+
'iapUpdateAdapterEntityCache',
|
92
|
+
'hasEntities'
|
93
|
+
];
|
87
94
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
88
95
|
myIgnore = inIgnore;
|
89
96
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
@@ -111,8 +118,10 @@ class Meraki extends AdapterBaseCl {
|
|
111
118
|
* @param {Callback} callback - The results of the call
|
112
119
|
*/
|
113
120
|
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
114
|
-
const
|
121
|
+
const meth = 'adapter-iapUpdateAdapterConfiguration';
|
122
|
+
const origin = `${this.id}-${meth}`;
|
115
123
|
log.trace(origin);
|
124
|
+
|
116
125
|
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
117
126
|
}
|
118
127
|
|
@@ -124,8 +133,10 @@ class Meraki extends AdapterBaseCl {
|
|
124
133
|
* @param {Callback} callback - The results of the call
|
125
134
|
*/
|
126
135
|
iapFindAdapterPath(apiPath, callback) {
|
127
|
-
const
|
136
|
+
const meth = 'adapter-iapFindAdapterPath';
|
137
|
+
const origin = `${this.id}-${meth}`;
|
128
138
|
log.trace(origin);
|
139
|
+
|
129
140
|
super.iapFindAdapterPath(apiPath, callback);
|
130
141
|
}
|
131
142
|
|
@@ -136,8 +147,10 @@ class Meraki extends AdapterBaseCl {
|
|
136
147
|
* @param {Callback} callback - callback function
|
137
148
|
*/
|
138
149
|
iapSuspendAdapter(mode, callback) {
|
139
|
-
const
|
150
|
+
const meth = 'adapter-iapSuspendAdapter';
|
151
|
+
const origin = `${this.id}-${meth}`;
|
140
152
|
log.trace(origin);
|
153
|
+
|
141
154
|
try {
|
142
155
|
return super.iapSuspendAdapter(mode, callback);
|
143
156
|
} catch (error) {
|
@@ -153,8 +166,10 @@ class Meraki extends AdapterBaseCl {
|
|
153
166
|
* @param {Callback} callback - callback function
|
154
167
|
*/
|
155
168
|
iapUnsuspendAdapter(callback) {
|
156
|
-
const
|
169
|
+
const meth = 'adapter-iapUnsuspendAdapter';
|
170
|
+
const origin = `${this.id}-${meth}`;
|
157
171
|
log.trace(origin);
|
172
|
+
|
158
173
|
try {
|
159
174
|
return super.iapUnsuspendAdapter(callback);
|
160
175
|
} catch (error) {
|
@@ -170,8 +185,10 @@ class Meraki extends AdapterBaseCl {
|
|
170
185
|
* @param {Callback} callback - callback function
|
171
186
|
*/
|
172
187
|
iapGetAdapterQueue(callback) {
|
173
|
-
const
|
188
|
+
const meth = 'adapter-iapGetAdapterQueue';
|
189
|
+
const origin = `${this.id}-${meth}`;
|
174
190
|
log.trace(origin);
|
191
|
+
|
175
192
|
return super.iapGetAdapterQueue(callback);
|
176
193
|
}
|
177
194
|
|
@@ -185,8 +202,10 @@ class Meraki extends AdapterBaseCl {
|
|
185
202
|
* @param {Callback} callback - The results of the call
|
186
203
|
*/
|
187
204
|
iapTroubleshootAdapter(props, persistFlag, callback) {
|
188
|
-
const
|
205
|
+
const meth = 'adapter-iapTroubleshootAdapter';
|
206
|
+
const origin = `${this.id}-${meth}`;
|
189
207
|
log.trace(origin);
|
208
|
+
|
190
209
|
try {
|
191
210
|
return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
|
192
211
|
} catch (error) {
|
@@ -203,8 +222,10 @@ class Meraki extends AdapterBaseCl {
|
|
203
222
|
* @param {Callback} callback - callback function
|
204
223
|
*/
|
205
224
|
iapRunAdapterHealthcheck(callback) {
|
206
|
-
const
|
225
|
+
const meth = 'adapter-iapRunAdapterHealthcheck';
|
226
|
+
const origin = `${this.id}-${meth}`;
|
207
227
|
log.trace(origin);
|
228
|
+
|
208
229
|
try {
|
209
230
|
return super.iapRunAdapterHealthcheck(this, callback);
|
210
231
|
} catch (error) {
|
@@ -220,8 +241,10 @@ class Meraki extends AdapterBaseCl {
|
|
220
241
|
* @param {Callback} callback - callback function
|
221
242
|
*/
|
222
243
|
iapRunAdapterConnectivity(callback) {
|
223
|
-
const
|
244
|
+
const meth = 'adapter-iapRunAdapterConnectivity';
|
245
|
+
const origin = `${this.id}-${meth}`;
|
224
246
|
log.trace(origin);
|
247
|
+
|
225
248
|
try {
|
226
249
|
return super.iapRunAdapterConnectivity(callback);
|
227
250
|
} catch (error) {
|
@@ -237,8 +260,10 @@ class Meraki extends AdapterBaseCl {
|
|
237
260
|
* @param {Callback} callback - callback function
|
238
261
|
*/
|
239
262
|
iapRunAdapterBasicGet(callback) {
|
240
|
-
const
|
263
|
+
const meth = 'adapter-iapRunAdapterBasicGet';
|
264
|
+
const origin = `${this.id}-${meth}`;
|
241
265
|
log.trace(origin);
|
266
|
+
|
242
267
|
try {
|
243
268
|
return super.iapRunAdapterBasicGet(callback);
|
244
269
|
} catch (error) {
|
@@ -255,8 +280,10 @@ class Meraki extends AdapterBaseCl {
|
|
255
280
|
* or the error
|
256
281
|
*/
|
257
282
|
iapMoveAdapterEntitiesToDB(callback) {
|
258
|
-
const
|
283
|
+
const meth = 'adapter-iapMoveAdapterEntitiesToDB';
|
284
|
+
const origin = `${this.id}-${meth}`;
|
259
285
|
log.trace(origin);
|
286
|
+
|
260
287
|
try {
|
261
288
|
return super.iapMoveAdapterEntitiesToDB(callback);
|
262
289
|
} catch (err) {
|
@@ -446,56 +473,18 @@ class Meraki extends AdapterBaseCl {
|
|
446
473
|
* value is true or false
|
447
474
|
*/
|
448
475
|
hasEntities(entityType, entityList, callback) {
|
449
|
-
const
|
476
|
+
const meth = 'adapter-hasEntities';
|
477
|
+
const origin = `${this.id}-${meth}`;
|
450
478
|
log.trace(origin);
|
451
479
|
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
480
|
+
try {
|
481
|
+
return super.hasEntities(entityType, entityList, callback);
|
482
|
+
} catch (err) {
|
483
|
+
log.error(`${origin}: ${err}`);
|
484
|
+
return callback(null, err);
|
457
485
|
}
|
458
486
|
}
|
459
487
|
|
460
|
-
/**
|
461
|
-
* @summary Helper method for hasEntities for the specific device case
|
462
|
-
*
|
463
|
-
* @param {Array} deviceList - array of unique device identifiers
|
464
|
-
* @param {Callback} callback - A map where the device is the key and the
|
465
|
-
* value is true or false
|
466
|
-
*/
|
467
|
-
hasDevices(deviceList, callback) {
|
468
|
-
const origin = `${this.id}-adapter-hasDevices`;
|
469
|
-
log.trace(origin);
|
470
|
-
|
471
|
-
const findings = deviceList.reduce((map, device) => {
|
472
|
-
// eslint-disable-next-line no-param-reassign
|
473
|
-
map[device] = false;
|
474
|
-
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
475
|
-
return map;
|
476
|
-
}, {});
|
477
|
-
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
478
|
-
this.getDevice(device, (result, error) => {
|
479
|
-
if (error) {
|
480
|
-
log.debug(`In map error: ${JSON.stringify(device)}`);
|
481
|
-
return resolve({ name: device, found: false });
|
482
|
-
}
|
483
|
-
log.debug(`In map: ${JSON.stringify(device)}`);
|
484
|
-
return resolve({ name: device, found: true });
|
485
|
-
});
|
486
|
-
}));
|
487
|
-
Promise.all(apiCalls).then((results) => {
|
488
|
-
results.forEach((device) => {
|
489
|
-
findings[device.name] = device.found;
|
490
|
-
});
|
491
|
-
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
492
|
-
return callback(findings);
|
493
|
-
}).catch((errors) => {
|
494
|
-
log.error('Unable to do device lookup.');
|
495
|
-
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
496
|
-
});
|
497
|
-
}
|
498
|
-
|
499
488
|
/**
|
500
489
|
* @summary Get Appliance that match the deviceName
|
501
490
|
*
|
@@ -510,75 +499,11 @@ class Meraki extends AdapterBaseCl {
|
|
510
499
|
const origin = `${this.id}-${meth}`;
|
511
500
|
log.trace(origin);
|
512
501
|
|
513
|
-
// make sure we are set up for device broker getDevice
|
514
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevice || this.allProps.devicebroker.getDevice.length === 0 || !this.allProps.devicebroker.getDevice[0].path) {
|
515
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevice.path'], null, null, null);
|
516
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
517
|
-
return callback(null, errorObj);
|
518
|
-
}
|
519
|
-
|
520
|
-
/* HERE IS WHERE YOU VALIDATE DATA */
|
521
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
522
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
523
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
524
|
-
return callback(null, errorObj);
|
525
|
-
}
|
526
|
-
|
527
502
|
try {
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
name: deviceName
|
533
|
-
}
|
534
|
-
};
|
535
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
536
|
-
// if we received an error or their is no response on the results return an error
|
537
|
-
if (ferr) {
|
538
|
-
return callback(null, ferr);
|
539
|
-
}
|
540
|
-
if (devs.list.length < 1) {
|
541
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
542
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
543
|
-
return callback(null, errorObj);
|
544
|
-
}
|
545
|
-
|
546
|
-
const callPromises = [];
|
547
|
-
for (let i = 0; i < this.allProps.devicebroker.getDevice.length; i += 1) {
|
548
|
-
// Perform component calls here.
|
549
|
-
callPromises.push(
|
550
|
-
new Promise((resolve, reject) => {
|
551
|
-
this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], devs.list[0], null, (callRet, callErr) => {
|
552
|
-
// return an error
|
553
|
-
if (callErr) {
|
554
|
-
reject(callErr);
|
555
|
-
} else {
|
556
|
-
// return the data
|
557
|
-
resolve(callRet);
|
558
|
-
}
|
559
|
-
});
|
560
|
-
})
|
561
|
-
);
|
562
|
-
}
|
563
|
-
|
564
|
-
// return an array of repsonses
|
565
|
-
return Promise.all(callPromises).then((results) => {
|
566
|
-
let myResult = {};
|
567
|
-
results.forEach((result) => {
|
568
|
-
myResult = { ...myResult, ...result };
|
569
|
-
});
|
570
|
-
|
571
|
-
return callback(myResult, null);
|
572
|
-
})
|
573
|
-
.catch((error) => {
|
574
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
575
|
-
return callback(null, error);
|
576
|
-
});
|
577
|
-
});
|
578
|
-
} catch (ex) {
|
579
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
580
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
581
|
-
return callback(null, errorObj);
|
503
|
+
return super.getDevice(deviceName, callback);
|
504
|
+
} catch (err) {
|
505
|
+
log.error(`${origin}: ${err}`);
|
506
|
+
return callback(null, err);
|
582
507
|
}
|
583
508
|
}
|
584
509
|
|
@@ -596,88 +521,11 @@ class Meraki extends AdapterBaseCl {
|
|
596
521
|
const origin = `${this.id}-${meth}`;
|
597
522
|
log.trace(origin);
|
598
523
|
|
599
|
-
// make sure we are set up for device broker getDevicesFiltered
|
600
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevicesFiltered || this.allProps.devicebroker.getDevicesFiltered.length === 0 || !this.allProps.devicebroker.getDevicesFiltered[0].path) {
|
601
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevicesFiltered.path'], null, null, null);
|
602
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
603
|
-
return callback(null, errorObj);
|
604
|
-
}
|
605
|
-
|
606
|
-
// verify the required fields have been provided
|
607
|
-
if (options === undefined || options === null || options === '' || options.length === 0) {
|
608
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
609
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
610
|
-
return callback(null, errorObj);
|
611
|
-
}
|
612
|
-
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
613
|
-
|
614
524
|
try {
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
// set up the filter of Device Names
|
620
|
-
let filterName = [];
|
621
|
-
if (options && options.filter && options.filter.name) {
|
622
|
-
// when this hack is removed, remove the lint ignore above
|
623
|
-
if (Array.isArray(options.filter.name)) {
|
624
|
-
// eslint-disable-next-line prefer-destructuring
|
625
|
-
filterName = options.filter.name;
|
626
|
-
} else {
|
627
|
-
filterName = [options.filter.name];
|
628
|
-
}
|
629
|
-
}
|
630
|
-
|
631
|
-
// TODO - get sort and order working
|
632
|
-
/*
|
633
|
-
if (options && options.sort) {
|
634
|
-
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
635
|
-
}
|
636
|
-
if (options && options.order) {
|
637
|
-
reqObj.uriOptions.order = options.order;
|
638
|
-
}
|
639
|
-
*/
|
640
|
-
const callPromises = [];
|
641
|
-
for (let i = 0; i < this.allProps.devicebroker.getDevicesFiltered.length; i += 1) {
|
642
|
-
// Perform component calls here.
|
643
|
-
callPromises.push(
|
644
|
-
new Promise((resolve, reject) => {
|
645
|
-
this.iapMakeBrokerCall('getDevicesFiltered', this.allProps.devicebroker.getDevicesFiltered[i], {}, filterName, (callRet, callErr) => {
|
646
|
-
// return an error
|
647
|
-
if (callErr) {
|
648
|
-
reject(callErr);
|
649
|
-
} else {
|
650
|
-
// return the data
|
651
|
-
resolve(callRet);
|
652
|
-
}
|
653
|
-
});
|
654
|
-
})
|
655
|
-
);
|
656
|
-
}
|
657
|
-
|
658
|
-
// return an array of repsonses
|
659
|
-
return Promise.all(callPromises).then((results) => {
|
660
|
-
let myResult = [];
|
661
|
-
results.forEach((result) => {
|
662
|
-
if (Array.isArray(result)) {
|
663
|
-
myResult = [...myResult, ...result];
|
664
|
-
} else if (Object.keys(result).length > 0) {
|
665
|
-
myResult.push(result);
|
666
|
-
}
|
667
|
-
});
|
668
|
-
|
669
|
-
log.debug(`${origin}: Found #${myResult.length} devices.`);
|
670
|
-
log.debug(`Devices: ${JSON.stringify(myResult)}`);
|
671
|
-
return callback({ total: myResult.length, list: myResult });
|
672
|
-
})
|
673
|
-
.catch((error) => {
|
674
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
675
|
-
return callback(null, error);
|
676
|
-
});
|
677
|
-
} catch (ex) {
|
678
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
679
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
680
|
-
return callback(null, errorObj);
|
525
|
+
return super.getDevicesFiltered(options, callback);
|
526
|
+
} catch (err) {
|
527
|
+
log.error(`${origin}: ${err}`);
|
528
|
+
return callback(null, err);
|
681
529
|
}
|
682
530
|
}
|
683
531
|
|
@@ -695,79 +543,11 @@ class Meraki extends AdapterBaseCl {
|
|
695
543
|
const origin = `${this.id}-${meth}`;
|
696
544
|
log.trace(origin);
|
697
545
|
|
698
|
-
// make sure we are set up for device broker isAlive
|
699
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.isAlive || this.allProps.devicebroker.isAlive.length === 0 || !this.allProps.devicebroker.isAlive[0].path) {
|
700
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.isAlive.path'], null, null, null);
|
701
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
702
|
-
return callback(null, errorObj);
|
703
|
-
}
|
704
|
-
|
705
|
-
// verify the required fields have been provided
|
706
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
707
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
708
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
709
|
-
return callback(null, errorObj);
|
710
|
-
}
|
711
|
-
|
712
546
|
try {
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
name: deviceName
|
718
|
-
}
|
719
|
-
};
|
720
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
721
|
-
// if we received an error or their is no response on the results return an error
|
722
|
-
if (ferr) {
|
723
|
-
return callback(null, ferr);
|
724
|
-
}
|
725
|
-
if (devs.list.length < 1) {
|
726
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
727
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
728
|
-
return callback(null, errorObj);
|
729
|
-
}
|
730
|
-
|
731
|
-
const callPromises = [];
|
732
|
-
for (let i = 0; i < this.allProps.devicebroker.isAlive.length; i += 1) {
|
733
|
-
// Perform component calls here.
|
734
|
-
callPromises.push(
|
735
|
-
new Promise((resolve, reject) => {
|
736
|
-
this.iapMakeBrokerCall('isAlive', this.allProps.devicebroker.isAlive[i], devs.list[0], null, (callRet, callErr) => {
|
737
|
-
// return an error
|
738
|
-
if (callErr) {
|
739
|
-
reject(callErr);
|
740
|
-
} else {
|
741
|
-
// return the data
|
742
|
-
resolve(callRet);
|
743
|
-
}
|
744
|
-
});
|
745
|
-
})
|
746
|
-
);
|
747
|
-
}
|
748
|
-
|
749
|
-
// return an array of repsonses
|
750
|
-
return Promise.all(callPromises).then((results) => {
|
751
|
-
let myResult = {};
|
752
|
-
results.forEach((result) => {
|
753
|
-
myResult = { ...myResult, ...result };
|
754
|
-
});
|
755
|
-
|
756
|
-
let response = true;
|
757
|
-
if (myResult.isAlive !== null && myResult.isAlive !== undefined && myResult.isAlive === false) {
|
758
|
-
response = false;
|
759
|
-
}
|
760
|
-
return callback(response);
|
761
|
-
})
|
762
|
-
.catch((error) => {
|
763
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
764
|
-
return callback(null, error);
|
765
|
-
});
|
766
|
-
});
|
767
|
-
} catch (ex) {
|
768
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
769
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
770
|
-
return callback(null, errorObj);
|
547
|
+
return super.isAlive(deviceName, callback);
|
548
|
+
} catch (err) {
|
549
|
+
log.error(`${origin}: ${err}`);
|
550
|
+
return callback(null, err);
|
771
551
|
}
|
772
552
|
}
|
773
553
|
|
@@ -786,79 +566,11 @@ class Meraki extends AdapterBaseCl {
|
|
786
566
|
const origin = `${this.id}-${meth}`;
|
787
567
|
log.trace(origin);
|
788
568
|
|
789
|
-
// make sure we are set up for device broker getConfig
|
790
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getConfig || this.allProps.devicebroker.getConfig.length === 0 || !this.allProps.devicebroker.getConfig[0].path) {
|
791
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getConfig.path'], null, null, null);
|
792
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
793
|
-
return callback(null, errorObj);
|
794
|
-
}
|
795
|
-
|
796
|
-
// verify the required fields have been provided
|
797
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
798
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
799
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
800
|
-
return callback(null, errorObj);
|
801
|
-
}
|
802
|
-
|
803
569
|
try {
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
name: deviceName
|
809
|
-
}
|
810
|
-
};
|
811
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
812
|
-
// if we received an error or their is no response on the results return an error
|
813
|
-
if (ferr) {
|
814
|
-
return callback(null, ferr);
|
815
|
-
}
|
816
|
-
if (devs.list.length < 1) {
|
817
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
818
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
819
|
-
return callback(null, errorObj);
|
820
|
-
}
|
821
|
-
|
822
|
-
const callPromises = [];
|
823
|
-
for (let i = 0; i < this.allProps.devicebroker.getConfig.length; i += 1) {
|
824
|
-
// Perform component calls here.
|
825
|
-
callPromises.push(
|
826
|
-
new Promise((resolve, reject) => {
|
827
|
-
this.iapMakeBrokerCall('getConfig', this.allProps.devicebroker.getConfig[i], devs.list[0], null, (callRet, callErr) => {
|
828
|
-
// return an error
|
829
|
-
if (callErr) {
|
830
|
-
reject(callErr);
|
831
|
-
} else {
|
832
|
-
// return the data
|
833
|
-
resolve(callRet);
|
834
|
-
}
|
835
|
-
});
|
836
|
-
})
|
837
|
-
);
|
838
|
-
}
|
839
|
-
|
840
|
-
// return an array of repsonses
|
841
|
-
return Promise.all(callPromises).then((results) => {
|
842
|
-
let myResult = {};
|
843
|
-
results.forEach((result) => {
|
844
|
-
myResult = { ...myResult, ...result };
|
845
|
-
});
|
846
|
-
|
847
|
-
// return the result
|
848
|
-
const newResponse = {
|
849
|
-
response: JSON.stringify(myResult, null, 2)
|
850
|
-
};
|
851
|
-
return callback(newResponse, null);
|
852
|
-
})
|
853
|
-
.catch((error) => {
|
854
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
855
|
-
return callback(null, error);
|
856
|
-
});
|
857
|
-
});
|
858
|
-
} catch (ex) {
|
859
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
860
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
861
|
-
return callback(null, errorObj);
|
570
|
+
return super.getConfig(deviceName, format, callback);
|
571
|
+
} catch (err) {
|
572
|
+
log.error(`${origin}: ${err}`);
|
573
|
+
return callback(null, err);
|
862
574
|
}
|
863
575
|
}
|
864
576
|
|
@@ -875,52 +587,11 @@ class Meraki extends AdapterBaseCl {
|
|
875
587
|
const origin = `${this.id}-${meth}`;
|
876
588
|
log.trace(origin);
|
877
589
|
|
878
|
-
// make sure we are set up for device broker getCount
|
879
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getCount || this.allProps.devicebroker.getCount.length === 0 || !this.allProps.devicebroker.getCount[0].path) {
|
880
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getCount.path'], null, null, null);
|
881
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
882
|
-
return callback(null, errorObj);
|
883
|
-
}
|
884
|
-
|
885
|
-
// verify the required fields have been provided
|
886
|
-
|
887
590
|
try {
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
new Promise((resolve, reject) => {
|
893
|
-
this.iapMakeBrokerCall('getCount', this.allProps.devicebroker.getCount[i], null, null, (callRet, callErr) => {
|
894
|
-
// return an error
|
895
|
-
if (callErr) {
|
896
|
-
reject(callErr);
|
897
|
-
} else {
|
898
|
-
// return the data
|
899
|
-
resolve(callRet);
|
900
|
-
}
|
901
|
-
});
|
902
|
-
})
|
903
|
-
);
|
904
|
-
}
|
905
|
-
|
906
|
-
// return an array of repsonses
|
907
|
-
return Promise.all(callPromises).then((results) => {
|
908
|
-
let myResult = {};
|
909
|
-
results.forEach((result) => {
|
910
|
-
myResult = { ...myResult, ...result };
|
911
|
-
});
|
912
|
-
|
913
|
-
// return the result
|
914
|
-
return callback({ count: myResult.length });
|
915
|
-
})
|
916
|
-
.catch((error) => {
|
917
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
918
|
-
return callback(null, error);
|
919
|
-
});
|
920
|
-
} catch (ex) {
|
921
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
922
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
923
|
-
return callback(null, errorObj);
|
591
|
+
return super.iapGetDeviceCount(callback);
|
592
|
+
} catch (err) {
|
593
|
+
log.error(`${origin}: ${err}`);
|
594
|
+
return callback(null, err);
|
924
595
|
}
|
925
596
|
}
|
926
597
|
|
@@ -1035,6 +706,116 @@ class Meraki extends AdapterBaseCl {
|
|
1035
706
|
}
|
1036
707
|
}
|
1037
708
|
|
709
|
+
/**
|
710
|
+
* Makes the requested generic call with no base path or version
|
711
|
+
*
|
712
|
+
* @function genericAdapterRequestNoBasePath
|
713
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
714
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
715
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
716
|
+
* Can be a stringified Object.
|
717
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
718
|
+
* Can be a stringified Object.
|
719
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
720
|
+
* Can be a stringified Object.
|
721
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
722
|
+
* or the error
|
723
|
+
*/
|
724
|
+
genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
725
|
+
const meth = 'adapter-genericAdapterRequestNoBasePath';
|
726
|
+
const origin = `${this.id}-${meth}`;
|
727
|
+
log.trace(origin);
|
728
|
+
|
729
|
+
if (this.suspended && this.suspendMode === 'error') {
|
730
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
731
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
732
|
+
return callback(null, errorObj);
|
733
|
+
}
|
734
|
+
|
735
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
736
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
737
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
738
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
739
|
+
return callback(null, errorObj);
|
740
|
+
}
|
741
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
742
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
743
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
744
|
+
return callback(null, errorObj);
|
745
|
+
}
|
746
|
+
|
747
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
748
|
+
// remove any leading / and split the uripath into path variables
|
749
|
+
let myPath = uriPath;
|
750
|
+
while (myPath.indexOf('/') === 0) {
|
751
|
+
myPath = myPath.substring(1);
|
752
|
+
}
|
753
|
+
const pathVars = myPath.split('/');
|
754
|
+
const queryParamsAvailable = queryData;
|
755
|
+
const queryParams = {};
|
756
|
+
const bodyVars = requestBody;
|
757
|
+
|
758
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
759
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
760
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
761
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
762
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
763
|
+
}
|
764
|
+
});
|
765
|
+
|
766
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
767
|
+
const reqObj = {
|
768
|
+
payload: bodyVars,
|
769
|
+
uriPathVars: pathVars,
|
770
|
+
uriQuery: queryParams,
|
771
|
+
uriOptions: {}
|
772
|
+
};
|
773
|
+
// add headers if provided
|
774
|
+
if (addlHeaders) {
|
775
|
+
reqObj.addlHeaders = addlHeaders;
|
776
|
+
}
|
777
|
+
|
778
|
+
// determine the call and return flag
|
779
|
+
let action = 'getGenericsNoBase';
|
780
|
+
let returnF = true;
|
781
|
+
if (restMethod.toUpperCase() === 'POST') {
|
782
|
+
action = 'createGenericNoBase';
|
783
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
784
|
+
action = 'updateGenericNoBase';
|
785
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
786
|
+
action = 'patchGenericNoBase';
|
787
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
788
|
+
action = 'deleteGenericNoBase';
|
789
|
+
returnF = false;
|
790
|
+
}
|
791
|
+
|
792
|
+
try {
|
793
|
+
// Make the call -
|
794
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
795
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
796
|
+
// if we received an error or their is no response on the results
|
797
|
+
// return an error
|
798
|
+
if (irReturnError) {
|
799
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
800
|
+
return callback(null, irReturnError);
|
801
|
+
}
|
802
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
803
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
|
804
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
805
|
+
return callback(null, errorObj);
|
806
|
+
}
|
807
|
+
|
808
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
809
|
+
// return the response
|
810
|
+
return callback(irReturnData, null);
|
811
|
+
});
|
812
|
+
} catch (ex) {
|
813
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
814
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
815
|
+
return callback(null, errorObj);
|
816
|
+
}
|
817
|
+
}
|
818
|
+
|
1038
819
|
/**
|
1039
820
|
* @callback healthCallback
|
1040
821
|
* @param {Object} result - the result of the get request (contains an id and a status)
|