Hello and welcome to the SAP HANA Academy.
The topic of this video tutorial series is SAP HANA Cockpit and in this video we will
show how you can work with Cockpit APIs.
This video has been recorded on release SAP HANA cockpit 2.0 SP 07 from August 2018.
For earlier or later releases, please check the playlist on the SAP HANA Academy.
Hi, I am Denys van Kempen.
As of SP 04, we can use REST API GET calls to query the SAP HANA cockpit for its registered
resources, the current state: is the database up and running, or down?
As of SP 07, we can now also use POST calls to register resources, create groups or cockpit
users, or delete them.
As we move to cloud computing, REST API calls are the lingua franca between systems everywhere,
so it is good news that these calls are available for the cockpit.
Typically, the calls would be used by an external tool, non-SAP software maybe, third-party,
or you could write your own, in Python, for example.
To test REST API calls, you don’t need any tool, you can use your browser but you might
need to install a plugin or extension.
A very famous one, in the world of API development is Postman, and to show you how this works,
conceptually, I will be using the Postman client, for Windows here.
Before we can start to GET and POST, we need the URL, a service key and a token.
The way this works is identical to working with cockpit in a browser.
When I connect to the cockpit manager, I am first redirected to the User Authorization
and Authentication service (UAA).
If my username and password are OK, I will get a token and I will be redirected to the
SAP HANA Cockpit Manager.
If I then go to the Cockpit, which is, in fact, a different application all together,
I don’t have to log on again, but behind the screens, my token will get me in.
To do this programatically, we need a service key, and we can use the xs command line tool
to get one: xs create-service-key cockpit-uaa, name of key.
I am using ‘postman’ here but you can use any name you want.
OK.
Service key created.
Then with the xs service-key command we can print the contents of the key to our screen,
I will redirect it to a file —any file name you want— and then if we cat the file to
view the contents, we get the clientid, the clientsecret, and the UAA URL.
Normally, you would feed this JSON file then to your API tool (you need to remove the lines
before and after the brackets) but for now, I will do it the manual way, so you can see
how the parts all fit together.
OK - we also need to get the URL of the cockpit app that we want to POST and GET.
For this, we can use the xs apps command, and grep (filter) cockpit-adminui-svc
This is the URL for the cockpit manager.
We could also have looked it up in our browser, of course.
Same thing.
OK
Let’s select the UAA security URL and paste this into the POST URL.
Append /oauth/token
Then, for authorization type, select Basic.
For username, we are going to enter the client ID and password, that’s the client secret
key (all without quotation marks).
OK - Then we need to build the body of the POST URL.
Three parameters: grant_type=password, the username and the password of that user.
YOu will need a user — let’s switch to the Cockpit Manager — that has COCKPIT_RESOURCE_ADMIN
or COCKPIT_POWER_USER privileges for this to work.
I am using the cockpit_admin user here but don’t do this for anything serious.
Create a dedicated user with a secure password.
OK —We can now send the request and, yes, we get an access token back.
Expires in 14,399 seconds, that’s about 4 hours.
Let’s copy our token, and paste it in here, on the Authorization tab.
For the URL, we are going to use the cockpit-adminui-svc and then append /resource/RegisteredResourcesGet.
How do we know?
Well, for this, we need to switch to the documentation.
SAP HANA Administration with SAP HANA Cockpit
Using Cockpit GET APIs.
We find them all here documented: RegisteredResourcesGet: returns information about the resources registered.
GroupsForUserGet: returns information about the resource groups, andGroupResourcesGet:
returns information about the resources in a specified group that’s accessible (or
visible) to you.
OK —back to Postman.
Send.
And here we have our registered resources.
This is a huge list.
ResourceName, DatabaseName, Version, Operating System, and so on.
This is OData, so we can use parameters in our POST query: /$count, for example.
4 - there are 4 registered resources.
Which ones?
Well, we can use the select parameter: ?$select=ResourceName
And we get our resources back.
Here I am using GroupsForUserGet - which groups can I access?
Now we are querying the landscape service.
Different URL.
Let’s paste that in.
Send.
OK
If we go back to the Cockpit Manager, we get the same view.
Resource Groups: Academy.
Then, with the result, we can query GroupResourcesGet but here we need to append ?groupId and the
group id we can grab from the previous POST request, here.
Append that to the query.
Very well, these are all the resources I have access to.
Similarly, as mentioned, we cannot only use GET API calls but we can also POST API calls.
This allows us to register resources, or create cockpit users, create cockpit groups, or delete
them.
GET is the equivalent of SELECT, and POST is INSERT, UPDATE and DELETE.
Very powerful and this we will discuss in the next video.
Managing Resources, Users, and Groups with the Cockpit APIs is documented in the SAP
HANA Administration with SAP HANA Cockpit guide, which you view or download from the
SAP Help Portal on help.sap.com
Thanks for watching.
You can find more video tutorials on our YouTube channel.
If you would like to be informed about new video tutorials, please subscribe to our channel.
You can connect with us on LinkedIn or follow us on Twitter, as well for updates, and if
you are watching this video on YouTube, do not hesitate to leave your comments to the
video page and, if you like, give us your vote on this video.
Thank you for watching.