Building a Program
Prerequisites
- Log in to the LTS console. In the navigation pane, choose Host Management.
- Click Install ICAgent in the upper right.
Figure 1 Installing an ICAgent
- 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.
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.
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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.