@itentialopensource/adapter-netbox 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/adapter.js CHANGED
@@ -98,7 +98,7 @@ class Netbox extends AdapterBaseCl {
98
98
  * @getWorkflowFunctions
99
99
  */
100
100
  getWorkflowFunctions(inIgnore) {
101
- let myIgnore = [];
101
+ let myIgnore = ['hasEntities', 'hasDevices'];
102
102
  if (!inIgnore && Array.isArray(inIgnore)) {
103
103
  myIgnore = inIgnore;
104
104
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -262,6 +262,24 @@ class Netbox extends AdapterBaseCl {
262
262
  }
263
263
  }
264
264
 
265
+ /**
266
+ * @summary moves entites into Mongo DB
267
+ *
268
+ * @function moveEntitiesToDB
269
+ * @param {getCallback} callback - a callback function to return the result (Generics)
270
+ * or the error
271
+ */
272
+ moveEntitiesToDB(callback) {
273
+ const origin = `${this.id}-adapter-moveEntitiesToDB`;
274
+ log.trace(origin);
275
+ try {
276
+ return super.moveEntitiesToDB(callback);
277
+ } catch (err) {
278
+ log.error(`${origin}: ${err}`);
279
+ return callback(null, err);
280
+ }
281
+ }
282
+
265
283
  /**
266
284
  * @summary Determines if this adapter supports the specific entity
267
285
  *
@@ -541,6 +559,456 @@ class Netbox extends AdapterBaseCl {
541
559
  }
542
560
  }
543
561
 
562
+ /* BROKER CALLS */
563
+ /**
564
+ * @summary Determines if this adapter supports any in a list of entities
565
+ *
566
+ * @function hasEntities
567
+ * @param {String} entityType - the entity type to check for
568
+ * @param {Array} entityList - the list of entities we are looking for
569
+ *
570
+ * @param {Callback} callback - A map where the entity is the key and the
571
+ * value is true or false
572
+ */
573
+ hasEntities(entityType, entityList, callback) {
574
+ const origin = `${this.id}-adapter-hasEntities`;
575
+ log.trace(origin);
576
+
577
+ switch (entityType) {
578
+ case 'Device':
579
+ return this.hasDevices(entityList, callback);
580
+ default:
581
+ return callback(null, `${this.id} does not support entity ${entityType}`);
582
+ }
583
+ }
584
+
585
+ /**
586
+ * @summary Helper method for hasEntities for the specific device case
587
+ *
588
+ * @param {Array} deviceList - array of unique device identifiers
589
+ * @param {Callback} callback - A map where the device is the key and the
590
+ * value is true or false
591
+ */
592
+ hasDevices(deviceList, callback) {
593
+ const origin = `${this.id}-adapter-hasDevices`;
594
+ log.trace(origin);
595
+
596
+ const findings = deviceList.reduce((map, device) => {
597
+ // eslint-disable-next-line no-param-reassign
598
+ map[device] = false;
599
+ log.debug(`In reduce: ${JSON.stringify(map)}`);
600
+ return map;
601
+ }, {});
602
+ const apiCalls = deviceList.map((device) => new Promise((resolve) => {
603
+ this.getDevice(device, (result, error) => {
604
+ if (error) {
605
+ log.debug(`In map error: ${JSON.stringify(device)}`);
606
+ return resolve({ name: device, found: false });
607
+ }
608
+ log.debug(`In map: ${JSON.stringify(device)}`);
609
+ return resolve({ name: device, found: true });
610
+ });
611
+ }));
612
+ Promise.all(apiCalls).then((results) => {
613
+ results.forEach((device) => {
614
+ findings[device.name] = device.found;
615
+ });
616
+ log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
617
+ return callback(findings);
618
+ }).catch((errors) => {
619
+ log.error('Unable to do device lookup.');
620
+ return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
621
+ });
622
+ }
623
+
624
+ /**
625
+ * @summary Get Appliance that match the deviceName
626
+ *
627
+ * @function getDevice
628
+ * @param {String} deviceName - the deviceName to find (required)
629
+ *
630
+ * @param {getCallback} callback - a callback function to return the result
631
+ * (appliance) or the error
632
+ */
633
+ getDevice(deviceName, callback) {
634
+ const meth = 'adapter-getDevice';
635
+ const origin = `${this.id}-${meth}`;
636
+ log.trace(origin);
637
+
638
+ if (this.suspended && this.suspendMode === 'error') {
639
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
640
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
641
+ return callback(null, errorObj);
642
+ }
643
+
644
+ /* HERE IS WHERE YOU VALIDATE DATA */
645
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
646
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
647
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
648
+ return callback(null, errorObj);
649
+ }
650
+
651
+ try {
652
+ // need to get the device so we can convert the deviceName to an id
653
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
654
+ const opts = {
655
+ filter: {
656
+ name: deviceName
657
+ }
658
+ };
659
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
660
+ // if we received an error or their is no response on the results return an error
661
+ if (ferr) {
662
+ return callback(null, ferr);
663
+ }
664
+ if (devs.list.length < 1) {
665
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
666
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
667
+ return callback(null, errorObj);
668
+ }
669
+ // get the uuid from the device
670
+ const { uuid } = devs.list[0];
671
+
672
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
673
+ // !! you can also replace with a specific call if that is easier
674
+ const uriPath = `/call/toget/device/${uuid}`;
675
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
676
+ // if we received an error or their is no response on the results return an error
677
+ if (error) {
678
+ return callback(null, error);
679
+ }
680
+ if (!result.response || !result.response.applianceMo) {
681
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
682
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
683
+ return callback(null, errorObj);
684
+ }
685
+
686
+ // return the response
687
+ // !! format the data we send back
688
+ // !! these fields are config manager fields you need to map to the data we receive
689
+ const thisDevice = result.response;
690
+ thisDevice.name = thisDevice.systemName;
691
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
692
+ thisDevice.port = thisDevice.systemPort;
693
+ thisDevice.ipaddress = thisDevice.systemIP;
694
+ return callback(thisDevice);
695
+ });
696
+ });
697
+ } catch (ex) {
698
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
699
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
700
+ return callback(null, errorObj);
701
+ }
702
+ }
703
+
704
+ /**
705
+ * @summary Get Appliances that match the filter
706
+ *
707
+ * @function getDevicesFiltered
708
+ * @param {Object} options - the data to use to filter the appliances (optional)
709
+ *
710
+ * @param {getCallback} callback - a callback function to return the result
711
+ * (appliances) or the error
712
+ */
713
+ getDevicesFiltered(options, callback) {
714
+ const meth = 'adapter-getDevicesFiltered';
715
+ const origin = `${this.id}-${meth}`;
716
+ log.trace(origin);
717
+
718
+ // verify the required fields have been provided
719
+ if (options === undefined || options === null || options === '' || options.length === 0) {
720
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
721
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
722
+ return callback(null, errorObj);
723
+ }
724
+ log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
725
+
726
+ // TODO - get pagination working
727
+ // const nextToken = options.start;
728
+ // const maxResults = options.limit;
729
+
730
+ // set up the filter of Device Names
731
+ let filterName = [];
732
+ if (options && options.filter && options.filter.name) {
733
+ // when this hack is removed, remove the lint ignore above
734
+ if (Array.isArray(options.filter.name)) {
735
+ // eslint-disable-next-line prefer-destructuring
736
+ filterName = options.filter.name;
737
+ } else {
738
+ filterName = [options.filter.name];
739
+ }
740
+ }
741
+
742
+ // TODO - get sort and order working
743
+ /*
744
+ if (options && options.sort) {
745
+ reqObj.uriOptions.sort = JSON.stringify(options.sort);
746
+ }
747
+ if (options && options.order) {
748
+ reqObj.uriOptions.order = options.order;
749
+ }
750
+ */
751
+ try {
752
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
753
+ // !! you can also replace with a specific call if that is easier
754
+ const uriPath = '/call/toget/devices';
755
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
756
+ // if we received an error or their is no response on the results return an error
757
+ if (error) {
758
+ return callback(null, error);
759
+ }
760
+ if (!result.response) {
761
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
762
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
763
+ return callback(null, errorObj);
764
+ }
765
+
766
+ // !! go through the response - may have to look for sub object
767
+ // handle an array of devices
768
+ if (Array.isArray(result.response)) {
769
+ const myDevices = [];
770
+
771
+ for (let d = 0; d < result.response.length; d += 1) {
772
+ // !! format the data we send back
773
+ // !! these fields are config manager fields you need to map to the data we receive
774
+ const thisDevice = result.response;
775
+ thisDevice.name = thisDevice.systemName;
776
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
777
+ thisDevice.port = thisDevice.systemPort;
778
+ thisDevice.ipaddress = thisDevice.systemIP;
779
+
780
+ // if there is no filter - return the device
781
+ if (filterName.length === 0) {
782
+ myDevices.push(thisDevice);
783
+ } else {
784
+ // if we have to match a filter
785
+ let found = false;
786
+ for (let f = 0; f < filterName.length; f += 1) {
787
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
788
+ found = true;
789
+ break;
790
+ }
791
+ }
792
+ // matching device
793
+ if (found) {
794
+ myDevices.push(thisDevice);
795
+ }
796
+ }
797
+ }
798
+ log.debug(`${origin}: Found #${myDevices.length} devices.`);
799
+ log.debug(`Devices: ${JSON.stringify(myDevices)}`);
800
+ return callback({ total: myDevices.length, list: myDevices });
801
+ }
802
+ // handle a single device response
803
+ // !! format the data we send back
804
+ // !! these fields are config manager fields you need to map to the data we receive
805
+ const thisDevice = result.response;
806
+ thisDevice.name = thisDevice.systemName;
807
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
808
+ thisDevice.port = thisDevice.systemPort;
809
+ thisDevice.ipaddress = thisDevice.systemIP;
810
+
811
+ // if there is no filter - return the device
812
+ if (filterName.length === 0) {
813
+ log.debug(`${origin}: Found #1 device.`);
814
+ log.debug(`Device: ${JSON.stringify(thisDevice)}`);
815
+ return callback({ total: 1, list: [thisDevice] });
816
+ }
817
+
818
+ // if there is a filter need to check for matching device
819
+ let found = false;
820
+ for (let f = 0; f < filterName.length; f += 1) {
821
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
822
+ found = true;
823
+ break;
824
+ }
825
+ }
826
+ // matching device
827
+ if (found) {
828
+ log.debug(`${origin}: Found #1 device.`);
829
+ log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
830
+ return callback({ total: 1, list: [thisDevice] });
831
+ }
832
+ // not a matching device
833
+ log.debug(`${origin}: No matching device found.`);
834
+ return callback({ total: 0, list: [] });
835
+ });
836
+ } catch (ex) {
837
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
838
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
839
+ return callback(null, errorObj);
840
+ }
841
+ }
842
+
843
+ /**
844
+ * @summary Gets the status for the provided appliance
845
+ *
846
+ * @function isAlive
847
+ * @param {String} deviceName - the deviceName of the appliance. (required)
848
+ *
849
+ * @param {configCallback} callback - callback function to return the result
850
+ * (appliance isAlive) or the error
851
+ */
852
+ isAlive(deviceName, callback) {
853
+ const meth = 'adapter-isAlive';
854
+ const origin = `${this.id}-${meth}`;
855
+ log.trace(origin);
856
+
857
+ // verify the required fields have been provided
858
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
859
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
860
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
861
+ return callback(null, errorObj);
862
+ }
863
+
864
+ try {
865
+ // need to get the device so we can convert the deviceName to an id
866
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
867
+ const opts = {
868
+ filter: {
869
+ name: deviceName
870
+ }
871
+ };
872
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
873
+ // if we received an error or their is no response on the results return an error
874
+ if (ferr) {
875
+ return callback(null, ferr);
876
+ }
877
+ if (devs.list.length < 1) {
878
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
879
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
880
+ return callback(null, errorObj);
881
+ }
882
+ // get the uuid from the device
883
+ const { uuid } = devs.list[0];
884
+
885
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
886
+ // !! you can also replace with a specific call if that is easier
887
+ const uriPath = `/call/toget/status/${uuid}`;
888
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
889
+ // if we received an error or their is no response on the results return an error
890
+ if (error) {
891
+ return callback(null, error);
892
+ }
893
+ // !! should update this to make sure we are checking for the appropriate object/field
894
+ if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
895
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
896
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
897
+ return callback(null, errorObj);
898
+ }
899
+
900
+ // !! return the response - Update to the appropriate object/field
901
+ return callback(!result.response.returnObj.statusField);
902
+ });
903
+ });
904
+ } catch (ex) {
905
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
906
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
907
+ return callback(null, errorObj);
908
+ }
909
+ }
910
+
911
+ /**
912
+ * @summary Gets a config for the provided Appliance
913
+ *
914
+ * @function getConfig
915
+ * @param {String} deviceName - the deviceName of the appliance. (required)
916
+ * @param {String} format - the desired format of the config. (optional)
917
+ *
918
+ * @param {configCallback} callback - callback function to return the result
919
+ * (appliance config) or the error
920
+ */
921
+ getConfig(deviceName, format, callback) {
922
+ const meth = 'adapter-getConfig';
923
+ const origin = `${this.id}-${meth}`;
924
+ log.trace(origin);
925
+
926
+ // verify the required fields have been provided
927
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
928
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
929
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
930
+ return callback(null, errorObj);
931
+ }
932
+
933
+ try {
934
+ // need to get the device so we can convert the deviceName to an id
935
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
936
+ const opts = {
937
+ filter: {
938
+ name: deviceName
939
+ }
940
+ };
941
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
942
+ // if we received an error or their is no response on the results return an error
943
+ if (ferr) {
944
+ return callback(null, ferr);
945
+ }
946
+ if (devs.list.length < 1) {
947
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
948
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
949
+ return callback(null, errorObj);
950
+ }
951
+ // get the uuid from the device
952
+ const { uuid } = devs.list[0];
953
+
954
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
955
+ // !! you can also replace with a specific call if that is easier
956
+ const uriPath = `/call/toget/config/${uuid}`;
957
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
958
+ // if we received an error or their is no response on the results return an error
959
+ if (error) {
960
+ return callback(null, error);
961
+ }
962
+
963
+ // return the result
964
+ const newResponse = {
965
+ response: JSON.stringify(result.response, null, 2)
966
+ };
967
+ return callback(newResponse);
968
+ });
969
+ });
970
+ } catch (ex) {
971
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
972
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
973
+ return callback(null, errorObj);
974
+ }
975
+ }
976
+
977
+ /**
978
+ * @summary Gets the device count from the system
979
+ *
980
+ * @function getCount
981
+ *
982
+ * @param {getCallback} callback - callback function to return the result
983
+ * (count) or the error
984
+ */
985
+ getCount(callback) {
986
+ const meth = 'adapter-getCount';
987
+ const origin = `${this.id}-${meth}`;
988
+ log.trace(origin);
989
+
990
+ // verify the required fields have been provided
991
+
992
+ try {
993
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
994
+ // !! you can also replace with a specific call if that is easier
995
+ const uriPath = '/call/toget/count';
996
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
997
+ // if we received an error or their is no response on the results return an error
998
+ if (error) {
999
+ return callback(null, error);
1000
+ }
1001
+
1002
+ // return the result
1003
+ return callback({ count: result.response });
1004
+ });
1005
+ } catch (ex) {
1006
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1007
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1008
+ return callback(null, errorObj);
1009
+ }
1010
+ }
1011
+
544
1012
  /**
545
1013
  * @callback healthCallback
546
1014
  * @param {Object} result - the result of the get request (contains an id and a status)
@@ -32529,6 +32997,88 @@ This request will yield a base64-encoded session key to be included in an `X-Ses
32529
32997
  return callback(null, errorObj);
32530
32998
  }
32531
32999
  }
33000
+
33001
+ /**
33002
+ * @function getGraphql
33003
+ * @pronghornType method
33004
+ * @name getGraphql
33005
+ * @summary A lightweight read-only endpoint for conveying querying using graphql.
33006
+ *
33007
+ * @param {object} body - graphql query data
33008
+ * @param {getCallback} callback - a callback function to return the result
33009
+ * @return {object} results - An object containing the response of the action
33010
+ *
33011
+ * @route {GET} /getGraphql
33012
+ * @roles admin
33013
+ * @task true
33014
+ */
33015
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
33016
+ getGraphql(body, callback) {
33017
+ const meth = 'adapter-getGraphql';
33018
+ const origin = `${this.id}-${meth}`;
33019
+ log.trace(origin);
33020
+
33021
+ if (this.suspended && this.suspendMode === 'error') {
33022
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
33023
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
33024
+ return callback(null, errorObj);
33025
+ }
33026
+
33027
+ /* HERE IS WHERE YOU VALIDATE DATA */
33028
+ if (body === undefined || body === null || body === '') {
33029
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
33030
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
33031
+ return callback(null, errorObj);
33032
+ }
33033
+
33034
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
33035
+ const queryParamsAvailable = {};
33036
+ const queryParams = {};
33037
+ const pathVars = [];
33038
+ const bodyVars = body;
33039
+
33040
+ // loop in template. long callback arg name to avoid identifier conflicts
33041
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
33042
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
33043
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
33044
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
33045
+ }
33046
+ });
33047
+
33048
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
33049
+ // see adapter code documentation for more information on the request object's fields
33050
+ const reqObj = {
33051
+ payload: bodyVars,
33052
+ uriPathVars: pathVars,
33053
+ uriQuery: queryParams
33054
+ };
33055
+
33056
+ try {
33057
+ // Make the call -
33058
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
33059
+ return this.requestHandlerInst.identifyRequest('Graphql', 'getGraphql', reqObj, true, (irReturnData, irReturnError) => {
33060
+ // if we received an error or their is no response on the results
33061
+ // return an error
33062
+ if (irReturnError) {
33063
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
33064
+ return callback(null, irReturnError);
33065
+ }
33066
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
33067
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getGraphql'], null, null, null);
33068
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
33069
+ return callback(null, errorObj);
33070
+ }
33071
+
33072
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
33073
+ // return the response
33074
+ return callback(irReturnData, null);
33075
+ });
33076
+ } catch (ex) {
33077
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
33078
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
33079
+ return callback(null, errorObj);
33080
+ }
33081
+ }
32532
33082
  }
32533
33083
 
32534
33084
  module.exports = Netbox;
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 troubleshootingAdapter.getAdapterConfig();
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;
@@ -4,7 +4,7 @@
4
4
  "name": "getGenerics",
5
5
  "protocol": "REST",
6
6
  "method": "GET",
7
- "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}?{query}",
7
+ "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}/{pathv11}/{pathv12}/{pathv13}/{pathv14}/{pathv15}/{pathv16}/{pathv17}/{pathv18}/{pathv19}/{pathv20}?{query}",
8
8
  "requestSchema": "schema.json",
9
9
  "responseSchema": "schema.json",
10
10
  "timeout": 0,
@@ -25,7 +25,7 @@
25
25
  "name": "createGeneric",
26
26
  "protocol": "REST",
27
27
  "method": "POST",
28
- "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}?{query}",
28
+ "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}/{pathv11}/{pathv12}/{pathv13}/{pathv14}/{pathv15}/{pathv16}/{pathv17}/{pathv18}/{pathv19}/{pathv20}?{query}",
29
29
  "requestSchema": "schema.json",
30
30
  "responseSchema": "schema.json",
31
31
  "timeout": 0,
@@ -46,7 +46,7 @@
46
46
  "name": "updateGeneric",
47
47
  "protocol": "REST",
48
48
  "method": "PUT",
49
- "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}?{query}",
49
+ "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}/{pathv11}/{pathv12}/{pathv13}/{pathv14}/{pathv15}/{pathv16}/{pathv17}/{pathv18}/{pathv19}/{pathv20}?{query}",
50
50
  "requestSchema": "schema.json",
51
51
  "responseSchema": "schema.json",
52
52
  "timeout": 0,
@@ -67,7 +67,7 @@
67
67
  "name": "patchGeneric",
68
68
  "protocol": "REST",
69
69
  "method": "PATCH",
70
- "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}?{query}",
70
+ "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}/{pathv11}/{pathv12}/{pathv13}/{pathv14}/{pathv15}/{pathv16}/{pathv17}/{pathv18}/{pathv19}/{pathv20}?{query}",
71
71
  "requestSchema": "schema.json",
72
72
  "responseSchema": "schema.json",
73
73
  "timeout": 0,
@@ -88,7 +88,7 @@
88
88
  "name": "deleteGeneric",
89
89
  "protocol": "REST",
90
90
  "method": "DELETE",
91
- "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}?{query}",
91
+ "entitypath": "{base_path}/{version}/{pathv1}/{pathv2}/{pathv3}/{pathv4}/{pathv5}/{pathv6}/{pathv7}/{pathv8}/{pathv9}/{pathv10}/{pathv11}/{pathv12}/{pathv13}/{pathv14}/{pathv15}/{pathv16}/{pathv17}/{pathv18}/{pathv19}/{pathv20}?{query}",
92
92
  "requestSchema": "schema.json",
93
93
  "responseSchema": "schema.json",
94
94
  "timeout": 0,