CTS Event Source

For the use of CTS triggers, please refer to Using a CTS Trigger.

CTS example event

{
  "cts": {
      "time": 1529996047,
      "user": {
          "name": "userName",
          "id": "5b726c4fbfd84821ba866bafaaf56aax",
          "domain": {
              "name": "domainName",
              "id": "b2b3853af40448fcb9e40dxj89505ba"
          }
      },
      "request": {},
      "response": {},
      "code": 204,
      "service_type": "FunctionGraph",
      "resource_type": "graph",
      "resource_name": "workflow-2be1",
      "resource_id": "urn:fgs:region:projectId:graph:workflow-2be1",
      "trace_name": "deleteGraph",
      "trace_type": "ConsoleAction",
      "record_time": 1529996047,
      "trace_id": "69be64a7-0233-11e8-82e4-e5d37911193e",
      "trace_status": "normal"
  }
}

Parameter description

Parameter

Type

Description

time

Int

Epoch timestamp in milliseconds

user

Map

Information about the user who initiated this request

request

Map

Event request content

response

Map

Incident response content

code

Int

Event response code, such as 200, 400

service_type

String

Abbreviation of the sender, such as vpc, ecs, etc.

resource_type

String

The sender resource type, such as vm, vpn, etc.

resource_name

String

Resource name, such as the name of a virtual machine in the ecs service

trace_name

String

Event name, such as: startServer, shutDown, etc.

trace_type

String

The event source type, such as ApiCall

record_time

String

The time when the cts service receives this trace (Epoch timestamp in milliseconds)

trace_id

String

Unique identifier for the event

trace_status

String

Status of the event

For full description of all parameters see CTS Event Reference.

Example

# -*- coding:utf-8 -*-
from fg_cts_event import CTSEvent
 
def handler(event, context):
  logger = context.getLogger()

  logger.info("Function Name: %s", context.getFunctionName())

  cts_event = CTSEvent(event)
 
  logger.info("CTS Event- Trace type: %s", cts_event.get_trace_type())
  logger.info("CTS Event- Service type: %s", cts_event.get_service_type())

  output = {
    "service_type": cts_event.get_service_type(),
    "trace_type": cts_event.get_trace_type(),
    "trace_name": cts_event.get_trace_name(),
  }
	
  return output

Full sample code is available in the samples-doc/scratch-event-cts.

Package description

Public package exports for fg_cts_event.

class fg_cts_event.CTSEvent(event)

Bases: object

Represents a CTS event for FunctionGraph.

get_time()
get_user()
get_request()
get_response()
get_service_type()
get_event_type()
get_project_id()
get_resource_type()
get_resource_account_id()
get_read_only()
get_tracker_name()
get_operation_id()
get_resource_name()
get_resource_id()
get_source_ip()
get_domain_id()
get_trace_name()
get_trace_status()
get_trace_rating()
get_trace_type()
get_api_version()
get_message()
get_record_time()
get_trace_id()
get_code()
get_request_id()
get_location_info()
get_endpoint()
get_resource_url()
get_enterprise_project_id()
get_user_agent()
get_content_length()
get_total_time()
to_json()
class fg_cts_event.CTSBaseUserDomain(user_domain)

Bases: object

Represents the domain information on a CTS user object.

get_id()
get_name()
to_json()
class fg_cts_event.CTSSessionContext(session_context)

Bases: object

Represents temporary security credential context on a CTS user.

get_attributes()
to_json()
class fg_cts_event.CTSSessionContextAttributes(session_attributes)

Bases: object

Represents session attributes for a CTS user context.

get_created_at()
get_mfa_authenticated()
to_json()
class fg_cts_event.CTSUserInfo(user)

Bases: object

Represents the user that triggered a CTS event.

get_type()
get_principal_id()
get_principal_urn()
get_account_id()
get_access_key_id()
get_id()
get_name()
get_domain()
get_user_name()
get_principal_is_root_user()
get_invoked_by()
get_session_context()
get_origin_user()
to_json()