Help Center/ Application Operations Management/ API Reference/ Historical APIs/ Common Monitoring APIs (Offline Soon)/ Adding or Modifying One or More Application Discovery Rules (Offline Soon)
Updated on 2023-11-16 GMT+08:00

Adding or Modifying One or More Application Discovery Rules (Offline Soon)

Function

This API is used to add or modify one or more application discovery rules. A maximum of 100 rules can be added to a project.

URI

PUT /v1/{project_id}/inv/servicediscoveryrules

Request

Request parameters

Table 1 describes the request parameter.

Table 1 Request parameter

Parameter

Mandatory

Type

Value Range

Description

appRules

No

Array

-

See Table 2.

Table 2 appRules parameters

Parameter

Mandatory

Type

Value Range

Description

projectid

Yes

String

-

Project ID obtained from IAM. Generally, a project ID contains 32 characters.

id

Yes

String

-

Rule ID. When creating a discovery rule, leave this parameter blank. When modifying a discovery rule, enter a rule ID.

name

Yes

String

The value can contain a maximum of 64 characters. It must start with a lowercase letter but cannot end with a hyphen (-). Only digits, lowercase letters, and hyphens are allowed.

Rule name.

createTime

No

String

-

Creation time. When creating a discovery rule, leave this parameter blank. When modifying a discovery rule, enter the returned createTime.

enable

Yes

Boolean

true or false

Whether to enable a rule.

hostid

No

Array

-

Host ID. Currently, this parameter is not used and can be left blank.

eventName

Yes

String

aom_inventory_rules_event

Rule event name. For application discovery, the value is fixed to aom_inventory_rules_event.

spec

Yes

Object

-

Rule details. See Table 3.

Table 3 spec parameters

Parameter

Mandatory

Type

Value Range

Description

detectLog

Yes

String

true or false

Whether to enable log collection.

logFileFix

Yes

Array

log, trace, or out

Log file suffix.

discoveryRule

Yes

Array

  • If the value of checkType is cmdLine, set the value of checkMode to contain. checkContent is in the format of ["xxx"], indicating that the process must contain the xxx parameter.
  • If the value of checkType is env, set the value of checkMode to contain. checkContent is in the format of ["k1","v1"], indicating that the process must contain the environment variable whose name is k1 and value is v1.
  • If the value of checkType is scope, set the value of checkMode to equals. checkContent is in the format of ["hostId1","hostId2"], indicating that the rule takes effect only on specified nodes. If no nodes are specified, the rule applies to all nodes of the project.

Discovery rule. When it is an array consisting of multiple conditions, only the processes that meet all the conditions are filtered. See Table 4.

attrList

No

Array

cmdLine or env

Attribute list. Currently, this parameter is not used and can be left blank.

isDetect

Yes

String

true or false

Whether the scenario is a pre-check scenario. No rules will be saved in the pre-check scenario. This scenario is designed only to check rules before they are delivered.

isDefaultRule

Yes

String

true or false

Whether this rule will become the default rule.

priority

Yes

Integer

An integer from 1 to 9999. Default value: 9999.

Rule priority.

nameRule

Yes

Object

-

Naming requirements of the application discovery rule. See Table 5.

appType

Yes

String

-

Application type, which is used to categorize applications and is used only for rule classification and UI display. Enter any field. For example, enter Java or Python by technology stack, or enter collector or database by function.

logPathRule

No

Array

  • If cmdLineHash is a fixed string, a log path or log file is specified. Otherwise, only the files whose names end with .log and .trace are collected.
  • If the value of nameType is cmdLineHash, args is in the format of ["00001"] and value is in the format of ["/xxx/xx.log"], indicating that the log path is /xxx/xx.log when the startup command is 00001.

Log path configuration rule. See Table 8.

Table 4 discoveryRule parameters

Parameter

Mandatory

Type

Value Range

Description

checkType

Yes

String

cmdLine, env, or scope

Match type.

checkMode

Yes

String

contain or equals

Match condition.

checkContent

Yes

Array

-

Matched value.

Table 5 nameRule parameters

Parameter

Mandatory

Type

Value Range

Description

appNameRule

Yes

Array

  • If the value of nameType is cmdLine, args is in the format of ["start", "end"], indicating that the characters between start and end in the command are extracted.
  • If the value of nameType is cmdLine, args is in the format of ["aa"], indicating that the environment variable named aa is extracted.
  • If the value of nameType is str, args is in the format of ["fix"], indicating that the application name is suffixed with fix.
  • If the value of nameType is cmdLineHash, args is in the format of ["0001"] and value is in the format of ["ser"], indicating that the application name is ser when the startup command is 0001.

Application name rule. If there are multiple objects in an array, the character strings extracted from these objects constitute the application name. See Table 6.

applicationNameRule

Yes

Array

  • If the value of nameType is cmdLine, args is in the format of ["start", "end"], indicating that the characters between start and end in the command are extracted.
  • If the value of nameType is cmdLine, args is in the format of ["aa"], indicating that the environment variable named aa is extracted.
  • If the value of nameType is str, args is in the format of ["fix"], indicating that the application name is suffixed with fix.
  • If the value of nameType is cmdLineHash, args is in the format of ["0001"] and value is in the format of ["ser"], indicating that the application name is ser when the startup command is 0001.

Application name rule. See Table 7.

Table 6 appNameRule parameters

Parameter

Mandatory

Type

Value Range

Description

nameType

Yes

String

cmdLineHash, cmdLine, env, or str

Value type.

args

Yes

Array

-

Input value.

value

No

Array

-

Application name, which is mandatory only when the value of nameType is cmdLineHash.

Table 7 applicationNameRule parameters

Parameter

Mandatory

Type

Value Range

Description

nameType

Yes

String

cmdLineHash, cmdLine, env, or str

Value type.

args

Yes

Array

-

Input value.

value

No

Array

-

Application name, which is mandatory only when the value of nameType is cmdLineHash.

Table 8 logPathRule parameters

Parameter

Mandatory

Type

Value Range

Description

nameType

Yes

String

cmdLineHash

Value type.

args

Yes

Array

-

Command.

value

Yes

Array

-

Log path.

Request headers

Table 9 describes the request headers.

Table 9 Request headers

Parameter

Mandatory

Description

X-Auth-Token

Yes

User token obtained from IAM.

Content-Type

Yes

Content type, which is application/json.

Example request

{
    "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"]
                    }
                ]
            }
        }
    ]
}

Response

Response parameters

Table 10 describes the response parameters.

Table 10 Response

Parameter

Type

Description

errorCode

String

Response code.

errorMessage

String

Response message.

Example response

{
     "errorCode":"SVCSTG.INV.2000000",
     "errorMessage":""
}

Status Code

  • Success response

    Table 11 describes the status code.

    Table 11 Status code

    Status Code

    Message

    Description

    200

    OK

    The request is successful.

  • Error response

    Table 12 describes the status codes. For more information, see Status Codes.

    Table 12 Status codes

    Status Code

    Message

    Description

    400

    Bad Request

    Invalid request.

    The client should not repeat the request without modifications.

    401

    Unauthorized

    The authentication information is incorrect or invalid.

    403

    Forbidden

    The request is rejected.

    The server has received the request and understood it, but the server refuses to respond to it. The client should not repeat the request without modifications.

    500

    Internal Server Error

    The server is able to receive the request but unable to understand the request.

    503

    Service Unavailable

    The requested service is invalid.

    The client should not repeat the request without modifications.

Error Code

Table 13 Error codes

Error Code

Error Message

Solution

SVCSTG.INV.4030000

Forbidden

Use an authorized account.

SVCSTG.INV.4000115

Invalid request parameter.

Check the parameter.

SVCSTG.INV.5000002

The Elasticsearch execution is abnormal.

Contact technical support.

SVCSTG.INV.5000003

The call ICMGR is abnormal.

Contact technical support.

SVCSTG.INV.5000001

The Elasticsearch session is null.

Contact technical support.

SVCSTG.INV.5000006

The apprule name already exists.

Use another name.

SVCSTG.INV.5000007

The maximum number of rules has been reached.

Delete unnecessary rules and add new rules.