WebSphere Application Server & Liberty

 View Only

WebSphere Automation "How To" Series #21 : How to list all registered hostnames and versions using APIs

By Brian Hanczaryk posted Mon February 13, 2023 08:09 AM

  

WebSphere Automation "How To" Series #21 : How to list all registered hostnames and versions 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
WebSphere Automation "How To" Series #11 : How to get and delete assets using APIs
WebSphere Automation "How To" Series #12 : How to get security bulletins using APIs
WebSphere Automation "How To" Series #13 : How to retrieve a list of vulnerabilities using APIs
WebSphere Automation "How To" Series #14 : How to get CVE impact summaries using APIs 
WebSphere Automation "How To" Series #15 : How to install interim fixes and fix packs using WebSphere Automation UI
WebSphere Automation "How To" Series #16 : How to retrieve and delete installations using APIs
WebSphere Automation "How To" Series #17 : How to retrieve fixes using APIs 
WebSphere Automation "How To" Series #18 : How to register WebSphere Liberty servers running in containers 
WebSphere Automation "How To" Series #19 : How to install WebSphere Automation to Red Hat® OpenShift® Local
WebSphere Automation "How To" Series #20 : How to retrieve all fix names using APIs


This post will focus on how to list all registered hostnames and versions 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 list all registered hostnames and versions.

For this example, we've registered several WebSphere Application Server traditional servers with v8 ranging from v8.5.5.15 through v8.5.5.22 and v9 ranging from v9.0.5.4 through 9.0.5.14.   

Security_1

As referenced in the previous article, WebSphere Automation "How To" Series #11 : How to get and delete assets using APIs , we can utilize the APIs to generate the json output with a list of our traditional WebSphere assets.  We can then utilize some commands, such as grep, awk and cut, to create a text file with the hostname and version of each registered asset printed on each line.  This is just one example of how APIs and scripting can be utilized to achieve this result.  The following is an example shell script.

[root@api.XXX.cp.fyre.ibm.com Demo]# cat listHostNameAndVersion.sh 
#!/bin/sh

rm -f temphostNameAndVersion.txt
curl -k -X GET "${URL}/assets?limit=100&type=traditional" -H "accept: application/json" -H "Authorization: Bearer $TOKEN" | jq . > json_get_assets.json
echo

grep hostName json_get_assets.json | cut -d '"' -f4 > hostName.txt
grep version json_get_assets.json | grep -v description | cut -d '"' -f4 > version.txt

X=1
XEND=$(wc -l version.txt | awk '{print $1}')

while [ $X -le $XEND ]
do
 HN=$(awk 'NR=='${X} hostName.txt)
 V=$(awk 'NR=='${X} version.txt)
 echo "$HN $V" >> temphostNameAndVersion.txt
 X=`expr $X + 1`
done

rm -f json_get_assets.json
rm -f hostName.txt
rm -f version.txt

cat temphostNameAndVersion.txt | sort -k 2 > hostNameAndVersion.txt
rm -f temphostNameAndVersion.txt

Using the APIs, the maximum number of results returned is determined by the 'limit' parameter. The value must be an integer between 1 and 100.  The default 'limit' parameter is 25.  

Future How-To articles in this series will detail how to list all servers vulnerable to a specific fix and how to update all servers vulnerable to a specific fix.

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

#Automation #WebSphereAutomation #WebSphere 

0 comments
48 views

Permalink