In our last blog post, we saw how to create a read-only client in bosh director which can be used by monitoring or reporting system. In this blog post, we will try to use that user and run some API calls to pull some data from the bosh director.
In my lab environment, I have a read only client created in bosh director which is readonly-new. SSH into the opsmanager vm and run the below steps.
Step 1:
Using the uaac target
command, target BOSH Director UAA on port 8443
using the bosh IP, and specify the location of the root certificate.
uaac target https://BOSH-DIRECTOR-IP:8443 --ca-cert \ /var/tempest/workspaces/default/root_ca_certificate
Step 2:
Run the below command to generate a token for the read only client
uaac token client get readonly-new -s 'VMware1!'
Note: readonly-new is the readonly client and VMware1! is it’s secret.
Step 3:
Run the below command and make a note of the access_token for readonly-new client
uaac context
The output will be similar to the one below.

Step 4:
Export the access token for ease of use in the commands by running the below command.
export access_token=<Replace it with the access token of readonly-new noted in the previous step>
Step 5:
Now let’s see how to make use of CURL and fetch details of service instances running in bosh. The curl command will be as below.
curl -s -k 'https://<BOSH-IP>:25555/deployments/service-instance_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/instances' -H "Authorization: Bearer $access_token" |jq .
The output will be like the below and we see all the vm details from that bosh service instance.
ubuntu@opsman:~$ curl -s -k 'https://172.31.0.2:25555/deployments/service-instance_9a6ee3ba-44e5-4a92-bb9e-01ac0566560b/instances' -H "Authorization: Bearer $access_token" |jq .
[
{
"agent_id": null,
"cid": null,
"job": "apply-addons",
"index": 0,
"id": "557b4aee-99e8-4123-af41-4e8b5469341f",
"az": "TKGI-COMP-1",
"ips": [],
"vm_created_at": null,
"expects_vm": false
},
{
"agent_id": "a6ac244b-ef7c-4eff-bb4f-02b5462ca6b9",
"cid": "vm-1e7dd07a-c1b0-42b9-87b6-046a565dd748",
"job": "master",
"index": 0,
"id": "f15c5820-b21d-485c-b7c4-4d7d31e9b566",
"az": "TKGI-COMP-1",
"ips": [
"172.15.0.2"
],
"vm_created_at": "2020-07-02T19:55:39Z",
"expects_vm": true
},
{
"agent_id": "7e2bf44a-3327-4c4d-9795-c40797ca5318",
"cid": "vm-32077ca8-8bb2-4b97-9403-d6b85386cdd7",
"job": "worker",
"index": 0,
"id": "c88add30-be75-45a9-9ce4-4597d8fbd2cd",
"az": "TKGI-COMP-1",
"ips": [
"172.15.0.3"
],
"vm_created_at": "2020-07-02T19:55:40Z",
"expects_vm": true
},
{
"agent_id": "ba1b272c-fcd2-4185-9666-8cdd910202ce",
"cid": "vm-782a7372-ed84-4be3-ae05-43ceea759eac",
"job": "worker",
"index": 1,
"id": "66c4a81e-77e7-4da1-ad6f-11a4b8165774",
"az": "TKGI-COMP-1",
"ips": [
"172.15.0.4"
],
"vm_created_at": "2020-07-02T19:55:37Z",
"expects_vm": true
}
]
Step 6:
Now, let’s see how to fetch some detailed information about the same service instance using curl.
curl -s -k 'https://<BOSH-IP>:25555/deployments/service-instance_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/instances?format=full' -H "Authorization: Bearer $access_token" -v
Unlike the first command, this one does not list our the output directly as we are asking to fetch lot of information and bosh will not be able to display it directly. Instead it runs a task to fetch the information. The output for the above curl command will be as below.
ubuntu@opsman:~$ curl -s -k 'https://172.31.0.2:25555/deployments/service-instance_9a6ee3ba-44e5-4a92-bb9e-01ac0566560b/instances?format=full' -H "Authorization: Bearer $access_token" -v
* Trying 172.31.0.2...
* Connected to 172.31.0.2 (172.31.0.2) port 25555 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 594 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
* server certificate verification SKIPPED
* server certificate status verification SKIPPED
* common name: 172.31.0.2 (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: C=US,O=Pivotal,CN=172.31.0.2
* start date: Wed, 01 Jul 2020 14:17:19 GMT
* expire date: Fri, 01 Jul 2022 14:17:19 GMT
* issuer: C=US,O=Pivotal
* compression: NULL
* ALPN, server accepted to use http/1.1
> GET /deployments/service-instance_9a6ee3ba-44e5-4a92-bb9e-01ac0566560b/instances?format=full HTTP/1.1
> Host: 172.31.0.2:25555
> User-Agent: curl/7.47.0
> Accept: */*
> Authorization: Bearer eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vMTcyLjMxLjAuMjo4NDQzL3Rva2VuX2tleXMiLCJraWQiOiJrZXktMSIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhNjY4NGQ0MmRlZGU0OTMzODI3ZDU1YTkzMjk2N2U3OCIsInN1YiI6InJlYWRvbmx5LW5ldyIsImF1dGhvcml0aWVzIjpbImJvc2gucmVhZCIsImJvc2guKi5yZWFkIl0sInNjb3BlIjpbImJvc2guKi5yZWFkIiwiYm9zaC5yZWFkIl0sImNsaWVudF9pZCI6InJlYWRvbmx5LW5ldyIsImNpZCI6InJlYWRvbmx5LW5ldyIsImF6cCI6InJlYWRvbmx5LW5ldyIsImdyYW50X3R5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJyZXZfc2lnIjoiNThlMGE4NGEiLCJpYXQiOjE1OTYxNzQyNjYsImV4cCI6MTU5NjIxNzQ2NiwiaXNzIjoiaHR0cHM6Ly8xNzIuMzEuMC4yOjg0NDMvb2F1dGgvdG9rZW4iLCJ6aWQiOiJ1YWEiLCJhdWQiOlsiYm9zaC4qIiwicmVhZG9ubHktbmV3IiwiYm9zaCJdfQ.tNEMhWe9E8C7F3dY27FmLbQovbN6DMOfyDCjLN4TnD4nodjBd0l7eUWSJc9HxSExqpBBSz-ji17XyqHFr4ZBtLTPkdjUXIGzdVR9DNvzkk40AvcE7b-jrvzI0ujny8SW9t1gQTj28ln5uC53fx1lE2X8vRl7YCdper2aosR7Vf3o1KgCr4liArsfxEi1A3KNCoyCVnJhz-u7gVk1ByLLfDjh708moIIw2A7IgEJpA7dCAeDkOab7Gqjp6DuYCas7z22pJhR_oJtPgrxFrJzIF5BKOb6rjRfH-n4sH07lGY0h6l2ZX8YX3RRk8xtn0cm9tpiiDLs-IqlayAu5iTTQBQ
>
< HTTP/1.1 302 Found
< Server: nginx
< Date: Fri, 31 Jul 2020 06:28:15 GMT
< Content-Type: text/html;charset=utf-8
< Content-Length: 0
< Connection: keep-alive
< WWW-Authenticate: Basic realm="BOSH Director"
< Location: https://172.31.0.2:25555/tasks/164
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
<
* Connection #0 to host 172.31.0.2 left intact
Step 7:
From the above response, make a note of Location which has the bosh task number. So there is a task 164 which is created by bosh to fetch this information.
Location: https://172.31.0.2:25555/tasks/164
You may run the below command from bosh cli to get the task details
bosh tasks --recent=2 --all
ubuntu@cli-vm:~$ bosh tasks --recent=2 --all
Using environment '172.31.0.2' as client 'ops_manager'
ID State Started At Finished At User Deployment Description Result
164 done Fri Jul 31 06:28:17 UTC 2020 Fri Jul 31 06:28:17 UTC 2020 readonly-new service-instance_9a6ee3ba-44e5-4a92-bb9e-01ac0566560b retrieve vm-stats -
162 done Fri Jul 31 06:15:29 UTC 2020 Fri Jul 31 06:15:30 UTC 2020 ops_manager pivotal-container-service-942e24a1e535f9022a67 retrieve vm-stats -
2 tasks
Succeeded
Step 8:
Run the below curl command to get the results of task that you made note of in the last step.
curl -k 'https://<BOSH-IP>:25555/tasks/<TASK-Number>/output?type=result' -H "Authorization: Bearer $access_token" | jq
The output response will be as below and you can see what all information we can fetch from that service instance using CURL.
ubuntu@opsman:~$ curl -k 'https://172.31.0.2:25555/tasks/164/output?type=result' -H "Authorization: Bearer $access_token" | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{
"vm_cid": null,
"active": null,
"vm_created_at": null,
"cloud_properties": {
"datacenters": [
{
"clusters": [
{
"RegionA01-MGMT": {
"resource_pool": "TKGI-Comp"
}
}
],
"name": "TKGI-COMP-1"
}
],
"cpu": 1,
"disk": 8192,
"ram": 1024
},
"disk_cid": null,
"disk_cids": [],
"ips": [],
"dns": [],
"agent_id": null,
"job_name": "apply-addons",
"index": 0,
"job_state": null,
"state": "started",
"vm_type": "micro",
"vitals": null,
"processes": [],
"az": "TKGI-COMP-1",
"id": "557b4aee-99e8-4123-af41-4e8b5469341f",
"bootstrap": true,
"ignore": false,
"stemcell": {
"name": null,
"version": null,
"api_version": null
}
}
{
"vm_cid": "vm-32077ca8-8bb2-4b97-9403-d6b85386cdd7",
"active": true,
"vm_created_at": "2020-07-02T19:55:40Z",
"cloud_properties": {
"datacenters": [
{
"clusters": [
{
"RegionA01-MGMT": {
"resource_pool": "TKGI-Comp"
}
}
],
"name": "TKGI-COMP-1"
}
],
"cpu": 2,
"disk": 32768,
"ram": 4096,
"vmx_options": {
"disk.enableUUID": "1"
},
"upgrade_hw_version": true
},
"disk_cid": "disk-cdad3bf7-1262-4905-8fbd-22d7c335329a",
"disk_cids": [
"disk-cdad3bf7-1262-4905-8fbd-22d7c335329a"
],
"ips": [
"172.15.0.3"
],
"dns": [],
"agent_id": "7e2bf44a-3327-4c4d-9795-c40797ca5318",
"job_name": "worker",
"index": 0,
"job_state": "running",
"state": "started",
"vm_type": "medium.disk",
"vitals": {
"cpu": {
"sys": "2.1",
"user": "4.3",
"wait": "0.2"
},
"disk": {
"ephemeral": {
"inode_percent": "2",
"percent": "12"
},
"persistent": {
"inode_percent": "4",
"percent": "10"
},
"system": {
"inode_percent": "33",
"percent": "47"
}
},
"load": [
"0.36",
"0.37",
"0.42"
],
"mem": {
"kb": "1748212",
"percent": "43"
},
"swap": {
"kb": "0",
"percent": "0"
},
"uptime": {
"secs": 928632
}
},
"processes": [
{
"name": "docker",
"state": "running",
"uptime": {
"secs": 928508
},
"mem": {
"kb": 1286264,
"percent": 31.8
},
"cpu": {
"total": 1.4
}
},
{
"name": "kubelet",
"state": "running",
"uptime": {
"secs": 928501
},
"mem": {
"kb": 109912,
"percent": 2.7
},
"cpu": {
"total": 2.4
}
},
{
"name": "kube-proxy",
"state": "running",
"uptime": {
"secs": 928491
},
"mem": {
"kb": 36436,
"percent": 0.9
},
"cpu": {
"total": 0
}
},
{
"name": "blackbox",
"state": "running",
"uptime": {
"secs": 928490
},
"mem": {
"kb": 10100,
"percent": 0.2
},
"cpu": {
"total": 0
}
},
{
"name": "nsx-node-agent",
"state": "running",
"uptime": {
"secs": 928364
},
"mem": {
"kb": 50940,
"percent": 1.2
},
"cpu": {
"total": 0
}
},
{
"name": "ovsdb-server",
"state": "running",
"uptime": {
"secs": 928459
},
"mem": {
"kb": 4600,
"percent": 0.1
},
"cpu": {
"total": 0
}
},
{
"name": "ovs-vswitchd",
"state": "running",
"uptime": {
"secs": 928457
},
"mem": {
"kb": 35024,
"percent": 0.8
},
"cpu": {
"total": 0
}
},
{
"name": "nsx-kube-proxy",
"state": "running",
"uptime": {
"secs": 928361
},
"mem": {
"kb": 53172,
"percent": 1.3
},
"cpu": {
"total": 0
}
},
{
"name": "bosh-dns",
"state": "running",
"uptime": {
"secs": 928455
},
"mem": {
"kb": 20216,
"percent": 0.5
},
"cpu": {
"total": 0.4
}
},
{
"name": "bosh-dns-resolvconf",
"state": "running",
"uptime": {
"secs": 928454
},
"mem": {
"kb": 8120,
"percent": 0.2
},
"cpu": {
"total": 0
}
},
{
"name": "bosh-dns-healthcheck",
"state": "running",
"uptime": {
"secs": 928453
},
"mem": {
"kb": 10404,
"percent": 0.2
},
"cpu": {
"total": 0
}
},
{
"name": "system-metrics-agent",
"state": "running",
"uptime": {
"secs": 928452
},
"mem": {
"kb": 13884,
"percent": 0.3
},
"cpu": {
"total": 0
}
}
],
"az": "TKGI-COMP-1",
"id": "c88add30-be75-45a9-9ce4-4597d8fbd2cd",
"bootstrap": true,
"ignore": false,
"stemcell": {
"name": "bosh-vsphere-esxi-ubuntu-xenial-go_agent",
"version": "621.75",
"api_version": 3
}
}
100 8004 100 8004 0 0 52723 0 --:--:-- --:--:-- --:--:-- 53006
{
"vm_cid": "vm-782a7372-ed84-4be3-ae05-43ceea759eac",
"active": true,
"vm_created_at": "2020-07-02T19:55:37Z",
"cloud_properties": {
"datacenters": [
{
"clusters": [
{
"RegionA01-MGMT": {
"resource_pool": "TKGI-Comp"
}
}
],
"name": "TKGI-COMP-1"
}
],
"cpu": 2,
"disk": 32768,
"ram": 4096,
"vmx_options": {
"disk.enableUUID": "1"
},
"upgrade_hw_version": true
},
"disk_cid": "disk-96517cb2-90ac-4a37-acff-76b2b0731d0e",
"disk_cids": [
"disk-96517cb2-90ac-4a37-acff-76b2b0731d0e"
],
"ips": [
"172.15.0.4"
],
"dns": [],
"agent_id": "ba1b272c-fcd2-4185-9666-8cdd910202ce",
"job_name": "worker",
"index": 1,
"job_state": "running",
"state": "started",
"vm_type": "medium.disk",
"vitals": {
"cpu": {
"sys": "3.0",
"user": "4.8",
"wait": "0.9"
},
"disk": {
"ephemeral": {
"inode_percent": "2",
"percent": "11"
},
"persistent": {
"inode_percent": "2",
"percent": "8"
},
"system": {
"inode_percent": "33",
"percent": "47"
}
},
"load": [
"0.68",
"0.42",
"0.39"
],
"mem": {
"kb": "1363244",
"percent": "34"
},
"swap": {
"kb": "0",
"percent": "0"
},
"uptime": {
"secs": 927826
}
},
"processes": [
{
"name": "docker",
"state": "running",
"uptime": {
"secs": 927698
},
"mem": {
"kb": 642740,
"percent": 15.9
},
"cpu": {
"total": 2.5
}
},
{
"name": "kubelet",
"state": "running",
"uptime": {
"secs": 927692
},
"mem": {
"kb": 112756,
"percent": 2.7
},
"cpu": {
"total": 2.9
}
},
{
"name": "kube-proxy",
"state": "running",
"uptime": {
"secs": 927681
},
"mem": {
"kb": 37108,
"percent": 0.9
},
"cpu": {
"total": 0
}
},
{
"name": "blackbox",
"state": "running",
"uptime": {
"secs": 927680
},
"mem": {
"kb": 10840,
"percent": 0.2
},
"cpu": {
"total": 0.4
}
},
{
"name": "nsx-node-agent",
"state": "running",
"uptime": {
"secs": 927628
},
"mem": {
"kb": 51096,
"percent": 1.2
},
"cpu": {
"total": 0
}
},
{
"name": "ovsdb-server",
"state": "running",
"uptime": {
"secs": 927648
},
"mem": {
"kb": 4632,
"percent": 0.1
},
"cpu": {
"total": 0.4
}
},
{
"name": "ovs-vswitchd",
"state": "running",
"uptime": {
"secs": 927645
},
"mem": {
"kb": 35008,
"percent": 0.8
},
"cpu": {
"total": 0.4
}
},
{
"name": "nsx-kube-proxy",
"state": "running",
"uptime": {
"secs": 927645
},
"mem": {
"kb": 53116,
"percent": 1.3
},
"cpu": {
"total": 0
}
},
{
"name": "bosh-dns",
"state": "running",
"uptime": {
"secs": 927644
},
"mem": {
"kb": 20204,
"percent": 0.5
},
"cpu": {
"total": 0
}
},
{
"name": "bosh-dns-resolvconf",
"state": "running",
"uptime": {
"secs": 927643
},
"mem": {
"kb": 8712,
"percent": 0.2
},
"cpu": {
"total": 0
}
},
{
"name": "bosh-dns-healthcheck",
"state": "running",
"uptime": {
"secs": 927642
},
"mem": {
"kb": 10628,
"percent": 0.2
},
"cpu": {
"total": 0
}
},
{
"name": "system-metrics-agent",
"state": "running",
"uptime": {
"secs": 927641
},
"mem": {
"kb": 14088,
"percent": 0.3
},
"cpu": {
"total": 0
}
}
],
"az": "TKGI-COMP-1",
"id": "66c4a81e-77e7-4da1-ad6f-11a4b8165774",
"bootstrap": false,
"ignore": false,
"stemcell": {
"name": "bosh-vsphere-esxi-ubuntu-xenial-go_agent",
"version": "621.75",
"api_version": 3
}
}
{
"vm_cid": "vm-1e7dd07a-c1b0-42b9-87b6-046a565dd748",
"active": true,
"vm_created_at": "2020-07-02T19:55:39Z",
"cloud_properties": {
"datacenters": [
{
"clusters": [
{
"RegionA01-MGMT": {
"resource_pool": "TKGI-Comp"
}
}
],
"name": "TKGI-COMP-1"
}
],
"cpu": 2,
"disk": 32768,
"ram": 4096
},
"disk_cid": "disk-cec9e136-8b26-438f-a6a4-72c5f59843cd",
"disk_cids": [
"disk-cec9e136-8b26-438f-a6a4-72c5f59843cd"
],
"ips": [
"172.15.0.2"
],
"dns": [],
"agent_id": "a6ac244b-ef7c-4eff-bb4f-02b5462ca6b9",
"job_name": "master",
"index": 0,
"job_state": "running",
"state": "started",
"vm_type": "medium.disk",
"vitals": {
"cpu": {
"sys": "3.8",
"user": "4.3",
"wait": "1.0"
},
"disk": {
"ephemeral": {
"inode_percent": "2",
"percent": "8"
},
"persistent": {
"inode_percent": "0",
"percent": "4"
},
"system": {
"inode_percent": "33",
"percent": "47"
}
},
"load": [
"0.04",
"0.23",
"0.37"
],
"mem": {
"kb": "1039320",
"percent": "26"
},
"swap": {
"kb": "0",
"percent": "0"
},
"uptime": {
"secs": 928167
}
},
"processes": [
{
"name": "kube-apiserver",
"state": "running",
"uptime": {
"secs": 928036
},
"mem": {
"kb": 449412,
"percent": 11.1
},
"cpu": {
"total": 4.4
}
},
{
"name": "kube-controller-manager",
"state": "running",
"uptime": {
"secs": 35519
},
"mem": {
"kb": 94228,
"percent": 2.3
},
"cpu": {
"total": 1.9
}
},
{
"name": "kube-scheduler",
"state": "running",
"uptime": {
"secs": 35532
},
"mem": {
"kb": 42880,
"percent": 1
},
"cpu": {
"total": 0
}
},
{
"name": "etcd",
"state": "running",
"uptime": {
"secs": 928018
},
"mem": {
"kb": 236740,
"percent": 5.8
},
"cpu": {
"total": 2.4
}
},
{
"name": "blackbox",
"state": "running",
"uptime": {
"secs": 928017
},
"mem": {
"kb": 18200,
"percent": 0.4
},
"cpu": {
"total": 0.4
}
},
{
"name": "ncp",
"state": "running",
"uptime": {
"secs": 35516
},
"mem": {
"kb": 168756,
"percent": 4.1
},
"cpu": {
"total": 0.4
}
},
{
"name": "bosh-dns",
"state": "running",
"uptime": {
"secs": 928012
},
"mem": {
"kb": 20060,
"percent": 0.4
},
"cpu": {
"total": 0
}
},
{
"name": "bosh-dns-resolvconf",
"state": "running",
"uptime": {
"secs": 928011
},
"mem": {
"kb": 8688,
"percent": 0.2
},
"cpu": {
"total": 0
}
},
{
"name": "bosh-dns-healthcheck",
"state": "running",
"uptime": {
"secs": 928010
},
"mem": {
"kb": 10716,
"percent": 0.2
},
"cpu": {
"total": 0
}
},
{
"name": "system-metrics-agent",
"state": "running",
"uptime": {
"secs": 928009
},
"mem": {
"kb": 14212,
"percent": 0.3
},
"cpu": {
"total": 0
}
}
],
"az": "TKGI-COMP-1",
"id": "f15c5820-b21d-485c-b7c4-4d7d31e9b566",
"bootstrap": true,
"ignore": false,
"stemcell": {
"name": "bosh-vsphere-esxi-ubuntu-xenial-go_agent",
"version": "621.75",
"api_version": 3
}
}
You can refer to this document for more bosh director API’s
I hope this blogs helps you to start with how you can run API commands against bosh director vm to fetch your PKS/TKGI cluster information. Thank you for reading š š
Leave a Reply