401 Unauthorized when use REST API to get ceilometer data with telnet command

Asked by ericshen

I was trying to use REST API to get ceilometer data with telnet
command like below, but it told me unauthorized, and I did not know
how to handle authorization in telnet, and could you please give me
some help, thanks very much.
telnet 127.0.0.1 8777
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
GET /v1/projects/default/resources/

401 Unauthorized

This server could not verify that you are authorized to access the
document you requested. Either you supplied the wrong credentials
(e.g., bad password), or your browser does not understand how to
supply the credentials required.

 Authentication required Connection closed by foreign host.

Question information

Language:
English Edit question
Status:
Solved
For:
Ceilometer Edit question
Assignee:
No assignee Edit question
Solved by:
Lianhao Lu
Solved:
Last query:
Last reply:
Revision history for this message
Julien Danjou (jdanjou) said :
#1

You need to provide an auth token via X-Auth-Token header, like for every OpenStack API.

Revision history for this message
ericshen (batigolsg) said :
#2

I used below command to get x-auth-token:

curl -d '{"auth":{"passwordCredentials":{"username": "admin", "password": "zhu88jie"}}}' -H "Content-type: application/json" http://localhost:35357/v2.0/tokens

get response as below:
{"access": {"token": {"issued_at": "2013-03-08T08:12:07.204739", "expires": "2013-03-09T08:12:07Z", "id": "MIICbgYJKoZIhvcNAQcCoIICXzCCAlsCAQExCTAHBgUrDgMCGjCCAUcGCSqGSIb3DQEHAaCCATgEggE0eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAiMjAxMy0wMy0wOFQwODoxMjowNy4yMDQ3MzkiLCAiZXhwaXJlcyI6ICIyMDEzLTAzLTA5VDA4OjEyOjA3WiIsICJpZCI6ICJwbGFjZWhvbGRlciJ9LCAic2VydmljZUNhdGFsb2ciOiBbXSwgInVzZXIiOiB7InVzZXJuYW1lIjogImFkbWluIiwgInJvbGVzX2xpbmtzIjogW10sICJpZCI6ICJjMzk0N2Y5MTFhMDk0ODgyYmI5MWZjNWU2NTEzNTQ4ZCIsICJyb2xlcyI6IFtdLCAibmFtZSI6ICJhZG1pbiJ9LCAibWV0YWRhdGEiOiB7ImlzX2FkbWluIjogMCwgInJvbGVzIjogW119fX0xgf8wgfwCAQEwXDBXMQswCQYDVQQGEwJVUzEOMAwGA1UECBMFVW5zZXQxDjAMBgNVBAcTBVVuc2V0MQ4wDAYDVQQKEwVVbnNldDEYMBYGA1UEAxMPd3d3LmV4YW1wbGUuY29tAgEBMAcGBSsOAwIaMA0GCSqGSIb3DQEBAQUABIGAnxOC6-jKEYTq1dquOEDfdL7YN09gS-wSw2evhLqjACW6DS6noJautwTw6BDjrfMQ821MTBcAbt7++9OxAzGKQya7zKL5Fr1SyyUww-ZzKQqrihV4cAZAQXNj5QDIFvC6MYN72gh-6N6mXTP4MHEsOr5HAFB0S9iMXIpEw4DENpM="}, "serviceCatalog": [], "user": {"username": "admin", "roles_links": [], "id": "c3947f911a094882bb91fc5e6513548d", "roles": [], "name": "admin"}, "metadata": {"is_admin": 0, "roles": []}}}

and then I use another command to retrieve ceilometer data but still get same error "401 Unauthorized" error
curl -H "X-Auth-Token:MIICbgYJKoZIhvcNAQcCoIICXzCCAlsCAQExCTAHBgUrDgMCGjCCAUcGCSqGSIb3DQEHAaCCATgEggE0eyJhY2Nlc3MiOiB7InRva2VuIjogeyJpc3N1ZWRfYXQiOiAiMjAxMy0wMy0wOFQwNzo1NTo0MC43MzgxMjYiLCAiZXhwaXJlcyI6ICIyMDEzLTAzLTA5VDA3OjU1OjQwWiIsICJpZCI6ICJwbGFjZWhvbGRlciJ9LCAic2VydmljZUNhdGFsb2ciOiBbXSwgInVzZXIiOiB7InVzZXJuYW1lIjogImFkbWluIiwgInJvbGVzX2xpbmtzIjogW10sICJpZCI6ICJjMzk0N2Y5MTFhMDk0ODgyYmI5MWZjNWU2NTEzNTQ4ZCIsICJyb2xlcyI6IFtdLCAibmFtZSI6ICJhZG1pbiJ9LCAibWV0YWRhdGEiOiB7ImlzX2FkbWluIjogMCwgInJvbGVzIjogW119fX0xgf8wgfwCAQEwXDBXMQswCQYDVQQGEwJVUzEOMAwGA1UECBMFVW5zZXQxDjAMBgNVBAcTBVVuc2V0MQ4wDAYDVQQKEwVVbnNldDEYMBYGA1UEAxMPd3d3LmV4YW1wbGUuY29tAgEBMAcGBSsOAwIaMA0GCSqGSIb3DQEBAQUABIGAannzunO1mQ2WVZBiHh1scKxl+8U7Xu1DzHVGPpoRoco1D7Ob1TYFItp13JSo8FuuZbmpZPm5D1KBffpGlff1K-+-oYoOymNvYMzeN34S8UYKRs30VqUxPVTc3QnJ4WJBwtgsnO1U9XvqwfZ3kRmYTyv2vEg2QKCWgeBwOF-k3As=" http://9.123.141.103:8777

Anything wrong in my step?

Revision history for this message
Best Lianhao Lu (lianhao-lu) said :
#3

When getting the x-auth-token, besides passwordCredentials, you also need to provide tenantName, e.g.

curl -d '{"auth":{"tenantName": "service", "passwordCredentials":{"username": "admin", "password": "zhu88jie"}}}' -H "Content-type: application/json" http://localhost:35357/v2.0/tokens

Revision history for this message
ericshen (batigolsg) said :
#4

Thanks Lianhao Lu, that solved my question.

Revision history for this message
ericshen (batigolsg) said :
#5

Thanks all your guys kindly help, adding tenantName solve my issues, thanks a lot again!