@itentialopensource/adapter-netbox 0.6.1 → 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/.eslintignore CHANGED
@@ -2,3 +2,4 @@
2
2
  backup/*
3
3
  coverage/*
4
4
  out/*
5
+ adapter_modifications/*
package/CHANGELOG.md CHANGED
@@ -1,4 +1,36 @@
1
1
 
2
+ ## 0.7.0 [02-14-2022]
3
+
4
+ * migration and added a call for graphql
5
+
6
+ See merge request itentialopensource/adapters/inventory/adapter-netbox!13
7
+
8
+ ---
9
+
10
+ ## 0.6.4 [07-13-2021]
11
+
12
+ * Updates healthcheck endpoint to use /api/status ADAPT-758
13
+
14
+ See merge request itentialopensource/adapters/inventory/adapter-netbox!12
15
+
16
+ ---
17
+
18
+ ## 0.6.3 [03-17-2021]
19
+
20
+ * fix descriptions and summaries
21
+
22
+ See merge request itentialopensource/adapters/inventory/adapter-netbox!11
23
+
24
+ ---
25
+
26
+ ## 0.6.2 [03-10-2021]
27
+
28
+ * migration to the latest adapter foundation
29
+
30
+ See merge request itentialopensource/adapters/inventory/adapter-netbox!10
31
+
32
+ ---
33
+
2
34
  ## 0.6.1 [01-28-2021]
3
35
 
4
36
  * update a schema so a parameter can be either string or object
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Netbox Adapter
1
+ # Adapter for Netbox
2
2
 
3
3
  This adapter is used to integrate the Itential Automation Platform (IAP) with the Netbox System. The API for Netbox is available at [undefined API URL]. The adapter utilizes the Netbox API to provide the integrations that are deemed pertinent to IAP. This ReadMe file is intended to provide information on this adapter.
4
4
 
@@ -58,8 +58,14 @@ The following list of packages are required for Itential product adapters or cus
58
58
  | ------- | ------- |
59
59
  | @itentialopensource/adapter-utils | Runtime library classes for all adapters; includes request handling, connection, throttling, and translation. |
60
60
  | ajv | Required for validation of adapter properties to integrate with Netbox. |
61
+ | axios | Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality. |
62
+ | commander | Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality. |
61
63
  | fs-extra | Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality. |
62
- | readline-sync | Utilized by the testRunner script that comes with the adapter; helps to test unit and integration functionality. |
64
+ | network-diagnostics | Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality. |
65
+ | readline-sync | Utilized by the node script that comes with the adapter; helps to test unit and integration functionality. |
66
+ | semver | Utilized by the node scripts that are included with the adapter; helps to build and extend the functionality. |
67
+
68
+ Some of the adapter node scripts run testing scripts which require the dev dependencies listed below.
63
69
 
64
70
  ### Additional Prerequisites for Development and Testing
65
71
 
@@ -72,7 +78,9 @@ eslint-config-airbnb-base
72
78
  eslint-plugin-import
73
79
  eslint-plugin-json
74
80
  mocha
81
+ mocha-param
75
82
  nyc
83
+ package-json-validator
76
84
  testdouble
77
85
  winston
78
86
  ```
@@ -112,11 +120,13 @@ This section defines **all** the properties that are available for the adapter,
112
120
  "token_timeout": 0,
113
121
  "token_cache": "local",
114
122
  "auth_field": "header.headers.X-AUTH-TOKEN",
115
- "auth_field_format": "{token}"
123
+ "auth_field_format": "{token}",
124
+ "auth_logging": false
116
125
  },
117
126
  "healthcheck": {
118
127
  "type": "startup",
119
- "frequency": 300000
128
+ "frequency": 300000,
129
+ "query_object": {}
120
130
  },
121
131
  "request": {
122
132
  "number_redirects": 0,
@@ -132,7 +142,8 @@ This section defines **all** the properties that are available for the adapter,
132
142
  },
133
143
  "healthcheck_on_timeout": false,
134
144
  "return_raw": false,
135
- "archiving": false
145
+ "archiving": false,
146
+ "return_request": false
136
147
  },
137
148
  "ssl": {
138
149
  "ecdhCurve": "",
@@ -158,7 +169,9 @@ This section defines **all** the properties that are available for the adapter,
158
169
  "enabled": false,
159
170
  "host": "localhost",
160
171
  "port": 9999,
161
- "protocol": "http"
172
+ "protocol": "http",
173
+ "username": "",
174
+ "password": "",
162
175
  },
163
176
  "mongo": {
164
177
  "host": "",
@@ -215,6 +228,7 @@ The following properties are used to define the authentication process to Netbox
215
228
  | token\_cache | Used to determine where the token should be stored (local memory or in Redis).|
216
229
  | auth\_field | Defines the request field the authentication (e.g., token are basic auth credentials) needs to be placed in order for the calls to work.|
217
230
  | auth\_field\_format | Defines the format of the auth\_field. See examples below. Items enclosed in {} inform the adapter to perofrm an action prior to sending the data. It may be to replace the item with a value or it may be to encode the item. |
231
+ | auth\_logging | Setting this true will add some additional logs but this should only be done when trying to debug an issue as certain credential information may be logged out when this is true. |
218
232
 
219
233
  #### Examples of authentication field format
220
234
 
@@ -237,6 +251,7 @@ The healthcheck properties defines the API that runs the healthcheck to tell the
237
251
  | ------- | ------- |
238
252
  | type | Required. The type of health check to run. |
239
253
  | frequency | Required if intermittent. Defines how often the health check should run. Measured in milliseconds. Default is 300000.|
254
+ | query_object | Query parameters to be added to the adapter healthcheck call.|
240
255
 
241
256
  ### Request Properties
242
257
 
@@ -257,6 +272,7 @@ The request section defines properties to help handle requests.
257
272
  | healthcheck\_on\_timeout | Required. Defines if the adapter should run a health check on timeout. If set to true, the adapter will abort the request and run a health check until it re-establishes connectivity and then it will re-attempt the request.|
258
273
  | return\_raw | Optional. Tells the adapter whether the raw response should be returned as well as the IAP response. This is helpful when running integration tests to save mock data. It does add overhead to the response object so it is not ideal from production.|
259
274
  | archiving | Optional flag. Default is false. It archives the request, the results and the various times (wait time, Netbox time and overall time) in the `adapterid_results` collection in MongoDB. Although archiving might be desirable, be sure to develop a strategy before enabling this capability. Consider how much to archive and what strategy to use for cleaning up the collection in the database so that it does not become too large, especially if the responses are large.|
275
+ | return\_request | Optional flag. Default is false. Will return the actual request that is made including headers. This should only be used during debugging issues as there could be credentials in the actual request.|
260
276
 
261
277
  ### SSL Properties
262
278
 
@@ -298,6 +314,8 @@ The proxy section defines the properties to utilize when Netbox is behind a prox
298
314
  | host | Host information for the proxy server. Required if `enabled` is true.|
299
315
  | port | Port information for the proxy server. Required if `enabled` is true.|
300
316
  | protocol | The protocol (i.e., http, https, etc.) used to connect to the proxy. Default is http.|
317
+ | username | If there is authentication for the proxy, provide the username here.|
318
+ | password | If there is authentication for the proxy, provide the password here.|
301
319
 
302
320
  ### Mongo Properties
303
321
 
@@ -331,6 +349,7 @@ Unit Testing includes testing basic adapter functionality as well as error condi
331
349
  node utils/testRunner --unit
332
350
 
333
351
  npm run test:unit
352
+ npm run test:baseunit
334
353
  ```
335
354
 
336
355
  To add new unit tests, edit the `test/unit/adapterTestUnit.js` file. The tests that are already in this file should provide guidance for adding additional tests.
@@ -366,6 +385,23 @@ Test should also be written to clean up after themselves. However, it is importa
366
385
 
367
386
  > **Reminder**: Do not check in code with actual credentials to systems.
368
387
 
388
+ ## Adapter Node Scripts
389
+
390
+ There are several node scripts that now accompany the adapter. These scripts are provided to make several activities easier. Each of these scripts are described below.
391
+
392
+ | Run | Description |
393
+ | ------- | ------- |
394
+ | npm run adapter:install | Provides an easier way to install the adapter.|
395
+ | npm run adapter:checkMigrate | Checks whether your adapter can and should be migrated to the latest foundation.|
396
+ | npm run adapter:findPath | Can be used to see if the adapter supports a particular API call.|
397
+ | npm run adapter:migrate | Provides an easier way to migrate your adapter after you download the migration zip from Itential DevSite|
398
+ | npm run adapter:update | Provides an easier way to update your adapter after you download the migration zip from Itential DevSite|
399
+ | npm run adapter:revert | Allows you to revert after a migration or update if it resulted in issues.|
400
+ | npm run troubleshoot | Provides a way to troubleshoot the adapter - runs connectivity, healthcheck and basic get.|
401
+ | npm run connectivity | Provides a connectivity check to the Netbox system.|
402
+ | npm run healthcheck | Checks whether the configured healthcheck call works to Netbox.|
403
+ | npm run basicget | Checks whether the basic get calls works to Netbox.|
404
+
369
405
  ## Installing an Itential Product Adapter
370
406
 
371
407
  If you have App-Artifact installed in IAP, you can follow the instruction for that application to install the adapter into IAP. If not, follow these instructions.
@@ -378,24 +414,21 @@ if the @itentialopensource directory does not exist, create it:
378
414
  mkdir @itentialopensource
379
415
  ```
380
416
 
381
- 1. Clone the adapter into your IAP environment.
417
+ 2. Clone the adapter into your IAP environment.
382
418
 
383
419
  ```bash
384
420
  cd \@itentialopensource
385
421
  git clone git@gitlab.com:\@itentialopensource/adapters/adapter-netbox
386
422
  ```
387
423
 
388
- 1. Install the dependencies for the adapter.
424
+ 3. Run the adapter install script.
389
425
 
390
426
  ```bash
391
427
  cd adapter-netbox
392
- npm install
428
+ npm run adapter:install
393
429
  ```
394
430
 
395
- 1. If you are running IAP 2019.1 or older, add the adapter properties for Netbox (created from Adapter Builder) to the `properties.json` file for your Itential build. You will need to change the credentials and possibly the host information below.
396
- [Netbox sample properties](sampleProperties.json). If you are running IAP 2019.2 the adapter properties need to go into the database. You can review IAP documentation for how to do this.
397
-
398
- 1. Restart IAP
431
+ 4. Restart IAP
399
432
 
400
433
  ```bash
401
434
  systemctl restart pronghorn
@@ -415,7 +448,7 @@ Depending on where your code is located, this process is different.
415
448
  Adapter should be placed into: /opt/pronghorn/current/node_modules/\@itentialopensource
416
449
  ```
417
450
 
418
- 1. Follow Steps 3-5 (above) to install an Itential adapter to load your properties, dependencies and restart IAP.
451
+ 2. Follow Steps 3-4 (above) to install an Itential adapter to load your properties, dependencies and restart IAP.
419
452
 
420
453
  ## Using this Adapter
421
454
 
@@ -443,11 +476,6 @@ The `encryptProperty` call will take the provided property and technique, and re
443
476
  encryptProperty(property, technique, callback)
444
477
  ```
445
478
 
446
- The `getQueue` call will return the requests that are waiting in the queue if throttling is enabled.
447
- ```js
448
- getQueue(callback)
449
- ```
450
-
451
479
  The `addEntityCache` call will take the entities and add the list to the entity cache to expedite performance.
452
480
  ```js
453
481
  addEntityCache(entityType, entities, key, callback)
@@ -468,39 +496,169 @@ The `verifyCapability` call verifies the adapter can perform the provided action
468
496
  verifyCapability(entityType, actionType, entityId, callback)
469
497
  ```
470
498
 
471
- The `updateEntityCache` call will update the entity cache.
499
+ The `updateEntityCache` call will update the entity cache.
472
500
  ```js
473
501
  updateEntityCache()
474
502
  ```
475
503
 
504
+ The `updateAdapterConfiguration` call provides the ability to update the adapter configuration from IAP - includes actions, schema, mockdata and other configurations.
505
+ ```js
506
+ updateAdapterConfiguration(configFile, changes, entity, type, action, callback)
507
+ ```
508
+
509
+ The `suspend` call provides the ability to suspend the adapter and either have requests rejected or put into a queue to be processed after the adapter is resumed.
510
+ ```js
511
+ suspend(mode, callback)
512
+ ```
513
+
514
+ The `unsuspend` call provides the ability to resume a suspended adapter. Any requests in queue will be processed before new requests.
515
+ ```js
516
+ unsuspend(callback)
517
+ ```
518
+
519
+ The `findPath` call provides the ability to see if a particular API path is supported by the adapter.
520
+ ```js
521
+ findPath(apiPath, callback)
522
+ ```
523
+
524
+ The `troubleshoot` call can be used to check on the performance of the adapter - it checks connectivity, healthcheck and basic get calls.
525
+ ```js
526
+ troubleshoot(props, persistFlag, adapter, callback)
527
+ ```
528
+
529
+ The `runHealthcheck` call will return the results of a healthcheck.
530
+ ```js
531
+ runHealthcheck(adapter, callback)
532
+ ```
533
+
534
+ The `runConnectivity` call will return the results of a connectivity check.
535
+ ```js
536
+ runConnectivity(callback)
537
+ ```
538
+
539
+ The `runBasicGet` call will return the results of running basic get API calls.
540
+ ```js
541
+ runBasicGet(callback)
542
+ ```
543
+
544
+ The `getQueue` call will return the requests that are waiting in the queue if throttling is enabled.
545
+ ```js
546
+ getQueue(callback)
547
+ ```
548
+
476
549
  ### Specific Adapter Calls
477
550
 
478
551
  Specific adapter calls are built based on the API of the Netbox. The Adapter Builder creates the proper method comments for generating JS-DOC for the adapter. This is the best way to get information on the calls.
479
552
 
553
+
554
+ ## Extending/Enhancing the Adapter
555
+
556
+ ### Adding a Second Instance of an Adapter
557
+
558
+ You can add a second instance of this adapter without adding new code on the file system. To do this go into the IAP Admin Essentials and add a new service config for this adapter. The two instances of the adapter should have unique ids. In addition, they should point to different instances of the other system. For example, they should be configured to talk to different hosts.
559
+
560
+ ### Adding Adapter Calls
561
+
562
+ There are multiple ways to add calls to an existing adapter.
563
+
564
+ The easiest way would be to use the Adapter Builder update process. This process takes in a Swagger or OpenAPI document, allows you to select the calls you want to add and then generates a zip file that can be used to update the adapter. Once you have the zip file simple put it in the adapter direcctory and execute `npm run adapter:update`.
565
+
566
+ ```bash
567
+ mv updatePackage.zip adapter-netbox
568
+ cd adapter-netbox
569
+ npm run adapter:update
570
+ ```
571
+
572
+ If you do not have a Swagger or OpenAPI document, you can use a Postman Collection and convert that to an OpenAPI document using APIMatic and then follow the first process.
573
+
574
+ If you want to manually update the adapter that can also be done the key thing is to make sure you update all of the right files. Within the entities directory you will find 1 or more entities. You can create a new entity or add to an existing entity. Each entity has an action.json file, any new call will need to be put in the action.json file. It will also need to be added to the enum for the ph_request_type in the appropriate schema files. Once this configuration is complete you will need to add the call to the adapter.js file and in order to make it available as a workflow task in IAP, it should also be added to the pronghorn.json file. You can optionally add it to the unit and integration test files. There is more information on how to work on each of these files in the Adapter Technical Resources on Dev Site [HERE](https://developer.itential.io/adapters-resources/)
575
+
576
+ ```text
577
+ Files to update
578
+ * entities/<entity>/action.json: add an action
579
+ * entities/<entity>/schema.json (or the schema defined on the action): add action to the enum for ph_request_type
580
+ * adapter.js: add the new method and make sure it calls the proper entity and action
581
+ * pronghorn.json: add the new method
582
+ * test/unit/adapterTestUnit.js (optional but best practice): add unit test(s) - function is there, any required parameters error when not passed in
583
+ * test/integration/adapterTestIntegration.js (optional but best practice): add integration test
584
+ ```
585
+
586
+ ### Adding Adapter Properties
587
+
588
+ While changing adapter properties is done in the service instance configuration section of IAP, adding properties has to be done in the adapter. To add a property you should edit the propertiesSchema.json with the proper information for the property. In addition, you should modify the sampleProperties to have the new property in it.
589
+
590
+ ```text
591
+ Files to update
592
+ * propertiesSchema.json: add the new property and how it is defined
593
+ * sampleProperties: add the new property with a default value
594
+ * test/unit/adapterTestUnit.js (optional but best practice): add the property to the global properties
595
+ * test/integration/adapterTestIntegration.js (optional but best practice): add the property to the global properties
596
+ ```
597
+
598
+ ### Changing Adapter Authentication
599
+
600
+ Often an adapter is built before knowing the authentication and authentication process can also change over time. The adapter supports many different kinds of authentication but it does require configuration. Some forms of authentication can be defined entirely with the adapter properties but others require configuration.
601
+
602
+ ```text
603
+ Files to update
604
+ * entities/<entity>/action.json: change the getToken action as needed
605
+ * entities/<entity>/schemaTokenReq.json: add input parameters (external name is name in other system)
606
+ * entities/<entity>/schemaTokenResp.json: add response parameters (external name is name in other system)
607
+ * propertiesSchema.json: add any new property and how it is defined
608
+ * sampleProperties: add any new property with a default value
609
+ * test/unit/adapterTestUnit.js (optional but best practice): add the property to the global properties
610
+ * test/integration/adapterTestIntegration.js (optional but best practice): add the property to the global properties
611
+ ```
612
+
613
+ ### Enhancing Adapter Integration Tests
614
+
615
+ The adapter integration tests are written to be able to test in either stub (standalone) mode or integrated to the other system. However, if integrating to the other system, you may need to provide better data than what the adapter provides by default as that data is likely to fail for create and update. To provide better data, edit the adapter integration test file. Make sure you do not remove the marker and keep custom code below the marker so you do not impact future migrations. Once the edits are complete, run the integration test as it instructs you to above. When you run integrated to the other system, you can also save mockdata for future use by changing the isSaveMockData flag to true.
616
+
617
+ ```text
618
+ Files to update
619
+ * test/integration/adapterTestIntegration.js: add better data for the create and update calls so that they will not fail.
620
+ ```
621
+
622
+ As mentioned previously, for most of these changes as well as other possible changes, there is more information on how to work on an adapter in the Adapter Technical Resources on Dev Site [HERE](https://developer.itential.io/adapters-resources/)
623
+
480
624
  ## Troubleshooting the Adapter
481
625
 
626
+ Run `npm run troubleshoot` to start the interactive troubleshooting process. The command allows user to verify and update connection, authentication as well as healthcheck configuration. After that it will test these properties by sending HTTP request to the endpoint. If the tests pass, it will persist these changes into IAP.
627
+
628
+ User also have the option to run individual command to perform specific test
629
+
630
+ - `npm run healthcheck` will perform a healthcheck request of with current setting.
631
+ - `npm run basicget` will perform some non-parameter GET request with current setting.
632
+ - `npm run connectivity` will perform networking diagnostics of the adatper endpoint.
633
+
482
634
  ### Connectivity Issues
483
635
 
484
- 1. Verify the adapter properties are set up correctly.
636
+ 1. You can run the adapter troubleshooting script which will check connectivity, run the healthcheck and run basic get calls.
637
+
638
+ ```bash
639
+ npm run troubleshoot
640
+ ```
641
+
642
+ 2. Verify the adapter properties are set up correctly.
485
643
 
486
644
  ```text
487
645
  Go into the Itential Platform GUI and verify/update the properties
488
646
  ```
489
647
 
490
- 1. Verify there is connectivity between the Itential Platform Server and Netbox Server.
648
+ 3. Verify there is connectivity between the Itential Platform Server and Netbox Server.
491
649
 
492
650
  ```text
493
651
  ping the ip address of Netbox server
494
652
  try telnet to the ip address port of Netbox
495
653
  ```
496
654
 
497
- 1. Verify the credentials provided for Netbox.
655
+ 4. Verify the credentials provided for Netbox.
498
656
 
499
657
  ```text
500
658
  login to Netbox using the provided credentials
501
659
  ```
502
660
 
503
- 1. Verify the API of the call utilized for Netbox Healthcheck.
661
+ 5. Verify the API of the call utilized for Netbox Healthcheck.
504
662
 
505
663
  ```text
506
664
  Go into the Itential Platform GUI and verify/update the properties