Updated on 2023-09-11 GMT+08:00

Building a Program

Prerequisites

(1) The IP address in the two functions is an access point of LTS. To obtain this IP address, perform the following steps:
  1. Log in to the LTS console. In the navigation pane, choose Host Management.
  2. Click Install ICAgent in the upper right.
    Figure 1 Installing an ICAgent
  3. Obtain the access point IP address in the Install ICAgent window.
    Figure 2 Access point IP address

2. Obtain the values of log_group_id and log_stream_id in the functions. For details, see Obtaining the Account ID, Project ID, Log Group ID, and Log Stream ID.

3. Create the LTS dependency required by function B. For details, see How Do I Create a Dependency on the FunctionGraph Console? and How Do I Add a Dependency to a Function? You can run the pip install huaweicloudsdklts command to create the dependency. The sample code contains the huaweicloudsdklts dependency for Python 3.9.

Creating a Function

Create a log extraction function by uploading the sample code package. Select the Python 3.9 runtime and the agency LtsOperation created in Creating an Agency. For details about how to create a function, see Creating an Event Function.

Create function A. For the sample code of this function, see the write_log.py file. In the code of function A, replace host, log_group_id, and log_stream_id with the access point and the IDs of log group test-1206 and log stream test-206, as shown in Figure 3.

Figure 3 write_log.py

Create function B. For the sample code of this function, see the lts_cleanse.py file. In the code of function B, replace host, log_group_id, and log_stream_id with the access point and the IDs of log group test-1121 and log stream test-1121, and add the huaweicloudsdklts dependency to this function, as shown in Figure 4 and Figure 5.

Figure 4 lts_cleanse.py
Figure 5 Adding a dependency for function B

This function performs Base64 decoding on received log event data, extracts alarm logs containing keyword WRN, WARN, ERR, or ERROR, and then stores the extracted logs to a specified LTS log stream. Set log extraction conditions based on the content of your service logs.