> 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 に保存され、Data Collection Rule が App Services をワークスペースに接続します。この最新の方法では、SCEPman が LAW にアクセスするために RBAC ベースの権限を使用します。

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

```
Install-Module SCEPman -Scope CurrentUser -Force
Complete-SCEPmanInstallation 6>&1
```

{% hint style="info" %}
既定の **保持期間** Log Analytics Table に保存されるデータの **30 日**. 別の保持期間が必要な場合は、テーブル "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"
```

### 選択した期間におけるエンドポイント別の発行済み証明書数

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
