@itentialopensource/adapter-netbox_v210 0.1.1 → 0.2.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/CHANGELOG.md +24 -1
- package/adapter.js +551 -1
- package/adapterBase.js +23 -1
- package/entities/.generic/action.json +5 -5
- package/entities/Graphql/action.json +25 -0
- package/entities/Graphql/schema.json +19 -0
- package/package.json +11 -7
- package/pronghorn.json +226 -0
- package/propertiesSchema.json +1 -1
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1644852199348.json +95 -0
- package/test/integration/adapterTestIntegration.js +28 -0
- package/test/unit/adapterBaseTestUnit.js +1 -1
- package/test/unit/adapterTestUnit.js +131 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +0 -0
- package/utils/basicGet.js +1 -14
- package/utils/entitiesToDB.js +224 -0
- package/utils/modify.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +14 -8
- package/utils/tbUtils.js +70 -8
- package/utils/troubleshootingAdapter.js +2 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
|
|
2
|
+
## 0.2.1 [03-07-2022]
|
|
3
|
+
|
|
4
|
+
* fix graphql sendGetBody
|
|
5
|
+
|
|
6
|
+
See merge request itentialopensource/adapters/inventory/adapter-netbox_v210!3
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 0.2.0 [02-14-2022]
|
|
11
|
+
|
|
12
|
+
* migration and add new call - getGraphql
|
|
13
|
+
|
|
14
|
+
See merge request itentialopensource/adapters/inventory/adapter-netbox_v210!2
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 0.1.2 [12-30-2021]
|
|
19
|
+
|
|
20
|
+
* Add / to generic call paths
|
|
21
|
+
|
|
22
|
+
See merge request itentialopensource/adapters/inventory/adapter-netbox_v210!1
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
2
26
|
## 0.1.1 [08-02-2021]
|
|
3
27
|
|
|
4
28
|
* Bug fixes and performance improvements
|
|
@@ -6,4 +30,3 @@
|
|
|
6
30
|
See commit 1173452
|
|
7
31
|
|
|
8
32
|
---
|
|
9
|
-
|
package/adapter.js
CHANGED
|
@@ -83,7 +83,7 @@ class NetboxV210 extends AdapterBaseCl {
|
|
|
83
83
|
* @getWorkflowFunctions
|
|
84
84
|
*/
|
|
85
85
|
getWorkflowFunctions(inIgnore) {
|
|
86
|
-
let myIgnore = [];
|
|
86
|
+
let myIgnore = ['hasEntities', 'hasDevices'];
|
|
87
87
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
88
88
|
myIgnore = inIgnore;
|
|
89
89
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
@@ -247,6 +247,24 @@ class NetboxV210 extends AdapterBaseCl {
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/**
|
|
251
|
+
* @summary moves entites into Mongo DB
|
|
252
|
+
*
|
|
253
|
+
* @function moveEntitiesToDB
|
|
254
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
255
|
+
* or the error
|
|
256
|
+
*/
|
|
257
|
+
moveEntitiesToDB(callback) {
|
|
258
|
+
const origin = `${this.id}-adapter-moveEntitiesToDB`;
|
|
259
|
+
log.trace(origin);
|
|
260
|
+
try {
|
|
261
|
+
return super.moveEntitiesToDB(callback);
|
|
262
|
+
} catch (err) {
|
|
263
|
+
log.error(`${origin}: ${err}`);
|
|
264
|
+
return callback(null, err);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
250
268
|
/**
|
|
251
269
|
* @summary Determines if this adapter supports the specific entity
|
|
252
270
|
*
|
|
@@ -526,6 +544,456 @@ class NetboxV210 extends AdapterBaseCl {
|
|
|
526
544
|
}
|
|
527
545
|
}
|
|
528
546
|
|
|
547
|
+
/* BROKER CALLS */
|
|
548
|
+
/**
|
|
549
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
550
|
+
*
|
|
551
|
+
* @function hasEntities
|
|
552
|
+
* @param {String} entityType - the entity type to check for
|
|
553
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
554
|
+
*
|
|
555
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
556
|
+
* value is true or false
|
|
557
|
+
*/
|
|
558
|
+
hasEntities(entityType, entityList, callback) {
|
|
559
|
+
const origin = `${this.id}-adapter-hasEntities`;
|
|
560
|
+
log.trace(origin);
|
|
561
|
+
|
|
562
|
+
switch (entityType) {
|
|
563
|
+
case 'Device':
|
|
564
|
+
return this.hasDevices(entityList, callback);
|
|
565
|
+
default:
|
|
566
|
+
return callback(null, `${this.id} does not support entity ${entityType}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* @summary Helper method for hasEntities for the specific device case
|
|
572
|
+
*
|
|
573
|
+
* @param {Array} deviceList - array of unique device identifiers
|
|
574
|
+
* @param {Callback} callback - A map where the device is the key and the
|
|
575
|
+
* value is true or false
|
|
576
|
+
*/
|
|
577
|
+
hasDevices(deviceList, callback) {
|
|
578
|
+
const origin = `${this.id}-adapter-hasDevices`;
|
|
579
|
+
log.trace(origin);
|
|
580
|
+
|
|
581
|
+
const findings = deviceList.reduce((map, device) => {
|
|
582
|
+
// eslint-disable-next-line no-param-reassign
|
|
583
|
+
map[device] = false;
|
|
584
|
+
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
585
|
+
return map;
|
|
586
|
+
}, {});
|
|
587
|
+
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
588
|
+
this.getDevice(device, (result, error) => {
|
|
589
|
+
if (error) {
|
|
590
|
+
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
591
|
+
return resolve({ name: device, found: false });
|
|
592
|
+
}
|
|
593
|
+
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
594
|
+
return resolve({ name: device, found: true });
|
|
595
|
+
});
|
|
596
|
+
}));
|
|
597
|
+
Promise.all(apiCalls).then((results) => {
|
|
598
|
+
results.forEach((device) => {
|
|
599
|
+
findings[device.name] = device.found;
|
|
600
|
+
});
|
|
601
|
+
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
602
|
+
return callback(findings);
|
|
603
|
+
}).catch((errors) => {
|
|
604
|
+
log.error('Unable to do device lookup.');
|
|
605
|
+
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* @summary Get Appliance that match the deviceName
|
|
611
|
+
*
|
|
612
|
+
* @function getDevice
|
|
613
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
614
|
+
*
|
|
615
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
616
|
+
* (appliance) or the error
|
|
617
|
+
*/
|
|
618
|
+
getDevice(deviceName, callback) {
|
|
619
|
+
const meth = 'adapter-getDevice';
|
|
620
|
+
const origin = `${this.id}-${meth}`;
|
|
621
|
+
log.trace(origin);
|
|
622
|
+
|
|
623
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
624
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
625
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
626
|
+
return callback(null, errorObj);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
630
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
631
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
632
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
633
|
+
return callback(null, errorObj);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
try {
|
|
637
|
+
// need to get the device so we can convert the deviceName to an id
|
|
638
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
639
|
+
const opts = {
|
|
640
|
+
filter: {
|
|
641
|
+
name: deviceName
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
645
|
+
// if we received an error or their is no response on the results return an error
|
|
646
|
+
if (ferr) {
|
|
647
|
+
return callback(null, ferr);
|
|
648
|
+
}
|
|
649
|
+
if (devs.list.length < 1) {
|
|
650
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
651
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
652
|
+
return callback(null, errorObj);
|
|
653
|
+
}
|
|
654
|
+
// get the uuid from the device
|
|
655
|
+
const { uuid } = devs.list[0];
|
|
656
|
+
|
|
657
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
658
|
+
// !! you can also replace with a specific call if that is easier
|
|
659
|
+
const uriPath = `/call/toget/device/${uuid}`;
|
|
660
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
661
|
+
// if we received an error or their is no response on the results return an error
|
|
662
|
+
if (error) {
|
|
663
|
+
return callback(null, error);
|
|
664
|
+
}
|
|
665
|
+
if (!result.response || !result.response.applianceMo) {
|
|
666
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
|
|
667
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
668
|
+
return callback(null, errorObj);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// return the response
|
|
672
|
+
// !! format the data we send back
|
|
673
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
674
|
+
const thisDevice = result.response;
|
|
675
|
+
thisDevice.name = thisDevice.systemName;
|
|
676
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
677
|
+
thisDevice.port = thisDevice.systemPort;
|
|
678
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
679
|
+
return callback(thisDevice);
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
} catch (ex) {
|
|
683
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
684
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
685
|
+
return callback(null, errorObj);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* @summary Get Appliances that match the filter
|
|
691
|
+
*
|
|
692
|
+
* @function getDevicesFiltered
|
|
693
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
694
|
+
*
|
|
695
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
696
|
+
* (appliances) or the error
|
|
697
|
+
*/
|
|
698
|
+
getDevicesFiltered(options, callback) {
|
|
699
|
+
const meth = 'adapter-getDevicesFiltered';
|
|
700
|
+
const origin = `${this.id}-${meth}`;
|
|
701
|
+
log.trace(origin);
|
|
702
|
+
|
|
703
|
+
// verify the required fields have been provided
|
|
704
|
+
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
705
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
706
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
707
|
+
return callback(null, errorObj);
|
|
708
|
+
}
|
|
709
|
+
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
|
710
|
+
|
|
711
|
+
// TODO - get pagination working
|
|
712
|
+
// const nextToken = options.start;
|
|
713
|
+
// const maxResults = options.limit;
|
|
714
|
+
|
|
715
|
+
// set up the filter of Device Names
|
|
716
|
+
let filterName = [];
|
|
717
|
+
if (options && options.filter && options.filter.name) {
|
|
718
|
+
// when this hack is removed, remove the lint ignore above
|
|
719
|
+
if (Array.isArray(options.filter.name)) {
|
|
720
|
+
// eslint-disable-next-line prefer-destructuring
|
|
721
|
+
filterName = options.filter.name;
|
|
722
|
+
} else {
|
|
723
|
+
filterName = [options.filter.name];
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// TODO - get sort and order working
|
|
728
|
+
/*
|
|
729
|
+
if (options && options.sort) {
|
|
730
|
+
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
731
|
+
}
|
|
732
|
+
if (options && options.order) {
|
|
733
|
+
reqObj.uriOptions.order = options.order;
|
|
734
|
+
}
|
|
735
|
+
*/
|
|
736
|
+
try {
|
|
737
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
738
|
+
// !! you can also replace with a specific call if that is easier
|
|
739
|
+
const uriPath = '/call/toget/devices';
|
|
740
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
741
|
+
// if we received an error or their is no response on the results return an error
|
|
742
|
+
if (error) {
|
|
743
|
+
return callback(null, error);
|
|
744
|
+
}
|
|
745
|
+
if (!result.response) {
|
|
746
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
|
747
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
748
|
+
return callback(null, errorObj);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// !! go through the response - may have to look for sub object
|
|
752
|
+
// handle an array of devices
|
|
753
|
+
if (Array.isArray(result.response)) {
|
|
754
|
+
const myDevices = [];
|
|
755
|
+
|
|
756
|
+
for (let d = 0; d < result.response.length; d += 1) {
|
|
757
|
+
// !! format the data we send back
|
|
758
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
759
|
+
const thisDevice = result.response;
|
|
760
|
+
thisDevice.name = thisDevice.systemName;
|
|
761
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
762
|
+
thisDevice.port = thisDevice.systemPort;
|
|
763
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
764
|
+
|
|
765
|
+
// if there is no filter - return the device
|
|
766
|
+
if (filterName.length === 0) {
|
|
767
|
+
myDevices.push(thisDevice);
|
|
768
|
+
} else {
|
|
769
|
+
// if we have to match a filter
|
|
770
|
+
let found = false;
|
|
771
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
772
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
773
|
+
found = true;
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// matching device
|
|
778
|
+
if (found) {
|
|
779
|
+
myDevices.push(thisDevice);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
log.debug(`${origin}: Found #${myDevices.length} devices.`);
|
|
784
|
+
log.debug(`Devices: ${JSON.stringify(myDevices)}`);
|
|
785
|
+
return callback({ total: myDevices.length, list: myDevices });
|
|
786
|
+
}
|
|
787
|
+
// handle a single device response
|
|
788
|
+
// !! format the data we send back
|
|
789
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
790
|
+
const thisDevice = result.response;
|
|
791
|
+
thisDevice.name = thisDevice.systemName;
|
|
792
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
793
|
+
thisDevice.port = thisDevice.systemPort;
|
|
794
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
795
|
+
|
|
796
|
+
// if there is no filter - return the device
|
|
797
|
+
if (filterName.length === 0) {
|
|
798
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
799
|
+
log.debug(`Device: ${JSON.stringify(thisDevice)}`);
|
|
800
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// if there is a filter need to check for matching device
|
|
804
|
+
let found = false;
|
|
805
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
806
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
807
|
+
found = true;
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
// matching device
|
|
812
|
+
if (found) {
|
|
813
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
814
|
+
log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
|
|
815
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
816
|
+
}
|
|
817
|
+
// not a matching device
|
|
818
|
+
log.debug(`${origin}: No matching device found.`);
|
|
819
|
+
return callback({ total: 0, list: [] });
|
|
820
|
+
});
|
|
821
|
+
} catch (ex) {
|
|
822
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
823
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
824
|
+
return callback(null, errorObj);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* @summary Gets the status for the provided appliance
|
|
830
|
+
*
|
|
831
|
+
* @function isAlive
|
|
832
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
833
|
+
*
|
|
834
|
+
* @param {configCallback} callback - callback function to return the result
|
|
835
|
+
* (appliance isAlive) or the error
|
|
836
|
+
*/
|
|
837
|
+
isAlive(deviceName, callback) {
|
|
838
|
+
const meth = 'adapter-isAlive';
|
|
839
|
+
const origin = `${this.id}-${meth}`;
|
|
840
|
+
log.trace(origin);
|
|
841
|
+
|
|
842
|
+
// verify the required fields have been provided
|
|
843
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
844
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
845
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
846
|
+
return callback(null, errorObj);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
try {
|
|
850
|
+
// need to get the device so we can convert the deviceName to an id
|
|
851
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
852
|
+
const opts = {
|
|
853
|
+
filter: {
|
|
854
|
+
name: deviceName
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
858
|
+
// if we received an error or their is no response on the results return an error
|
|
859
|
+
if (ferr) {
|
|
860
|
+
return callback(null, ferr);
|
|
861
|
+
}
|
|
862
|
+
if (devs.list.length < 1) {
|
|
863
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
864
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
865
|
+
return callback(null, errorObj);
|
|
866
|
+
}
|
|
867
|
+
// get the uuid from the device
|
|
868
|
+
const { uuid } = devs.list[0];
|
|
869
|
+
|
|
870
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
871
|
+
// !! you can also replace with a specific call if that is easier
|
|
872
|
+
const uriPath = `/call/toget/status/${uuid}`;
|
|
873
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
874
|
+
// if we received an error or their is no response on the results return an error
|
|
875
|
+
if (error) {
|
|
876
|
+
return callback(null, error);
|
|
877
|
+
}
|
|
878
|
+
// !! should update this to make sure we are checking for the appropriate object/field
|
|
879
|
+
if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
|
|
880
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
|
|
881
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
882
|
+
return callback(null, errorObj);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// !! return the response - Update to the appropriate object/field
|
|
886
|
+
return callback(!result.response.returnObj.statusField);
|
|
887
|
+
});
|
|
888
|
+
});
|
|
889
|
+
} catch (ex) {
|
|
890
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
891
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
892
|
+
return callback(null, errorObj);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* @summary Gets a config for the provided Appliance
|
|
898
|
+
*
|
|
899
|
+
* @function getConfig
|
|
900
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
901
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
902
|
+
*
|
|
903
|
+
* @param {configCallback} callback - callback function to return the result
|
|
904
|
+
* (appliance config) or the error
|
|
905
|
+
*/
|
|
906
|
+
getConfig(deviceName, format, callback) {
|
|
907
|
+
const meth = 'adapter-getConfig';
|
|
908
|
+
const origin = `${this.id}-${meth}`;
|
|
909
|
+
log.trace(origin);
|
|
910
|
+
|
|
911
|
+
// verify the required fields have been provided
|
|
912
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
913
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
914
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
915
|
+
return callback(null, errorObj);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
try {
|
|
919
|
+
// need to get the device so we can convert the deviceName to an id
|
|
920
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
921
|
+
const opts = {
|
|
922
|
+
filter: {
|
|
923
|
+
name: deviceName
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
927
|
+
// if we received an error or their is no response on the results return an error
|
|
928
|
+
if (ferr) {
|
|
929
|
+
return callback(null, ferr);
|
|
930
|
+
}
|
|
931
|
+
if (devs.list.length < 1) {
|
|
932
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
933
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
934
|
+
return callback(null, errorObj);
|
|
935
|
+
}
|
|
936
|
+
// get the uuid from the device
|
|
937
|
+
const { uuid } = devs.list[0];
|
|
938
|
+
|
|
939
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
940
|
+
// !! you can also replace with a specific call if that is easier
|
|
941
|
+
const uriPath = `/call/toget/config/${uuid}`;
|
|
942
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
943
|
+
// if we received an error or their is no response on the results return an error
|
|
944
|
+
if (error) {
|
|
945
|
+
return callback(null, error);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// return the result
|
|
949
|
+
const newResponse = {
|
|
950
|
+
response: JSON.stringify(result.response, null, 2)
|
|
951
|
+
};
|
|
952
|
+
return callback(newResponse);
|
|
953
|
+
});
|
|
954
|
+
});
|
|
955
|
+
} catch (ex) {
|
|
956
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
957
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
958
|
+
return callback(null, errorObj);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* @summary Gets the device count from the system
|
|
964
|
+
*
|
|
965
|
+
* @function getCount
|
|
966
|
+
*
|
|
967
|
+
* @param {getCallback} callback - callback function to return the result
|
|
968
|
+
* (count) or the error
|
|
969
|
+
*/
|
|
970
|
+
getCount(callback) {
|
|
971
|
+
const meth = 'adapter-getCount';
|
|
972
|
+
const origin = `${this.id}-${meth}`;
|
|
973
|
+
log.trace(origin);
|
|
974
|
+
|
|
975
|
+
// verify the required fields have been provided
|
|
976
|
+
|
|
977
|
+
try {
|
|
978
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
979
|
+
// !! you can also replace with a specific call if that is easier
|
|
980
|
+
const uriPath = '/call/toget/count';
|
|
981
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
982
|
+
// if we received an error or their is no response on the results return an error
|
|
983
|
+
if (error) {
|
|
984
|
+
return callback(null, error);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// return the result
|
|
988
|
+
return callback({ count: result.response });
|
|
989
|
+
});
|
|
990
|
+
} catch (ex) {
|
|
991
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
992
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
993
|
+
return callback(null, errorObj);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
529
997
|
/**
|
|
530
998
|
* @callback healthCallback
|
|
531
999
|
* @param {Object} result - the result of the get request (contains an id and a status)
|
|
@@ -44593,6 +45061,88 @@ This request will yield a base64-encoded session key to be included in an `X-Ses
|
|
|
44593
45061
|
}
|
|
44594
45062
|
}
|
|
44595
45063
|
|
|
45064
|
+
/**
|
|
45065
|
+
* @function getGraphql
|
|
45066
|
+
* @pronghornType method
|
|
45067
|
+
* @name getGraphql
|
|
45068
|
+
* @summary A lightweight read-only endpoint for conveying querying using graphql.
|
|
45069
|
+
*
|
|
45070
|
+
* @param {object} body - graphql query data
|
|
45071
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
45072
|
+
* @return {object} results - An object containing the response of the action
|
|
45073
|
+
*
|
|
45074
|
+
* @route {GET} /getGraphql
|
|
45075
|
+
* @roles admin
|
|
45076
|
+
* @task true
|
|
45077
|
+
*/
|
|
45078
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
45079
|
+
getGraphql(body, callback) {
|
|
45080
|
+
const meth = 'adapter-getGraphql';
|
|
45081
|
+
const origin = `${this.id}-${meth}`;
|
|
45082
|
+
log.trace(origin);
|
|
45083
|
+
|
|
45084
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
45085
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
45086
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45087
|
+
return callback(null, errorObj);
|
|
45088
|
+
}
|
|
45089
|
+
|
|
45090
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
45091
|
+
if (body === undefined || body === null || body === '') {
|
|
45092
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
45093
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45094
|
+
return callback(null, errorObj);
|
|
45095
|
+
}
|
|
45096
|
+
|
|
45097
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
45098
|
+
const queryParamsAvailable = {};
|
|
45099
|
+
const queryParams = {};
|
|
45100
|
+
const pathVars = [];
|
|
45101
|
+
const bodyVars = body;
|
|
45102
|
+
|
|
45103
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
45104
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
45105
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
45106
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
45107
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
45108
|
+
}
|
|
45109
|
+
});
|
|
45110
|
+
|
|
45111
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
45112
|
+
// see adapter code documentation for more information on the request object's fields
|
|
45113
|
+
const reqObj = {
|
|
45114
|
+
payload: bodyVars,
|
|
45115
|
+
uriPathVars: pathVars,
|
|
45116
|
+
uriQuery: queryParams
|
|
45117
|
+
};
|
|
45118
|
+
|
|
45119
|
+
try {
|
|
45120
|
+
// Make the call -
|
|
45121
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
45122
|
+
return this.requestHandlerInst.identifyRequest('Graphql', 'getGraphql', reqObj, true, (irReturnData, irReturnError) => {
|
|
45123
|
+
// if we received an error or their is no response on the results
|
|
45124
|
+
// return an error
|
|
45125
|
+
if (irReturnError) {
|
|
45126
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
45127
|
+
return callback(null, irReturnError);
|
|
45128
|
+
}
|
|
45129
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
45130
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getGraphql'], null, null, null);
|
|
45131
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45132
|
+
return callback(null, errorObj);
|
|
45133
|
+
}
|
|
45134
|
+
|
|
45135
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
45136
|
+
// return the response
|
|
45137
|
+
return callback(irReturnData, null);
|
|
45138
|
+
});
|
|
45139
|
+
} catch (ex) {
|
|
45140
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
45141
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45142
|
+
return callback(null, errorObj);
|
|
45143
|
+
}
|
|
45144
|
+
}
|
|
45145
|
+
|
|
44596
45146
|
/**
|
|
44597
45147
|
* @function getTenancyTenantGroups
|
|
44598
45148
|
* @pronghornType method
|
package/adapterBase.js
CHANGED
|
@@ -22,6 +22,7 @@ const AjvCl = require('ajv');
|
|
|
22
22
|
const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
|
|
23
23
|
const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHandler;
|
|
24
24
|
|
|
25
|
+
const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
|
|
25
26
|
const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
|
|
26
27
|
const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
|
|
27
28
|
|
|
@@ -821,7 +822,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
821
822
|
*/
|
|
822
823
|
async runConnectivity(callback) {
|
|
823
824
|
try {
|
|
824
|
-
const { serviceItem } = await
|
|
825
|
+
const { serviceItem } = await tbUtils.getAdapterConfig();
|
|
825
826
|
const { host } = serviceItem.properties.properties;
|
|
826
827
|
const result = tbUtils.runConnectivity(host, false);
|
|
827
828
|
if (result.failCount > 0) {
|
|
@@ -1001,6 +1002,27 @@ class AdapterBase extends EventEmitterCl {
|
|
|
1001
1002
|
return [];
|
|
1002
1003
|
}
|
|
1003
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* @summary moves entities to mongo database
|
|
1008
|
+
*
|
|
1009
|
+
* @function moveEntitiesToDB
|
|
1010
|
+
*
|
|
1011
|
+
* @return {Callback} - containing the response from the mongo transaction
|
|
1012
|
+
*/
|
|
1013
|
+
moveEntitiesToDB(callback) {
|
|
1014
|
+
const meth = 'adapterBase-moveEntitiesToDB';
|
|
1015
|
+
const origin = `${this.id}-${meth}`;
|
|
1016
|
+
log.trace(origin);
|
|
1017
|
+
|
|
1018
|
+
try {
|
|
1019
|
+
return callback(entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
|
|
1020
|
+
} catch (err) {
|
|
1021
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
|
|
1022
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1023
|
+
return callback(null, errorObj);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1004
1026
|
}
|
|
1005
1027
|
|
|
1006
1028
|
module.exports = AdapterBase;
|