Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
概要: 透過 HTTP 資料收集器 API 從任何地方傳送資料到 OMS。
本文要介紹的 HTTP 資料收集器 API 就如同其名,此 API 讓您能夠透過 HTTP 直接將資料傳至 Log Analytics 中。如此一來,您可以輕易地將您環境的資料傳至 OMS 中,進而使用記錄搜尋功能、利用 View Designer 使您的儀表板更加豐富、還能建立新的警示。
以下是 PowerShell 範例片段:
#Update customer Id to your Operational Insights workspace ID$customerId = "abcdefg-abcd-abcd-abcd-abcdefghijk"
#For shared key use either the primary or secondary Connected Sources client authentication key$sharedKey = "******************************************************************=="
#Log type is name of the event that is being submitted$logType = "EvanAPITest"
#Field used for time stamp. If time field not specified, assumes ingestion time $TimeStampField = "MyTimestamp"#Example JSON web monitor object$json = @"[{
"slot_ID": 12345, "ID": "5cdad72f-c848-4df0-8aaa-ffe033e75d57", "availability_Value": 100, "performance_Value": 6.954, "measurement_Name": "last_one_hour", "duration": 3600, "warning_Threshold": 0, "critical_Threshold": 0, "IsActive": "true"}]"@#Posts the data to the endpointPostData -customerId $customerId -sharedKey $sharedKey -body $json -logType $logType
在本文中,僅會介紹 "傳送 field=value (欄位=值) 這個組合如何運作?"。其他的案例像是 C# 或是 Python 您可以參閱以下文章:使用 HTTP 資料收集器 API 將資料傳送給 Log Analytics。
#Update customer Id to your Operational Insights workspace ID$customerId = "abcdefg-abcd-abcd-abcd-abcdefghijk"
#For shared key use either the primary or secondary Connected Sources client authentication key$sharedKey = "******************************************************************=="
用來驗證您 POST 的標題將透過您的 Workspace ID 和 Workspace Key 來產生,而在此處它們分別被稱為 $customerId
和 $sharedKey
。您可以在 設定>Connected Sources>Windows Servers 找到它。
#Log type is name of the event that is being submitted$logType = "EvanAPITest"
接著要給您在傳送的資料一個 自訂記錄類型,就像我們在自訂記錄中所建立的種類。(事實上,您可以將您的自訂記錄類型與您今日收集的任何自訂記錄類型設定成一樣的,如此它們便會一起顯示出來。)這將在您於記錄搜尋中搜尋時用上。在我的範例中,有一個 EvanAPITest。要搜尋它,可以輸入 Type=EvanAPITest_CL 來搜尋。
#Field used for time stamp. If time field not specified, assumes ingestion time$TimeStampField = "MyTimestamp"
您可以透過 $TimeStampField
設定自己的 Timestamp 欄位。無論您設什麼欄位作為您的 Timestamp 欄位,它都會永久的在您的事件中成為替換 TimeGenerated 的欄位。若此處沒被使用,將會預設成資料匯入的時間(Ingestion Time)。
#Example JSON web monitor object$json = @"[{
"slot_ID": 12345, "ID": "5cdad72f-c848-4df0-8aaa-ffe033e75d57", "availability_Value": 100, "performance_Value": 6.954, "measurement_Name": "last_one_hour", "duration": 3600, "warning_Threshold": 0, "critical_Threshold": 0, "IsActive": "true"}]"@
現在,要定義您的資料,只需建立一個 JSON Payload。
每一個物件都會成為自己的記錄搜尋事件。您可能已經發現我們並沒有指定任何欄位的資料型態,原因是 OMS 會動態的為您決定資料型態。沒有繁瑣的模式規範,您可以直接傳送資料。每個欄位都成為一個自訂欄位,並與您新的(或現存的)自訂記錄類別相關。
#Posts the data to the endpointPostData -customerId $customerId -sharedKey $sharedKey -body $json -logType $logType
最後,利用 Workspace ID、Workspace Key、JSON Payload、和 Custom Log Type 的名稱來聯繫到 PostData。使用 HTTP 資料收集器 API 將資料傳送給 Log Analytics 中的範例包含了整個函式。
在您執行 POST 之後,搜尋 Type=EvanAPITest_CL,便可以看到您的欄位。這些所有欄位的運作都跟記錄搜尋中其他欄位一樣,因此您可以使用任何記錄搜尋提供的功能。
現在您已經看到了 HTTP 收集器 API 的範例,它已經在所有的工作區啟用,您不需要到設定中去開啟功能。
若需要更詳細的資訊,請參考這篇 "Log Analytics HTTP 資料收集器 API 說明文件"!!