Help Center/ Application Operations Management/ API Reference(ME-Abu Dhabi Region) / APIs/ Monitoring (v1)/ Adding or Modifying One or More Application Discovery Rules
Updated on 2022-06-01 GMT+08:00

Adding or Modifying One or More Application Discovery Rules

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

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.

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 an application discovery rule, leave this parameter blank. When modifying an application discovery rule, enter the returned createTime.

enable

Yes

Boolean

Whether a rule is enabled. Value: true or false.

eventName

Yes

String

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

Enumeration values:

  • aom_inventory_rules_event

hostid

No

Array of strings

Host ID (not used currently and can be left empty).

id

Yes

String

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

name

Yes

String

Rule name. The value can contain a maximum of 64 characters. It must start with a lowercase letter and 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.

Table 5 AppRulesSpec

Parameter

Mandatory

Type

Description

appType

No

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. You can also enter collector or database by function.

attrList

No

Array of strings

Attribute list (not used currently and can be left empty). Value: cmdLine or env.

detectLog

No

String

Whether to enable log collection. Value: true or false.

discoveryRule

Yes

Array of DiscoveryRule objects

Discovery rule. When it is an array consisting of multiple conditions, only the processes that meet all the conditions are filtered. 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 current rule is the default one. Value: true or 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. Value: true or false.

logFileFix

No

Array of strings

Log file suffix. Value: log, trace, or out.

logPathRule

No

Array of LogPathRule objects

Log path configuration rule. 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.

nameRule

Yes

NameRule object

Naming rules for discovered services and applications.

priority

Yes

String

Rule priority. An integer ranging from 1 to 9999. The default value is 9999.

Table 6 DiscoveryRule

Parameter

Mandatory

Type

Description

checkContent

Yes

Array of strings

Matched value.

checkMode

Yes

String

Match condition. Value: contain or equals.

checkType

Yes

String

Match type. Value: cmdLine, env, or scope.

Table 7 LogPathRule

Parameter

Mandatory

Type

Description

args

No

Array of strings

Command.

nameType

No

String

Value type. Option: cmdLineHash.

value

No

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. Options: cmdLineHash, cmdLine, env, and str.

args

Yes

Array of strings

Input value.

value

No

Array of strings

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

Table 10 ApplicationNameRule

Parameter

Mandatory

Type

Description

nameType

Yes

String

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

args

Yes

Array of strings

Input value.

value

No

Array of strings

Service name, which is mandatory only if 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 or modify one or more application discovery rules.

PUT https://{Endpoint}/v1/{project_id}/inv/servicediscoveryrules

{
  "appRules" : [ {
    "id" : "44d6c4bb-f673-4bf4-8d33-313832f37b28",
    "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",
          "args" : [ "00000000001" ],
          "value" : [ "applicationName1" ]
        }, {
          "nameType" : "str",
          "args" : [ "kubeproxy" ]
        } ]
      },
      "appType" : "",
      "isDefaultRule" : "false",
      "logPathRule" : [ {
        "nameType" : "cmdLineHash",
        "args" : [ "00000000001" ],
        "value" : [ "/xx/xxx/xx.log", "/xx/xxx/xx" ]
      } ]
    }
  } ]
}

Example Responses

Status code: 200

OK The request is successful.

{
  "errorCode" : "SVCSTG.INV.2000000",
  "errorMessage" : "success",
  "id" : [ "44d6c4bb-f673-4bf4-8d33-313832f37b28" ]
}

Status Codes

Status Code

Description

200

OK The request is successful.

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 Codes

See Error Codes.