> For the complete documentation index, see [llms.txt](https://docs.scepman.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scepman.com/ja/azure-gou-cheng/log-configuration.md).

# ログ管理

### Azure Monitor へのログ記録を有効にする

バージョン 3.0 以降、SCEPman と Certificate Master は、Microsoft の Log Ingestion API を使用してログを Azure Monitor に書き込みます。これには、データを保持して分析を可能にするための Log Analytics Workspace の概念と、App Service とログ ストレージの間で連携する Data Collection Rule が使用されます。これにより、SCEPman が LAW にアクセスするための RBAC ベースのアクセス許可を含む、よりモダンなアプローチが可能になります。

Log Analytics Workspace の作成および Data Collection Rule の構成は、次を実行することで自動的に行われます `Complete-SCEPmanInstallation` SCEPman PowerShell モジュールの

{% hint style="info" %}
この **デフォルトの保持期間** Log Analytics Table に保存されたデータの保持期間は **30日**。異なる保持期間が必要な場合は、Table "SCEPman\_CL" の構成をそれに応じて調整してください。
{% endhint %}

#### Data Collector API の再有効化

何らかの理由で以前の API を再度使用したい場合は、Log Ingestion に関連する App Service の変数を削除し、Data Collector API で使用する変数を再度追加してください。

対象の変数 **削除**:

* [AppConfig:LoggingConfig:DataCollectionEndpointUri](/ja/scepman-gou-cheng/application-settings/dependencies-azure-services/logging.md#appconfig-loggingconfig-datacollectionendpointuri)
* [AppConfig:LoggingConfig:RuleId](/ja/scepman-gou-cheng/application-settings/dependencies-azure-services/logging.md#appconfig-loggingconfig-ruleid)

追加する変数:

* [AppConfig:LoggingConfig:WorkspaceId](/ja/scepman-gou-cheng/application-settings/dependencies-azure-services/logging.md#appconfig-loggingconfig-workspaceid)
* [AppConfig:LoggingConfig:SharedKey](/ja/scepman-gou-cheng/application-settings/dependencies-azure-services/logging.md#appconfig-loggingconfig-sharedkey)

SCEPman は再起動後に設定を自動的に取得し、再び Data Collector API を使用します。

## KQL クエリの例

### SCEPman インスタンスの問題を確認する

```kusto
SCEPman_CL
| where Level == "Warn" or Level == "Error" or Level == "Fatal"
```

### 選択した期間における Endpoint ごとの発行済み証明書数

{% hint style="success" %}
このクエリは、ログ記録に Log Ingestion API を使用する場合、SCEPman 3.0 以降で動作することが保証されています。このクエリを使用できなくする SCEPman の変更は、Breaking Changes と見なされます。
{% endhint %}

{% tabs %}
{% tab title="Log Ingestion API（既定）" %}

```kql
SCEPman_CL
| where Level == "Info" and Message startswith_cs "Issued a certificate with serial number"
| project Message, RequestBase = trim_end('/', replace_string(replace_string(replace_regex(RequestUrl, "(/pkiclient\\.exe)?(\\?operation=PKIOperation(&message=.+)?)?", ""),"certsrv/mscep/mscep.dll","intune"),"step/enrollment","activedirectory"))
| summarize IssuanceCount = count() by Endpoint = extract("/([a-zA-Z]+)$", 1, RequestBase)
```

{% endtab %}

{% tab title="Data Collector API（旧）" %}

```kusto
SCEPman_CL
| where Level == "Info" and Message startswith_cs "Issued a certificate with serial number"
| project Message, RequestBase = trim_end('/', replace_string(replace_string(replace_regex(RequestUrl_s, "(/pkiclient\\.exe)?(\\?operation=PKIOperation(&message=.+)?)?", ""),"certsrv/mscep/mscep.dll","intune"),"step/enrollment","activedirectory"))
| summarize IssuanceCount = count() by Endpoint = extract("/([a-zA-Z]+)$", 1, RequestBase)
```

{% endtab %}
{% endtabs %}

SCEPman 2.8 以降、発行された証明書ごとに、ログ メッセージが "Issued a certificate with serial number " で始まる Info レベルのログ エントリが常にちょうど 1 件あり、その後にシリアル番号が続きます。ただし、解決不能な [二軍問題](https://en.wikipedia.org/wiki/Two_Generals'_Problem)、作成された証明書が要求元に届かない、または別の種類のエラーによって実際の登録が妨げられることがあります。同様に、重大なエラーの場合、対応するデータベース エントリがないログ エントリが存在したり、その逆が起こったりすることがあります。

### OCSP チェック付きの一意な証明書

{% tabs %}
{% tab title="Log Ingestion API（既定）" %}

```kusto
let map_certtype = datatable(serial_start:string, readable:string)
[
  "40", "Intune デバイス",
  "41", "Intune デバイス",
  "42", "Intune 非準拠デバイス",
  "50", "固定",
  "51", "固定",
  "60", "Intune ユーザー",
  "61", "Intune ユーザー",
  "64", "Jamf ユーザー",
  "65", "Jamf ユーザー",
  "6C", "デバイス上の Jamf ユーザー",
  "6D", "デバイス上の Jamf ユーザー",
  "70", "Domain Controller",
  "7C", "コンピューター上の Jamf ユーザー",
  "7D", "コンピューター上の Jamf ユーザー",
  "54", "Jamf コンピューター",
  "55", "Jamf コンピューター",
  "44", "Jamf デバイス",
  "45", "Jamf デバイス"
];
SCEPman_CL
| where LogCategory == "Scepman.Server.Controllers.OcspController" and Level == "Info"
| where Message startswith_cs "OCSP Response"
| project serial = extract("Serial Number ([A-F0-9]+)", 1, Message)
| distinct serial
| extend serial_start = substring(serial,0,2)
| join kind=leftouter map_certtype on serial_start
| summarize count() by (readable)
```

{% endtab %}

{% tab title="Data Collector API（旧）" %}

```kql
let map_certtype = datatable(serial_start:string, readable:string)
[
  "40", "Intune デバイス",
  "41", "Intune デバイス",
  "42", "Intune 非準拠デバイス",
  "50", "固定",
  "51", "固定",
  "60", "Intune ユーザー",
  "61", "Intune ユーザー",
  "64", "Jamf ユーザー",
  "65", "Jamf ユーザー",
  "6C", "デバイス上の Jamf ユーザー",
  "6D", "デバイス上の Jamf ユーザー",
  "70", "Domain Controller",
  "7C", "コンピューター上の Jamf ユーザー",
  "7D", "コンピューター上の Jamf ユーザー",
  "54", "Jamf コンピューター",
  "55", "Jamf コンピューター",
  "44", "Jamf デバイス",
  "45", "Jamf デバイス"
];
SCEPman_CL
| where LogCategory_s == "Scepman.Server.Controllers.OcspController" and Level == "Info"
| where Message startswith_cs "OCSP Response"
| project serial = extract("Serial Number ([A-F0-9]+)", 1, Message)
| distinct serial
| extend serial_start = substring(serial,0,2)
| join kind=leftouter map_certtype on serial_start
| summarize count() by (readable)
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.scepman.com/ja/azure-gou-cheng/log-configuration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
