Python或Http通过endpoint传log到Log Analytics workspace

1. Python
pip install azure-monitor-ingestion
pip install azure-identity


# information needed to send data to the DCR endpoint
dce_endpoint = "https://monitoring-poc-dce-01-xhvs.eastasia-1.ingest.monitor.azure.com" 
# ingestion endpoint of the Data Collection Endpoint object
dcr_immutableid = "dcr-1ceaafe3115746d8ab02232fd1d85343" # immutableId property of the Data Collection Rule
stream_name = "Custom-PROJECT_INFO_02_CL" #name of the stream in the DCR that represents the destination table

# Import required modules
import os
from azure.identity import ClientSecretCredential
from azure.monitor.ingestion import LogsIngestionClient
from azure.core.exceptions import HttpResponseError

credential = ClientSecretCredential(
    tenant_id="xxx",
    client_id="xxx",
    client_secret="sfk8Q~.ktZzwK_rsNLl-YICkk2EdbRtERIol~cWq"
)
client = LogsIngestionClient(endpoint=dce_endpoint, credential=credential, logging_enable=True)

body = [
        {
            "ONBOARD_DATE": "2023-03-12T15:04:48.423211Z",
            "PROJECT_ID": "10001",
            "PROJECT_NAME":"test1",
            "PROJECT_OWNER":"a1",
            "ID01":"a000000001"
        },
        {
            "ONBOARD_DATE": "2023-03-12T15:04:48.423211Z",
            "PROJECT_ID": "10002",
            "PROJECT_NAME":"test2",
            "PROJECT_OWNER":"a2",
            "ID01":"a000000001"
        }
    ]

try:
    client.upload(rule_id=dcr_immutableid, stream_name=stream_name, logs=body)
except HttpResponseError as e:
    print(f"Upload failed: {e}")

2. Http

{Data Collection Endpoint URI}/dataCollectionRules/{DCR Immutable ID}/streams/{Stream Name}?api-version=2023-01-01