Help Center/ Application Operations Management/ API Reference/ API/ Monitoring/ Adding or Modifying One or More Service Discovery Rules
Updated on 2023-11-16 GMT+08:00

Adding or Modifying One or More Service Discovery Rules

Function

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

URI

PUT /v1/{project_id}/inv/servicediscoveryrules

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

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

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token obtained from IAM.

Content-Type

Yes

String

Content type, which is application/json.

Enumeration values:

  • application/json

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

appRules

No

Array of AppRules objects

Service parameters.

Table 4 AppRules

Parameter

Mandatory

Type

Description

createTime

No

String

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

Default: 1599098476654

enable

Yes

Boolean

Whether a rule is enabled. Values: true and false.

eventName

Yes

String

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

hostid

No

Array of strings

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

id

Yes

String

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

name

Yes

String

Rule name, which contains 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.

projectid

Yes

String

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

spec

Yes

AppRulesSpec object

Rule details.

desc

No

String

Custom description

Table 5 AppRulesSpec

Parameter

Mandatory

Type

Description

appType

Yes

String

Service type, which is used only for rule classification and UI display. You can enter any field. For example, enter Java or Python by technology stack, or enter collector or database by function.

attrList

No

Array of strings

Attribute list. Currently, this parameter is not used and can be left blank. Values: cmdLine and env.

detectLog

Yes

String

Whether to enable log collection. Values: true and false.

discoveryRule

Yes

Array of DiscoveryRule objects

Discovery rule. If the array contains multiple conditions, only the processes that meet all the conditions will be matched. 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.

isDefaultRule

Yes

String

Whether the rule is the default one. Values: true and false.

isDetect

Yes

String

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 whether a rule can detect node processes before it is delivered. Values: true and false.

logFileFix

Yes

Array of strings

Log file suffix. Values: log, trace, and out.

logPathRule

No

Array of LogPathRule objects

Log path configuration rule. If cmdLineHash is a fixed string, logs in the specified log path or log file are collected. Otherwise, only the files whose names end with .log or .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.

nameRule

Yes

NameRule object

Naming rules for discovered services and applications.

priority

Yes

Integer

Rule priority. Value range: 1 to 9999. Default value: 9999.

Table 6 DiscoveryRule

Parameter

Mandatory

Type

Description

checkContent

Yes

Array of strings

Matched value.

checkMode

Yes

String

Match condition. Values: contain and equals.

checkType

Yes

String

Match type. Values: cmdLine, env, and scope.

Table 7 LogPathRule

Parameter

Mandatory

Type

Description

args

Yes

Array of strings

Command.

nameType

Yes

String

Value type, which can be cmdLineHash.

value

Yes

Array of strings

Log path.

Table 8 NameRule

Parameter

Mandatory

Type

Description

appNameRule

Yes

Array of AppNameRule objects

Service name rule. If there are multiple objects in the array, the character strings extracted from these objects constitute the service name. 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 service 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 service name is ser when the startup command is 0001.

applicationNameRule

Yes

Array of ApplicationNameRule objects

Application name rule.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 service 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.

Table 9 AppNameRule

Parameter

Mandatory

Type

Description

nameType

Yes

String

Value type. Values: cmdLineHash, cmdLine, env, and str.

args

Yes

Array of strings

Input value.

value

No

Array of strings

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

Table 10 ApplicationNameRule

Parameter

Mandatory

Type

Description

nameType

Yes

String

Value type. Values: cmdLineHash, cmdLine, env, and str.

args

Yes

Array of strings

Input value.

value

No

Array of strings

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

Response Parameters

Status code: 200

Table 11 Response body parameters

Parameter

Type

Description

errorCode

String

Response code.

errorMessage

String

Response message.

responseStatus

Integer

Response status code.

Example Requests

Add an application discovery rule whose name is aom_inventory_rules_event and project ID is 684fc87a79d7xxxx22e62a7da95b.

https://{endpoint}/v1/{project_id}/inv/servicediscoveryrules

{
  "appRules" : [ {
    "createTime" : "1694705766730",
    "enable" : true,
    "name" : "ica**nt",
    "eventName" : "aom_inventory_rules_event",
    "hostid" : [ ],
    "id" : "b53a5152-****-****-****-302367e04c0b",
    "projectid" : "684fc87a79d7xxxx22e62a7da95b",
    "spec" : {
      "detectLog" : "true",
      "editable" : null,
      "logPathRule" : [ ],
      "priority" : 9999,
      "attrList" : [ "cmdLine" ],
      "nameRule" : {
        "appNameRule" : [ {
          "args" : [ "/opt/********* -DNFW=ica**nt" ],
          "nameType" : "cmdLineHash",
          "value" : [ "aicagentserver" ]
        } ],
        "applicationNameRule" : [ {
          "args" : [ "/opt/*********** -DNFW=ica**nt" ],
          "nameType" : "cmdLineHash",
          "value" : [ "aica**nt" ]
        } ]
      },
      "appType" : "",
      "aom_metric_relabel_configs" : null,
      "logFileFix" : [ "log", "trace", "out" ],
      "isDetect" : "false",
      "isDefaultRule" : null,
      "dataSource" : null,
      "discoveryRule" : [ {
        "checkType" : "cmdLine",
        "checkContent" : [ "-DNFW=ica**nt" ],
        "checkMode" : "contain"
      } ]
    },
    "desc" : "Custom description"
  } ],
  "errorMessage" : null,
  "errorCode" : "SVCSTG.INV.2000000",
  "id" : [ ]
}

Example Responses

Status code: 200

OK: The request is successful.

{
  "errorCode" : "SVCSTG.INV.2000000",
  "errorMessage" : null,
  "id" : [ ],
  "results" : [ {
    "name" : "aom_inventory_rules_event",
    "id" : "b53a5152-****-****-****-302367e04c0b"
  } ]
}

Status code: 400

Bad Request: The request is invalid. The client should not repeat the request without modifications.

{
  "errorCode" : "SVCSTG.INV.4000115",
  "errorMessage" : "Request param is invalid",
  "id" : [ ],
  "results" : [ ]
}

Status Codes

Status Code

Description

200

OK: The request is successful.

400

Bad Request: The request is invalid. 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 Codes

See Error Codes.