说明: 下面的接口调用是基于st2 2.10版本
curl -X POST -u 'st2admin:Ch@ngeMe' http://127.0.0.1:9100/tokens
输出结果:
[root@localhost task]# curl -X POST -u 'st2admin:Ch@ngeMe' http://127.0.0.1:9100/tokens
{
"service": false,
"expiry": "2019-03-27T11:00:49.391396Z",
"token": "fff728d233be471fb5ce6f6a4959beb5",
"user": "st2admin",
"id": "5c9a06619dc6d64beb1295cb",
"metadata": {}
}
curl -X GET -H 'Connection: keep-alive' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'User-Agent: python-requests/2.14.2' -H 'X-Auth-Token: fff728d233be471fb5ce6f6a4959beb5' http://127.0.0.1:9101/v1/rules/default.counter
输出结果样例如下:
[root@localhost ~]# curl -X GET -H 'Connection: keep-alive' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'User-Agent: python-requests/2.14.2' -H 'X-Auth-Token: fff728d233be471fb5ce6f6a4959beb5' http://127.0.0.1:9101/v1/rules/default.counter
{
"description": "counter sensor rule description",
"tags": [],
"ref": "default.counter",
"enabled": true,
"name": "counter",
"trigger": {
"ref": "default.counter",
"type": "default.counter",
"parameters": {}
},
"metadata_file": "",
"context": {
"user": "st2admin"
},
"criteria": {
"trigger.name": {
"pattern": "chao",
"type": "equals"
}
},
"action": {
"ref": "default.multiTask",
"parameters": {
"count": "{{ trigger.count }}",
"age": "{{ trigger.age }}",
"cmd": "{{ trigger.cmd }}",
"node_name": "{{ trigger.params['node_name'] }}",
"pod_name": "{{ trigger.params['pod_name'] }}",
"healing_execution_id": "{{ trigger.params['healing_execution_id'] }}"
}
},
"pack": "default",
"type": {
"ref": "standard",
"parameters": {}
},
"id": "5c92055a9dc6d60b423bb4fe",
"uid": "rule:default:counter"
}
执行的命令:
st2 execution list --action default.multiTask -a liveaction result
对应的curl请求:
curl -X GET -H 'X-Auth-Token: ba2f261a6160464dadee6cf3bea3e878' 'http://127.0.0.1:9101/v1/executions/?action=default.multiTask&include_attributes=liveaction,result&parent=null'
注意:
请将 X-Auth-Token 后面的
ba2f261a6160464dadee6cf3bea3e878
替换为真实的token
输出结果样例如下:
[
{
"liveaction": {
"runner_info": {
"hostname": "localhost.localdomain",
"pid": 1774
},
"parameters": {
"count": 2880,
"age": 29,
"cmd": "date",
"node_name": "node-1",
"pod_name": "ceilometer-api",
"healing_execution_id": "b93fc040-5034-11e9-812e-185e0fbea924"
},
"action_is_workflow": true,
"callback": {},
"action": "default.multiTask",
"id": "5c9ada4b9dc6d605c5e3ba8c"
},
"result": {
"extra": {
"state_info": null,
"state": "SUCCESS"
},
"tasks": [
{
"state_info": null,
"name": "task3",
"created_at": "2019-03-27 02:05:04",
"updated_at": "2019-03-27 02:05:06",
"id": "31497aff-d1db-4855-94f8-34e15ff821ec",
"workflow_execution_id": "005aeed7-b355-42d7-851b-043f1f47eb9b",
"state": "SUCCESS",
"result": {
"succeeded": true,
"failed": false,
"return_code": 0,
"stderr": "",
"stdout": "task3"
},
"published": {
"stderr": "",
"stdout": "task3"
},
"input": null,
"workflow_name": "default.multiTask"
},
{
"state_info": null,
"name": "task2",
"created_at": "2019-03-27 02:05:02",
"updated_at": "2019-03-27 02:05:04",
"id": "f8e10dc8-68b4-42b5-8456-c1b228c183bf",
"workflow_execution_id": "005aeed7-b355-42d7-851b-043f1f47eb9b",
"state": "SUCCESS",
"result": {
"stdout": "node_name: node-1, age: 29, count: 2880, cmd: date, time: 2019-03-27 10:05:03.990998\\n",
"exit_code": 0,
"stderr": "",
"result": "date"
},
"published": {
"stderr": "",
"stdout": "node_name: node-1, age: 29, count: 2880, cmd: date, time: 2019-03-27 10:05:03.990998\\n"
},
"input": null,
"workflow_name": "default.multiTask"
},
{
"state_info": null,
"name": "task1",
"created_at": "2019-03-27 02:05:00",
"updated_at": "2019-03-27 02:05:02",
"id": "20a4bf6c-3437-4502-9df4-3928fd97d06d",
"workflow_execution_id": "005aeed7-b355-42d7-851b-043f1f47eb9b",
"state": "SUCCESS",
"result": {
"succeeded": true,
"failed": false,
"return_code": 0,
"stderr": "",
"stdout": "2019\\u5e74 03\\u6708 27\\u65e5 \\u661f\\u671f\\u4e09 10:05:01 CST"
},
"published": {
"result1": "2019\\u5e74 03\\u6708 27\\u65e5 \\u661f\\u671f\\u4e09 10:05:01 CST",
"stderr": "",
"stdout": "2019\\u5e74 03\\u6708 27\\u65e5 \\u661f\\u671f\\u4e09 10:05:01 CST"
},
"input": null,
"workflow_name": "default.multiTask"
}
],
"stdout": "task3"
},
"id": "5c9ada4b9dc6d605c5e3ba8d"
},
{
"liveaction": {
"runner_info": {
"hostname": "localhost.localdomain",
"pid": 1712
},
"parameters": {
"count": 2880,
"age": 26,
"cmd": "date",
"node_name": "node-1",
"pod_name": "ceilometer-api",
"healing_execution_id": "b93fc040-5034-11e9-812e-185e0fbea924"
},
"action_is_workflow": true,
"callback": {},
"action": "default.multiTask",
"id": "5c9ada4a9dc6d605c5e3ba87"
},
"result": {
"extra": {
"state_info": null,
"state": "SUCCESS"
},
"tasks": [
{
"state_info": null,
"name": "task3",
"created_at": "2019-03-27 02:05:04",
"updated_at": "2019-03-27 02:05:06",
"id": "8afce243-dd36-42a2-95d0-98dfb2d2c912",
"workflow_execution_id": "9ff75994-5722-44f2-8959-da83dd5b2cbb",
"state": "SUCCESS",
"result": {
"succeeded": true,
"failed": false,
"return_code": 0,
"stderr": "",
"stdout": "task3"
},
"published": {
"stderr": "",
"stdout": "task3"
},
"input": null,
"workflow_name": "default.multiTask"
},
{
"state_info": null,
"name": "task2",
"created_at": "2019-03-27 02:05:02",
"updated_at": "2019-03-27 02:05:04",
"id": "334fa81c-2504-4ef8-81c0-6327c8376cd7",
"workflow_execution_id": "9ff75994-5722-44f2-8959-da83dd5b2cbb",
"state": "SUCCESS",
"result": {
"stdout": "node_name: node-1, age: 26, count: 2880, cmd: date, time: 2019-03-27 10:05:03.872965\\n",
"exit_code": 0,
"stderr": "",
"result": "date"
},
"published": {
"stderr": "",
"stdout": "node_name: node-1, age: 26, count: 2880, cmd: date, time: 2019-03-27 10:05:03.872965\\n"
},
"input": null,
"workflow_name": "default.multiTask"
},
{
"state_info": null,
"name": "task1",
"created_at": "2019-03-27 02:04:59",
"updated_at": "2019-03-27 02:05:02",
"id": "9cba7965-cb7d-4abb-8e69-2a2d7b8ac75e",
"workflow_execution_id": "9ff75994-5722-44f2-8959-da83dd5b2cbb",
"state": "SUCCESS",
"result": {
"succeeded": true,
"failed": false,
"return_code": 0,
"stderr": "",
"stdout": "2019\\u5e74 03\\u6708 27\\u65e5 \\u661f\\u671f\\u4e09 10:05:01 CST"
},
"published": {
"result1": "2019\\u5e74 03\\u6708 27\\u65e5 \\u661f\\u671f\\u4e09 10:05:01 CST",
"stderr": "",
"stdout": "2019\\u5e74 03\\u6708 27\\u65e5 \\u661f\\u671f\\u4e09 10:05:01 CST"
},
"input": null,
"workflow_name": "default.multiTask"
}
],
"stdout": "task3"
},
"id": "5c9ada4a9dc6d605c5e3ba88"
}
]
1) 外部系统调用stackstorm的api,需要先获取token,然后发送请求给stackstorm的时候,
都需要携带这个token
2) 如何知道st2命令对应真实的curl请求,加上 --debug参数
例如:
st2 --debug rule get
参考:
https://docs.stackstorm.com/authentication.html