Updated on 2024-04-15 GMT+08:00

Querying Application Discovery Rules

Function

This API is used to query existing application discovery rules in the system.

URI

GET /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.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

id

No

String

Application discovery rule ID, which corresponds to an application discovery rule. If this parameter is left blank, all application discovery rules in the project are returned.

Request Parameters

Table 3 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.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

appRules

Array of AppRules objects

Rule information.

errorCode

String

Response code. SVCSTG.INV.2000000: Success response.

errorMessage

String

Response message.

Table 5 AppRules

Parameter

Type

Description

createTime

String

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

enable

Boolean

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

eventName

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

Array of strings

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

id

String

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

name

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

String

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

spec

AppRulesSpec object

Rule details.

Table 6 AppRulesSpec

Parameter

Type

Description

appType

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

Array of strings

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

detectLog

String

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

discoveryRule

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

String

Whether the current rule is the default one. Value: true or false.

isDetect

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

Array of strings

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

logPathRule

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

NameRule object

Naming rules for discovered services and applications.

priority

String

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

Table 7 DiscoveryRule

Parameter

Type

Description

checkContent

Array of strings

Matched value.

checkMode

String

Match condition. Value: contain or equals.

checkType

String

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

Table 8 LogPathRule

Parameter

Type

Description

args

Array of strings

Command.

nameType

String

Value type. Option: cmdLineHash.

value

Array of strings

Log path.

Table 9 NameRule

Parameter

Type

Description

appNameRule

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 nameType is cmdLine and args is ["start","end"], the characters between start and end in the command are extracted. If args is ["start",""], the characters from start to the end of the command are extracted.If nameType is env and args is ["aa"], the environment variable named aa is extracted.If nameType is str and args is ["fix"], the service name is suffixed with fix.If nameType is cmdLineHash, args is ["0001"], and value is ["ser"], the service name is ser when the startup command is 0001.

applicationNameRule

Array of ApplicationNameRule objects

Application name rule.If nameType is cmdLine and args is ["start","end"], the characters between start and end in the command are extracted. If args is ["start",""], the characters from start to the end of the command are extracted.If nameType is env and args is ["aa"], the environment variable named aa is extracted.If nameType is str and args is ["fix"], the service name is suffixed with fix.If nameType is cmdLineHash, args is ["0001"], and value is ["ser"], the application name is ser when the startup command is 0001.

Table 10 AppNameRule

Parameter

Type

Description

nameType

String

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

args

Array of strings

Input value.

value

Array of strings

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

Table 11 ApplicationNameRule

Parameter

Type

Description

nameType

String

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

args

Array of strings

Input value.

value

Array of strings

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

Example Requests

None

Example Responses

Status code: 200

OK

The request is successful.

{
  "appRules" : [ {
    "createTime" : "1599098476654",
    "enable" : true,
    "name" : "ica**nt",
    "eventName" : "aom_in***tory_rules_event",
    "hostid" : [ ],
    "id" : "b53a5152-****-****-****-302367e04c0b",
    "projectid" : "2a473356c**********be891bffc1cf",
    "spec" : {
      "detectLog" : "true",
      "editable" : null,
      "logPathRule" : [ ],
      "priority" : 9999,
      "attrList" : [ "cmdLine" ],
      "nameRule" : {
        "appNameRule" : [ {
          "nameType" : "cmdLineHash",
          "args" : [ "/opt/********* -DNFW=ica**nt" ],
          "value" : [ "aicagentserver" ]
        } ],
        "applicationNameRule" : [ {
          "nameType" : "cmdLineHash",
          "args" : [ "/opt/*********** -DNFW=ica**nt" ],
          "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" : null
  } ],
  "errorMessage" : null,
  "errorCode" : "SVCSTG.INV.2000000",
  "responseStatus" : 200
}

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 authorization information is incorrect or invalid.

403

ForbiddenThe 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.