添加或修改应用发现规则
功能介绍
该接口用于添加或修改一条或多条应用发现规则。同一projectid下可添加的规则上限为100条。
URI
PUT /v1/{project_id}/inv/servicediscoveryrules
请求消息
请求参数
请求参数如表1所示。
参数 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
projectid | 是 | String | - | 租户从IAM申请到的projectid,一般为32位字符串。 |
id | 是 | String | - | 创建时填空,修改时填规则ID。 |
name | 是 | String | 字符长度小于64位,以小写字母(a-z)开头,只能包含0-9/a-z/-,不能以-结尾。 | 规则名称。 |
createTime | 否 | String | - | 创建时间(创建时不传,修改时传查询返回的createTime) |
enable | 是 | Boolean | true、false | 规则是否启用。 |
hostid | 否 | Array | - | 主机ID(暂不使用,传空即可)。 |
eventName | 是 | String | aom_inventory_rules_event | 规则事件名称,对于应用发现固定为"aom_inventory_rules_event" |
spec | 是 | Object | - | 规则详情。详见表3。 |
参数 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
detectLog | 是 | String | true、false | 是否开启日志采集。 |
logFileFix | 是 | Array | log、trace、out | 日志文件的后缀。 |
discoveryRule | 是 | Array |
| 规则发现部分,数组中有多个对象时表示需要同时满足所有条件的进程才会被匹配到。详见表4。 |
attrList | 否 | Array | cmdLine、env | 属性列表(暂不使用,可不传)。 |
isDetect | 是 | String | true、false | 是否为规则预探测场景(预探测场景不会保存规则,仅用于规则下发之前对规则正确性的检测)。 |
isDefaultRule | 是 | String | true、false | 是否为默认规则。 |
priority | 是 | Integer | 1~9999的整数,默认取值为9999 | 规则优先级。 |
nameRule | 是 | Object | - | 应用发现规则命名部分。详见表5。 |
appType | 是 | String | - | 应用类型,用于标记应用的分类,仅用于规则分类和界面展示。可以填写任意字段,如按技术栈分类可填写Java,Python。按作用分类可填写collector(采集),database(数据库)等。 |
logPathRule | 否 | Array |
| 日志路径配置规则。详见表8。 |
参数 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
checkType | 是 | String | cmdLine、env、scope | 匹配类型。 |
checkMode | 是 | String | contain、equals | 匹配条件。 |
checkContent | 是 | Array | - | 匹配值。 |
参数 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
appNameRule | 是 | Array |
| 应用命名部分,数组中有多个对象时表示将每个对象抽取到的字符串拼接作为应用的名称。详见表6。 |
applicationNameRule | 是 | Array |
| 应用命名部分。详见表7。 |
参数 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
nameType | 是 | String | cmdLineHash、cmdLine、env、str | 取值类型。 |
args | 是 | Array | - | 输入值。 |
value | 否 | Array | - | 应用名(仅nameType为cmdLineHash时填写)。 |
参数 | 是否必选 | 参数类型 | 取值范围 | 描述 |
|---|---|---|---|---|
nameType | 是 | String | cmdLineHash、cmdLine、env、str | 取值类型。 |
args | 是 | Array | - | 输入值。 |
value | 否 | Array | - | 应用名(仅nameType为cmdLineHash时填写)。 |
Header说明
请求消息头(Header)如表9所示。
请求示例
{
"appRules": [
{
"id": "",
"name": "bytest",
"createTime": "",
"projectid": "5a6036f48e954fcd84d198cb28db311a",
"enable": true,
"hostid": [],
"eventName": "aom_inventory_rules_event",
"spec": {
"detectLog": "true",
"logFileFix": ["log","trace"],
"discoveryRule": [
{
"checkType": "cmdLine",
"checkMode": "contain",
"checkContent": ["default"]
},{
"checkType": "scope",
"checkMode": "equals",
"checkContent": [
"44d6c4bb-f673-4bf4-8d33-313832f37b28"
]
}
],
"attrList": ["cmdLine"],
"isDetect": "false",
"priority": "1",
"nameRule": {
"appNameRule": [
{
"nameType":"cmdLineHash",
"args":["00000000001"],
"value":["serviceName1"]
},
{
"nameType": "cmdLine",
"args": [
"/var/paas/kubernetes/","/kubeconfig"
]
},
{
"nameType": "env",
"args": ["APP_NAME"]
},
{
"nameType": "str",
"args": ["kube"]
}
],
"applicationNameRule": [
{
"nameType":"cmdLineHash",
"agrs":["00000000001"],
"value":["applicationName1"]
},
{
"nameType": "str",
"args": ["kubeproxy"]
}
]
},
"appType": "",
"isDefaultRule":"false",
"logPathRule": [
{
"nameType":"cmdLineHash",
"agrs":["00000000001"],
"value":["/xx/xxx/xx.log","/xx/xxx/xx"]
}
]
}
}
]
} 状态码
- 正常
状态码如表11所示。
- 异常
表12 状态码 状态码
编码
描述
400
BadRequest
非法请求。
建议直接修改该请求,不要重试该请求。
401
Unauthorized
在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。
403
Forbidden
请求被拒绝访问。
返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。
500
InternalServerError
表明服务端能被请求访问到,但是不能理解用户的请求。
503
ServiceUnavailable
被请求的服务无效。
建议直接修改该请求,不要重试该请求。
错误码
错误码 | 错误信息 | 处理措施 |
|---|---|---|
SVCSTG.INV.4030000 | Forbidden | 请更换有权限的账号。 |
SVCSTG.INV.4000115 | Invalid request parameter. | 请检查参数。 |
SVCSTG.INV.5000002 | The Elasticsearch execution is abnormal. | 请联系技术支持工程师解决。 |
SVCSTG.INV.5000003 | The call ICMGR is abnormal. | 请联系技术支持工程师解决。 |
SVCSTG.INV.5000001 | The Elasticsearch session is null. | 请联系技术支持工程师解决。 |
SVCSTG.INV.5000006 | The apprule name already exists. | 请修改规则名称。 |
SVCSTG.INV.5000007 | The maximum number of rules has been reached. | 请删除不需要的规则后重新添加规则。 |

