Citrix Analytics ODATA API
概述
CAS ODATA v4 REST API 可帮助您轻松获取聚合数据。目前,我们支持用户从 CAS 性能数据源获取会话数据。
本文提供了有关如何使用这些 API 的指南。
API 规范
身份验证
此实现使用 Citrix Cloud™ 持有者令牌进行身份验证。
参考:
Citrix Cloud 客户端 ID 和 Citrix Cloud 客户端密钥
以下是获取令牌的示例请求。
请求示例:
POST https://api.cloud.com/cctrustoauth2/{customerid}/tokens/clients
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Body: grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}
<!--NeedCopy-->
响应示例:
HTTP/1.1 200 OK
Content-Type: application/json
...
{
"token_type": "bearer",
"access_token": "ey1..",
"expires_in": "3600"
}
<!--NeedCopy-->
注意:
持有者令牌的有效期为 1 小时。如果在一小时后需要执行查询,请重新生成它。
端点
全局: https://api.cloud.com/casodata
示例:
https://api.cloud.com/casodata/sessions?year=2023&month=04&day=14 将获取 2023/04/14(UTC)的聚合会话数据。
服务路径
本节包含有关服务路径和实体名称(例如会话、计算机和用户)的信息。例如,请参阅以下示例服务路径:
/sessions?year=2023&month=04&day=14
<!--NeedCopy-->
参数 year、month 和 day 是强制性的,并以 UTC 格式添加。
还支持指定小时的数据,路径如下:
/sessions?year=2023&month=04&day=14&hour=10 (获取 2023/04/14 10:00 的数据)
<!--NeedCopy-->
HTTP 标头
| 键 | 示例 | 值 | 强制 |
|---|---|---|---|
| Authorization | CwsAuth bearer= | 是 | |
| Citrix-CustomerId | 是 | ||
| Content-Type | application/json | 是 | |
| Citrix-TransactionId | 否 | ||
| Accept-Encoding | gzip | 否 | |
系统运算符
CAS ODATA API 支持以下基本 OData 系统选项:
| 系统选项 | 示例 |
|---|---|
| $select | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState |
| $orderby | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState&$orderby=sessionScore desc |
| $top | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState&$top=1 |
| $top&$skip | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState&$top=10&$skip=20 |
| $count | https:///casodata/sessions?year=2023&month=04&day=14&$count=true |
| $filters | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState&$filter=sessionScore ne 20 |
注意:
请勿在 $select 选项的值中添加任何空格。
$filter 运算符和函数
CAS ODATA API 支持 $filter 选项的以下 OData 逻辑运算符和字符串函数:
| 类别 | 运算符 | 示例 |
|---|---|---|
| 逻辑运算符
|
eq/ne/gt/lt/le/ge | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState&$filter=sessionScore ge 20 |
| not | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState,deliveryGroupName&$filter=not(deliveryGroupName eq null) | |
| and/or | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState,logonDuration&$filter=sessionState eq ‘5’ and (sessionScore le 20 or logonDuration gt 19.914) | |
| in | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState,logonDuration&$filter=sessionState in (‘5’,’3’) | |
| not in | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState,logonDuration&$filter=not (sessionState in (‘5’,’3’)) | |
| 字符串函数
|
contains | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState,deliveryGroupName&$filter=contains(deliveryGroupName,’PRD’) |
| startswith | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState,deliveryGroupName&$filter=not endswith(deliveryGroupName,’CVAD Development’) | |
| endswith | https:///casodata/sessions?year=2023&month=04&day=14&$select=sessionKey,sessionScore,sessionState,deliveryGroupName&$filter=startswith(sessionKey,’09c3268e’) |
实体和数据属性
支持以下三个 CAS 性能实体:
示例用例
获取元数据并从中选择一些列以执行查询
-
请求元数据
请求示例:
curl --location 'https://api.cloud.com/casodata/$metadata' \ --header 'Authorization: CwsAuth bearer=eyJhbGciOiJSUzI1NiIsInR5.....' \ --header 'Citrix-CustomerId: qt64gkrzji7h' \ --header 'Content-Type: application/json' <!--NeedCopy-->响应示例:
<?xml version="1.0" encoding="UTF-8"?> <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"> <edmx:DataServices> <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="cas.odata.v1"> <EntityType Name="session"> <Property Name="timestamp" Type="Edm.String"></Property> <Property Name="sessionKey" Type="Edm.String"></Property> <Property Name="sessionScore" Type="Edm.Double"></Property> <Property Name="sessionState" Type="Edm.String"></Property> ... <Property Name="sessionLaunchStatus" Type="Edm.Int32"></Property> <Property Name="sessionLaunchStatusCustom" Type="Edm.String"></Property> </EntityType> <EntityContainer Name="Container"> <EntitySet Name="sessions" EntityType="cas.odata.v1.session" IncludeInServiceDocument="false"></EntitySet> </EntityContainer> </Schema> </edmx:DataServices> </edmx:Edmx> <!--NeedCopy--> -
选择列
sessionKey、sessionScore和sessionState以执行查询请求示例:
curl --location 'https://api.cloud.com/casodata/sessions?year=2023&month=04&day=14&%24select=sessionKey%2CsessionScore% 2CsessionState' \ --header 'Authorization: CwsAuth bearer=eyJhbGciOiJSUzI1NiIsInR5.....' \ --header 'Citrix-CustomerId: qt64gkrzji7h' \ --header 'Content-Type: application/json' <!--NeedCopy-->响应示例:
{ "@odata.context": "$metadata#sessions(sessionKey,sessionScore,sessionState)/$entity", "value": [ { "sessionKey": "009e7f0f-5707-4083-934f-24d8ad5e91f8", "sessionScore": -1.0, "sessionState": "2" }, ... { "sessionKey": "ff0504e3-0867-414a-b0b2-beb73f06fdad", "sessionScore": 0.0, "sessionState": "5" } ] } <!--NeedCopy-->
获取指定日期的所有数据并进行分页
查询的默认限制为 1000 行。
用户可以设置 $top 选项的值以限制查询中的结果行数。在此场景中,查询响应底部提供了下一页链接。
请求示例:
curl --location 'https://api.cloud.com/casodata/sessions?year=2023&month=04&day=14&%24top=100' \
--header 'Authorization: CwsAuth bearer=eyJhbGciOiJSUzI1NiIsInR5.....' \
--header 'Citrix-CustomerId: qt64gkrzji7h' \
--header 'Content-Type: application/json'
<!--NeedCopy-->
响应示例:
{
"@odata.context": "$metadata#sessions/$entity",
"value": [
{
"timestamp": "2023-03-28T00:00:00.000Z",
"sessionKey": "009e7f0f-5707-4083-934f-24d8ad5e91f8",
"sessionScore": 79.0,
"sessionState": "2",
"sessionType": "0",
"userName": "81d0260b529c11fbb05c8dfabb3d312182e6af9deecfc6c036768df2ed3c3a39",
"sessionStartTime": "2023-03-28T17:38:38.000Z",
"machineName": "253f6a031c9b65cbb7bcc3f137b9878fe0effef010757aec54420776a0d2dd71",
"deliveryGroupName": "CVD\\BUR CVAD Development",
"logonDuration": 18.69,
"brokeringDuration": 0.0,
"vmStartDuration": 0.0,
"hdxConnectionDuration": 0.0,
"authenticationDuration": 0.0,
"gpoDuration": 0.0,
"logonScriptsDuration": 0.0,
"profileLoadDuration": 0.0,
"interactiveSessionsDuration": 0.0,
"siteName": "cloudxdsite",
"icaRtt": 125.38,
"reconnects": 0.0,
"wanLatency": 0,
"hostDelay": 0,
"dcLatency": 0,
"endpointLocationCity": null,
"endpointReceiverVersion": "21.6.0.47",
"endpointOS": "Windows",
"endpointLocationCountry": null,
"endpointLinkSpeed": -1.0,
"endpointName": "64368231b5d925e40d67449640ca110e9658f63eef37d2579b09b975cc7f7e88",
"endpointIP": "850a4b2abc159a2f7d44dac564bda06afad0c558a070a2681f5cc0e1aa81991c",
"vdaIP": null,
"gatewayFQDN": null,
"connectionType": "External",
"connectorName": null,
"connectorGatewayLatency": 0.0,
"networkInterfaceType": null,
"isp": null,
"sessionLaunchType": "ICA®",
"throughputBytesReceived": -1.0,
"throughputBytesSent": -1.0,
"inputBandwidthConsumed": -1.0,
"outputBandwidthAvailable": -1.0,
"outputBandwidthUsed": -1.0,
"networkLatency": -1.0,
"outputBandwidthUtilization": -1.0,
"siteId": "090e20c8-c852-4a92-9b3f-dfb8d8b2ab61",
"sessionLaunchStatus": 0,
"sessionLaunchStatusCustom": "Succeeded"
},
...
{
"timestamp": "2023-04-14T00:00:00.000Z",
"sessionKey": "ff0504e3-0867-414a-b0b2-beb73f06fdad",
"sessionScore": 0.0,
"sessionState": "5",
"sessionType": "0",
"userName": "aed8a56c38d5d2824d8699a48cdd1b19eb3b16f135c8d61bf2cd6acd465aa998",
"sessionStartTime": "2023-03-09T21:39:51.000Z",
"machineName": "5603b4dcad97424b6329caccc9cc6ad949b764bbc0015bc6e2a2b4938e4be954",
"deliveryGroupName": "Remote PC - Miami LABs",
"logonDuration": 0.0,
"brokeringDuration": 0.0,
"vmStartDuration": 0.0,
"hdxConnectionDuration": 0.0,
"authenticationDuration": 0.0,
"gpoDuration": 0.0,
"logonScriptsDuration": 0.0,
"profileLoadDuration": 0.0,
"interactiveSessionsDuration": 0.0,
"siteName": "cloudxdsite",
"icaRtt": 0.0,
"reconnects": 0.0,
"wanLatency": 0,
"hostDelay": 0,
"dcLatency": 0,
"endpointLocationCity": null,
"endpointReceiverVersion": null,
"endpointOS": "Windows 10",
"endpointLocationCountry": null,
"endpointLinkSpeed": -1.0,
"endpointName": "Precision 5550",
"endpointIP": "e74dbbbd20d20f971c0254c6680aad800ad3932c4740544b39a42bb422424272",
"vdaIP": null,
"gatewayFQDN": null,
"connectionType": "External",
"connectorName": null,
"connectorGatewayLatency": 0.0,
"networkInterfaceType": null,
"isp": null,
"sessionLaunchType": "ICA",
"throughputBytesReceived": -1.0,
"throughputBytesSent": -1.0,
"inputBandwidthConsumed": -1.0,
"outputBandwidthAvailable": -1.0,
"outputBandwidthUsed": -1.0,
"networkLatency": -1.0,
"outputBandwidthUtilization": -1.0,
"siteId": "090e20c8-c852-4a92-9b3f-dfb8d8b2ab61",
"sessionLaunchStatus": 0,
"sessionLaunchStatusCustom": "Succeeded"
}
],
"@odata.nextLink": "https://api.cloud.com/casodata/sessions?year=2023&month=04&day=14&%
24skip=100&%24top=100"
}
<!--NeedCopy-->
获取特定会话的所有数据(使用 sessionkey 筛选数据)
请求示例:
curl --location 'https://api.cloud.com/casodata/sessions?year=2023&month=04&day=14&%24filter=sessionKey%20eq%20%
27009e7f0f-5707-4083-934f-24d8ad5e91f8%27' \
--header 'Authorization: CwsAuth bearer=eyJhbGciOiJSUzI1NiIsInR5.....' \
--header 'Citrix-CustomerId: qt64gkrzji7h' \
--header 'Content-Type: application/json'
<!--NeedCopy-->
响应示例:
{
"@odata.context": "$metadata#sessions/$entity",
"value": [
{
"timestamp": "2023-04-14T00:00:00.000Z",
"sessionKey": "009e7f0f-5707-4083-934f-24d8ad5e91f8",
"sessionScore": -1.0,
"sessionState": "2",
"sessionType": "0",
"userName": "81d0260b529c11fbb05c8dfabb3d312182e6af9deecfc6c036768df2ed3c3a39",
"sessionStartTime": "2023-04-05T17:32:45.000Z",
"machineName": "253f6a031c9b65cbb7bcc3f137b9878fe0effef010757aec54420776a0d2dd71",
"deliveryGroupName": "CVD\\BUR CVAD Development",
"logonDuration": 21.2,
"brokeringDuration": 0.0,
"vmStartDuration": 0.0,
"hdxConnectionDuration": 0.0,
"authenticationDuration": 0.0,
"gpoDuration": 0.0,
"logonScriptsDuration": 0.0,
"profileLoadDuration": 0.0,
"interactiveSessionsDuration": 0.0,
"siteName": "cloudxdsite",
"icaRtt": 0.0,
"reconnects": 0.0,
"wanLatency": 0,
"hostDelay": 0,
"dcLatency": 0,
"endpointLocationCity": null,
"endpointReceiverVersion": "21.6.0.47",
"endpointOS": "Windows",
"endpointLocationCountry": null,
"endpointLinkSpeed": -1.0,
"endpointName": "64368231b5d925e40d67449640ca110e9658f63eef37d2579b09b975cc7f7e88",
"endpointIP": "8dbacd9197f4d3dc068fd44b4837828f8e10a19358b14e96d439cfc82042b70f",
"vdaIP": null,
"gatewayFQDN": null,
"connectionType": "External",
"connectorName": null,
"connectorGatewayLatency": 0.0,
"networkInterfaceType": null,
"isp": null,
"sessionLaunchType": "ICA",
"throughputBytesReceived": -1.0,
"throughputBytesSent": -1.0,
"inputBandwidthConsumed": -1.0,
"outputBandwidthAvailable": -1.0,
"outputBandwidthUsed": -1.0,
"networkLatency": -1.0,
"outputBandwidthUtilization": -1.0,
"siteId": "090e20c8-c852-4a92-9b3f-dfb8d8b2ab61",
"sessionLaunchStatus": 0,
"sessionLaunchStatusCustom": "Succeeded"
}
]
}
<!--NeedCopy-->
统计某天的所有活动会话
请求示例:
curl --location 'https://api.cloud.com/casodata/sessions?year=2023&month=04&day=14&%24count=true&%24filter=sessionState%
20eq%20%275%27' \
--header 'Authorization: CwsAuth bearer=eyJhbGciOiJSUzI1NiIsInR5.....' \
--header 'Citrix-CustomerId: qt64gkrzji7h' \
--header 'Content-Type: application/json'
<!--NeedCopy-->
响应示例:
207
数据源
CAS 自助服务搜索仪表板可视化并向客户管理员显示数据,并启用搜索功能。ODATA API 使用相同的数据源,并为客户管理员提供更大的灵活性以获取和筛选数据。有关详细信息,请参阅表格数据。