Unsolved

1 Rookie

 • 

6 Posts

1287

October 25th, 2022 00:00

How can i use Curl command to get event data for unity API

I have a use case to use only curl command to get the unity event data. but each time i got 400 Bad Request response.

my curl looks like

curl -L -H 'Accept:application/json' -H 'Content-type:application/json' -H 'X-EMC-REST-CLIENT: true' -k -X GET -u admin:XXXXX 'https://unity.dryicelabs.com/api/types/event/instances?compact=true&fields=id,node,creationTime,severity,messageId,arguments,message,category,source,username&filter=creationTime GT "2022-10-25T05:21:48.121Z"'

 

Response 

samrathal_0-1666683569802.png

The same API is running fine with python code, but here my target is to achieve this only using curl. Please suggest. 

Moderator

 • 

7.7K Posts

October 25th, 2022 09:00

Hello samrathal,

Here is a link to a kb that maybe of assistance.

https://dell.to/3VUBjq1

1 Rookie

 • 

6 Posts

October 25th, 2022 22:00

Hi Sam, This link require permission, which i don't have. 
I have gone through one same scenario where solution is marked by adding -L in curl. I did tried but no change. 

Can you please suggest here. 

Moderator

 • 

7.7K Posts

October 26th, 2022 14:00

Dell EMC Unity: How To Use cURL to interact with Unity REST API (User Correctable)

Summary: Users might use cURL tool to manage the Unity storage via its REST API. The cURL command is a quick alternative to Perl or other scripting languages which leverage standard JSON dataSee more

Audience Level: Customer

Article Content


Instructions

cURL version tested: 7.37.0
OS tested: SUSE Linux (SLES 12)
Unity OE tested: 4.1.1.9138882


The article describes the following actions through REST API with cURL commands:
1. Logging into the Unisphere Management REST API server.
2. Querying an existing LUN information.
3. Creating a new LUN.
4. Resizing the newly created LUN.
5. Querying the resized LUN.
6. Deleting that LUN.
7. Logging out of the Unisphere Management REST API server.

Here below are the related commands and outputs:
The following information in the commands examples need to be replaced by the ones in your own case.
- Unisphere admin user name:   admin
- admin account password:         P@ssw0rd
- VNXe management IP:              10.32.106.115
- cookies file name:                       cookies1.txt
- EMC-CSRF-TOKEN:                   Session token retrieved from the first logging command verbose output
- Old LUN CLI ID:                           sv_7
- New LUN name:                          curlLUN
- New LUN CLI ID:                         sv_19

1. Logging into the Unisphere Management REST API server.
curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -u "admin:P@ssw0rd" -c cookies1.txt -verbose -L -k https://dell.to/3DzWaHL

Result ==>
{"@base":" https://dell.to/3TMXwF6 service@VIRT170979R20E-spa spa:~>

EMC-CSRF-TOKEN information in the verbose output ==>
EMC-CSRF-TOKEN: dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXsLI=

2. Querying an existing LUN information.
curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k https://dell.to/3D9aNk5

Result ==>
{"@base":" https://dell.to/3zl7Dsh":[{"rel":"self","href":"/sv_7"}],"content":{"id":"sv_7","name":"DR_Rep_test_Des","sizeTotal":1073741824}}02:50:55 service@VIRT170979R20E-spa spa:~> 

3. Creating a new LUN (Size=1GB(1073741824 Bytes)).
curl -X POST -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN: dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXsLI=" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -d '{"name":"curlLUN","lunParameters":{"pool":{"id":"pool_2"},"isThinEnabled":"false","size":"1073741824"}}' -k https://dell.to/3THBByP

Result ==>
{"@base":" https://dell.to/3D8GD0p":[{"rel":"self","href":"/sv_19"}],"content":{"storageResource":{"id":"sv_19"}}}02:51:51 service@VIRT170979R20E-spa spa:~> 

4. Resizing the newly created LUN (from 1GB to 1.6GB).
curl -X POST -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN: dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXsLI=" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -d '{"lunParameters":{"size":"1717986918"}}' -k https://dell.to/3TI1i2c

Result ==>
HTTP/1.1 204 No Content (because there is no output in the content of the HTTP response of the above request)

5. Querying the resized LUN.
curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k https://dell.to/3TDTPS3

Result ==>
{"@base":" https://dell.to/3TG6ns1":[{"rel":"self","href":"/sv_19"}],"content":{"id":"sv_19","name":"curlLUN","sizeTotal":1717987328}}02:54:05 service@VIRT170979R20E-spa spa:~> 

6. Deleting that LUN.
curl -X DELETE -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN: dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXsLI=" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k https://dell.to/3DdnvOC

Result ==>
HTTP/1.1 204 No Content

7. Logging out of the Unisphere Management REST API server.
curl -X POST -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN: dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXsLI=" -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k https://dell.to/3THn4TP

Result ==>
Logout successful

Additional Information

Explanation about the cURL parameters.

X-EMC-REST-CLIENT: true
This tells the server to use the HTTP Basic access authentication mechanism to authenticate the login request.

EMC-CSRF-TOKEN
Token header, which is required for POST and DELETE requests.
This token header is good for the entirety of the session.
This token string is retrieved from the verbose output of the first login cURL command.

-u "admin:P@ssw0rd"
Passing the username and password to REST API server for authentication in the login request.

-verbose
Verbose output of the communication process. Useful to retrieve the EMC-CSRF-TOKEN from the login command output.
Also useful when there is error of the command to have debug level information.

-H "Accept: application/json" 
To indicate that the format of the response content is JSON.

-H "Content-type: application/json"
To indicate that the format of the request contains body is JSON; required if there is a request body.

-c cookies1.txt
Set the cookies file name to record cookies information.

-b cookies1.txt
Get the cookies information from previously saved cookies file.

-L
Necessary when there is URI redirection (HTTP 302). The command will resend the parameters to redirected URI.

-d '{"name":"curlLUN","lunParameters":{"pool":{"id":"pool_2"},"isThinEnabl ed":"false","size":"1073741824"}}'
curl data format to fit into JSON data structure

-k
Ignore the SSL certificate verification.
This option explicitly allows curl to perform "insecure" SSL connections and transfers.

Any further question, please refer to the attached Unity REST API programmer guide.

1 Rookie

 • 

6 Posts

October 27th, 2022 23:00

Hi Sam, Using the above curl, I'm one step ahead but still my result is not expected with query., Below is my curl query and response :

curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k -u admin:XXXXXXX https://unity.mylab.com/api/types/event/instances?compact=true&fields=id,node,creationTime,severity,messageId,arguments,message,category,source,username&filter=creationTime GT "2022-10-28T05:45:09.927Z"

 

Response : 

{"@base":"https://unity.mylab.com/api/types/alert/instances?per_page=2000&compact=true","updated":"2022-10-28T05:45:09.699Z","links":[{"rel":"self","href":"&page=1"}],"entries":[{"content":{"id":"alert_1327"}},{"content":{"id":"alert_1328"}}]}

Moderator

 • 

7.7K Posts

October 28th, 2022 09:00

Hello samrathal,

It would best to open a support ticket for this as I am not the best at curl.

No Events found!

Top