WebSphere Application Server & Liberty

 View Only

WebSphere Automation "How To" Series #11 : How to get and delete assets using APIs

By Brian Hanczaryk posted Mon May 23, 2022 07:50 AM

  

WebSphere Automation "How To" Series #11 : How to get and delete assets using APIs

Previous blogs in this WebSphere Automation "How To" series :
WebSphere Automation "How To" Series #1 : How to get WebSphere Automation UI URL 
WebSphere Automation "How To" Series #2 : How to specify user roles and permissions 
WebSphere Automation "How To" Series #3 : How to configure WebSphere Automation with an Enterprise LDAP 
WebSphere Automation "How To" Series #4 : How to register WebSphere Application Server traditional servers using configuretWasUsageMetering.py script 
WebSphere Automation "How To" Series #5 : How to register WebSphere Liberty servers 
WebSphere Automation "How To" Series #6 : How to configure email server and email addresses for notifications 
WebSphere Automation "How To" Series #7 : How to setup Instana to send alerts to WebSphere Automation 
WebSphere Automation "How To" Series #8 : How to setup secure access to Linux or UNIX servers 
WebSphere Automation "How To" Series #9 : How to trigger a memory leak health investigation when used heap is over 80 percent 
WebSphere Automation "How To" Series #10 : How to view WebSphere Automation REST APIs using Swagger UI


This post will focus on how to get and delete assets using APIs.

The WebSphere Automation REST APIs are technology preview in this release. IBM Docs directly related to WebSphere Automation REST API are located at https://www.ibm.com/docs/en/ws-automation?topic=technology-preview-viewing-rest-api.

To utilize WebSphere Automation REST APIs through CLI, we need the URL and token values. IBM Docs https://www.ibm.com/docs/en/ws-automation?topic=technology-preview-viewing-rest-api shows the following details on how to acquire the necessary token value for an authorized user profile.

Get the password for the administrator account.

oc -n WSA_INSTANCE_NAMESPACE get secret admin-user-details -o jsonpath='{.data.initial_admin_password}' | base64 -d && echo

WSA_INSTANCE_NAMESPACE is the namespace of the instance where WebSphere Automation is installed.

Replace <password> in the following command with the value returned from the command above, and use the correct value for WSA_INSTANCE_NAMESPACE.

curl -k -X POST -H 'Content-Type: application/json' -d '{"username":"admin","password":"<password>"}' https://$(oc get route -n WSA_INSTANCE_NAMESPACE -o jsonpath='{.items[?(@.spec.to.name=="ibm-nginx-svc")].spec.host}')/icp4d-api/v1/authorize | jq -r .token

To get the necessary URL value to use in the curl commands, we can append a prefix of 'https://' and a suffix of '/websphereauto/secvul/apis' around the result of the following command.

oc get route -n WSA_INSTANCE_NAMESPACE -o jsonpath='{.items[?(@.spec.to.name=="ibm-nginx-svc")].spec.host}'

To set a URL variable on Linux, we could use the following :

URL=https://$(oc get route -n WSA_INSTANCE_NAMESPACE -o jsonpath='{.items[?(@.spec.to.name=="ibm-nginx-svc")].spec.host}')/websphereauto/secvul/apis

Now that we've captured the token and URL values, we can show how to utilize the WebSphere Automation REST APIs to get and delete the registered assets.

For this example, we've registered a WebSphere Application Server traditional v9.0.5.10 server and a WebSphere Liberty 21.0.0.12 server with several fixes applied as shown in the following screenshot.

Security_1


The Swagger UI shows the following available Assets operations.

Assets_1


Using CLI with the token value set in a variable TOKEN and url set in a variable URL, we can issue the following command to get the assets and use jq to pretty print the json output.

[root@XXX.ibm.com Assets]# curl -k -X GET "${URL}/assets?limit=100" -H "accept: application/json" -H "Authorization: Bearer $TOKEN" | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4878 0 4878 0 0 78677 0 --:--:-- --:--:-- --:--:-- 78677
{
"offset": 0,
"limit": 100,
"total_count": 4,
"results": [
{
"id": "eb267a3d-07db-395b-b778-9765edddff64",
"name": "IBM J9 VM@XXX.ibm.com",
"type": "jdk",
"productName": "IBM J9 VM",
"version": "8.0.7.5",
"apars": [],
"hostName": "XXX.ibm.com",
"operatingSystem": "Linux",
"operatingSystemVersion": "3.10.0-1160.25.1.el7.x86_64",
"unresolvedVulnerabilities": [],
"links": {
"self": {
"rel": "self",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/eb267a3d-07db-395b-b778-9765edddff64",
"type": "application/json",
"title": "self"
},
"vulnerabilities": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/vulnerabilities?assetId=eb267a3d-07db-395b-b778-9765edddff64",
"type": "application/json",
"title": "vulnerabilities"
}
},
"created": "2022-05-19T16:44:05Z",
"createdBy": "server-registration-processor",
"updated": "2022-05-20T12:46:55Z",
"updatedBy": "server-registration-processor"
},
{
"id": "8bc3c78f-6fae-3893-a88b-1c1e5cfb7793",
"name": "test-server1@XXX.ibm.com",
"type": "liberty",
"productName": "WebSphere Application Server Liberty Network Deployment",
"version": "21.0.0.12",
"features": [
"jaxb-2.2",
"jaxws-2.2",
"monitor-1.0",
"ssl-1.0",
"transportSecurity-1.0",
"usageMetering-1.0"
],
"apars": [
"PH42074"
],
"hostName": "XXX.ibm.com",
"serverName": "test-server1",
"installDirectory": "/opt/ibm/wlp/",
"profileDirectory": "/opt/ibm/wlp/usr/",
"operatingSystem": "Linux",
"operatingSystemVersion": "3.10.0-1160.25.1.el7.x86_64",
"jdkId": "eb267a3d-07db-395b-b778-9765edddff64",
"unresolvedVulnerabilities": [],
"groups": [
"NO_GROUP"
],
"links": {
"jdk": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/eb267a3d-07db-395b-b778-9765edddff64",
"type": "application/json",
"title": "8.0.7.5"
},
"self": {
"rel": "self",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/8bc3c78f-6fae-3893-a88b-1c1e5cfb7793",
"type": "application/json",
"title": "self"
},
"vulnerabilities": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/vulnerabilities?assetId=8bc3c78f-6fae-3893-a88b-1c1e5cfb7793&assetId=eb267a3d-07db-395b-b778-9765edddff64",
"type": "application/json",
"title": "vulnerabilities"
}
},
"created": "2022-05-19T16:44:07Z",
"createdBy": "server-registration-processor",
"updated": "2022-05-20T12:46:56Z",
"updatedBy": "vulnerability-manager"
},
{
"id": "39259729-c5a0-37cc-b887-dcda610e4518",
"name": "IBM J9 VM@XXX.ibm.com",
"type": "jdk",
"productName": "IBM J9 VM",
"version": "8.0.7.5",
"apars": [],
"hostName": "XXX.ibm.com",
"operatingSystem": "Linux",
"operatingSystemVersion": "4.18.0-305.25.1.el8_4.x86_64",
"unresolvedVulnerabilities": [],
"links": {
"self": {
"rel": "self",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "self"
},
"vulnerabilities": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/vulnerabilities?assetId=39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "vulnerabilities"
}
},
"created": "2022-05-19T16:46:41Z",
"createdBy": "server-registration-processor",
"updated": "2022-05-20T12:50:13Z",
"updatedBy": "server-registration-processor"
},
{
"id": "ee7186ad-698a-34d9-a48e-a2b2d4fbcc18",
"name": "server1@XXX.ibm.com",
"type": "traditional",
"productName": "WebSphere Application Server Network Deployment",
"version": "9.0.5.10",
"apars": [
"PH37034",
"PH41676",
"PH42728",
"PH44339",
"PI97162",
"PH43148",
"PH38485",
"PH43760",
"PH42762",
"PH34122"
],
"hostName": "XXX.ibm.com",
"cellName": "DefaultCell01",
"nodeName": "DefaultNode01",
"serverName": "server1",
"installDirectory": "/opt/WAS",
"profileDirectory": "/opt/WAS/profiles/AppSrv01",
"operatingSystem": "Linux",
"operatingSystemVersion": "4.18.0-305.25.1.el8_4.x86_64",
"jdkId": "39259729-c5a0-37cc-b887-dcda610e4518",
"adminUiUrl": "http://10.21.37.173:9060/ibm/console",
"unresolvedVulnerabilities": [],
"groups": [
"[WebSphereCells",
"WebSphereCells/DefaultCell01",
"WebSphereCells/DefaultCell01/WebSphereNodes",
"WebSphereCells/DefaultCell01/WebSphereNodes/DefaultNode01]"
],
"links": {
"jdk": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "8.0.7.5"
},
"self": {
"rel": "self",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/ee7186ad-698a-34d9-a48e-a2b2d4fbcc18",
"type": "application/json",
"title": "self"
},
"vulnerabilities": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/vulnerabilities?assetId=ee7186ad-698a-34d9-a48e-a2b2d4fbcc18&assetId=39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "vulnerabilities"
}
},
"created": "2022-05-19T16:46:42Z",
"createdBy": "server-registration-processor",
"updated": "2022-05-20T12:50:15Z",
"updatedBy": "vulnerability-manager"
}
]
}


In our example, the id values for the Liberty server asset and the corresponding JVM asset for that Liberty server are 8bc3c78f-6fae-3893-a88b-1c1e5cfb7793 and eb267a3d-07db-395b-b778-9765edddff64 respectively. We can utilize the WebSphere Automation REST APIs to delete these assets as follows.

[root@XXX.ibm.com Assets]# curl -k -X DELETE "${URL}/assets/8bc3c78f-6fae-3893-a88b-1c1e5cfb7793" -H "accept: application/json" -H "Authorization: Bearer $TOKEN"

When we delete a server asset and that corresponding JVM asset is not associated with any additionally registered servers, that JVM asset is also deleted.

The following WebSphere Automation REST APIs call for get assets shows that only WebSphere Application Server traditional server asset and its corresponding JVM asset remain after deleting the Liberty server asset.

[root@XXX.ibm.com Assets]# curl -k -X GET "${URL}/assets?limit=100" -H "accept: application/json" -H "Authorization: Bearer $TOKEN" | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2581 0 2581 0 0 56108 0 --:--:-- --:--:-- --:--:-- 56108
{
"offset": 0,
"limit": 100,
"total_count": 2,
"results": [
{
"id": "39259729-c5a0-37cc-b887-dcda610e4518",
"name": "IBM J9 VM@XXX.ibm.com",
"type": "jdk",
"productName": "IBM J9 VM",
"version": "8.0.7.5",
"apars": [],
"hostName": "XXX.ibm.com",
"operatingSystem": "Linux",
"operatingSystemVersion": "4.18.0-305.25.1.el8_4.x86_64",
"unresolvedVulnerabilities": [],
"links": {
"self": {
"rel": "self",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "self"
},
"vulnerabilities": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/vulnerabilities?assetId=39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "vulnerabilities"
}
},
"created": "2022-05-19T16:46:41Z",
"createdBy": "server-registration-processor",
"updated": "2022-05-20T12:50:13Z",
"updatedBy": "server-registration-processor"
},
{
"id": "ee7186ad-698a-34d9-a48e-a2b2d4fbcc18",
"name": "server1@XXX.ibm.com",
"type": "traditional",
"productName": "WebSphere Application Server Network Deployment",
"version": "9.0.5.10",
"apars": [
"PH37034",
"PH41676",
"PH42728",
"PH44339",
"PI97162",
"PH43148",
"PH38485",
"PH43760",
"PH42762",
"PH34122"
],
"hostName": "XXX.ibm.com",
"cellName": "DefaultCell01",
"nodeName": "DefaultNode01",
"serverName": "server1",
"installDirectory": "/opt/WAS",
"profileDirectory": "/opt/WAS/profiles/AppSrv01",
"operatingSystem": "Linux",
"operatingSystemVersion": "4.18.0-305.25.1.el8_4.x86_64",
"jdkId": "39259729-c5a0-37cc-b887-dcda610e4518",
"adminUiUrl": "http://10.21.37.173:9060/ibm/console",
"unresolvedVulnerabilities": [],
"groups": [
"[WebSphereCells",
"WebSphereCells/DefaultCell01",
"WebSphereCells/DefaultCell01/WebSphereNodes",
"WebSphereCells/DefaultCell01/WebSphereNodes/DefaultNode01]"
],
"links": {
"jdk": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "8.0.7.5"
},
"self": {
"rel": "self",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/assets/ee7186ad-698a-34d9-a48e-a2b2d4fbcc18",
"type": "application/json",
"title": "self"
},
"vulnerabilities": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.XXX.ibm.com/vulnerabilities?assetId=ee7186ad-698a-34d9-a48e-a2b2d4fbcc18&assetId=39259729-c5a0-37cc-b887-dcda610e4518",
"type": "application/json",
"title": "vulnerabilities"
}
},
"created": "2022-05-19T16:46:42Z",
"createdBy": "server-registration-processor",
"updated": "2022-05-20T12:50:15Z",
"updatedBy": "vulnerability-manager"
}
]
}


The following is a WSA UI screenshot after the asset delete command was performed.

Security_2


You can find more IBM Docs related to WebSphere Automation at https://www.ibm.com/docs/en/ws-automation.
#websphere #automation#WSA#WebSphereAutomation









​​​​​
0 comments
47 views

Permalink