> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Processing Monitor のイベントログ

> GetEventsCSV POST request を使用して、ABBYY FlexiCapture Processing Monitor の文書処理イベントログを CSV としてダウンロードする方法と、スクリプト例について説明します。

このログには、文書処理のイベントやエラーが記録されます。

<Warning>
  Processing Monitor からイベントログをダウンロードできるのは、テナント管理者 (既定の tenant の場合はシステム管理者) および Monitoring Operator の権限を持つユーザーのみです。
</Warning>

このログをダウンロードするには、POST request を使用します:

```http theme={null}
POST https://<server address>/FlexiCapture12/Monitoring/Project/GetEventsCSV
```

<div id="request-parameters">
  ## リクエストパラメーター
</div>

すべてのパラメーターは必須です。正しく指定されていることを確認してください。

<Info>
  Oracle Database での検索では、大文字と小文字が区別されます。Oracle Database を使用する場合は、この点に注意してください。
</Info>

| パラメーター            | 型      | 説明                                                                                                                                                                                                             |
| ----------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `filter`          | string | ログのフィルター条件。条件の結合には、`GeneralOperator` パラメーターで設定する `AND` 演算子と `OR` 演算子のみを使用します。詳細は、[Build the filter parameter](#build-the-filter-parameter)を参照してください。                                                           |
| `columnsOrder`    | string | レポートに含める列をカンマ区切りで指定します: `ID`, `Date`, `EventType`, `Comment`, `UserFullName`, `Workstation`, `BatchId`, `BatchName`, `BatchTypeName`, `StageFromName`, `StageToName`, `ProjectName`, `RoleName`, `TenantName`. |
| `sortColumnindex` | int    | ログ内のレコードの並べ替えに使用する列のインデックス。                                                                                                                                                                                    |
| `sortOrder`       | bool   | 並べ替え順序: `true` は降順、`false` は昇順で並べ替えます。                                                                                                                                                                         |
| `projectId`       | int    | ログに含めるプロジェクト。利用可能なすべてのプロジェクトを指定する場合は `-1`、特定のプロジェクトを指定する場合は project ID (`1` 以上) を指定します。利用可能なすべての project ID を取得するには、[GetProjects](/ja/flexi-capture/api/methods/get-projects) メソッドを使用します。                      |

<div id="build-the-filter-parameter">
  ### `filter` パラメーターを作成する
</div>

`filter` パラメーターには JSON オブジェクトを指定します。たとえば、次のとおりです。

```json theme={null}
{
  "GeneralOperator": "AND",
  "FilterItems": [
    {
      "PropertyKey": "Date",
      "PropertyOperator": "BETWEEN",
      "PropertyValues": [
        "2021-08-28",
        "00:00:00",
        "2023-09-28",
        "23:59:59"
      ]
    },
    {
      "PropertyKey": "Id",
      "PropertyOperator": ">=",
      "PropertyValues": ["127602430"]
    },
    {
      "PropertyKey": "BatchName",
      "PropertyOperator": "CONTAINS",
      "PropertyValues": ["default"]
    }
  ]
}
```

`PropertyKey` パラメーターと `PropertyOperator` パラメーターの値を確認するには、管理および監視コンソールでフィルターを作成します。

<Steps>
  <Step title="ブラウザーの開発者ツールを開く">
    ブラウザーのメニューで **More tools → Developer tools** をクリックし、**Network** タブに移動します。
  </Step>

  <Step title="コンソールでフィルターを作成する">
    管理および監視コンソールを起動し、**Processing Monitor → イベントログ** に移動して、<img src="https://mintcdn.com/abbyy/39LtOHLEp1q7pm1x/images/flexi-capture/Add_filter.png?fit=max&auto=format&n=39LtOHLEp1q7pm1x&q=85&s=7fca1d511f8470021946ae439989fb68" alt="フィルター追加ボタン" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="22" height="22" data-path="images/flexi-capture/Add_filter.png" /> ボタンをクリックします。
  </Step>

  <Step title="フィルター条件を適用する">
    フィルター条件を指定し、**Apply** をクリックします。
  </Step>

  <Step title="フィルターパラメーターを確認する">
    `GetFilteredEvents` リクエストをクリックします。フィルタリング パラメーターは **Payload** タブに表示されます。
  </Step>
</Steps>

デフォルト バッチのイベントをフィルタリングするには、`BatchTypeName` ではなく `BatchTypeNameExt` パラメーターを指定します。

```json theme={null}
"FilterItems": [
  {
    "PropertyKey": "BatchTypeNameExt",
    "PropertyOperator": "CONTAINS",
    "PropertyValues": ["Default"]
  }
]
```

<Note>
  `columnsOrder` パラメーターでは、既定のバッチには `BatchTypeName` を使用してください。
</Note>

<div id="example-script">
  ## スクリプト例
</div>

次の PowerShell スクリプトは、この API を使用してイベント ログをダウンロードする方法を示しています。

<Note>
  このスクリプト内のパラメーターを、ご利用のサーバー アドレス、テナント名、および認証情報に置き換えてください。
</Note>

```powershell theme={null}
# パラメーター
$server = "https://<server address>"
$tenant = "<tenant name>"
$user = "<user name>"
$password = "<password>"
#ログの保存先フォルダーのパス
$folder = "C:\Temp\Logs\Stage"
$reportFileName = "Project_Events-{0:yyMMdd-HHmmss}.csv" -f (Get-Date)
# ログパラメーター
$requestBody =  @"
filter={
    "Name": "Complex filter",
    "GeneralOperator": "AND",
    "FilterItems": [
        {
            "PropertyKey": "Date",
            "PropertyOperator": "BETWEEN",
            "PropertyValues": ["2018-09-12","00:00:00","2023-10-12","23:59:59"]
        },
        {
            "PropertyKey": "Id",
            "PropertyOperator": ">=",
            "PropertyValues": ["127602430"]
        }
    ]
}
&columnsOrder=Id,Date,EventType,Comment,UserFullName,Workstation,BatchId,BatchName,BatchTypeName,StageFromName,StageToName,ProjectName,RoleName,TenantName
&sortColumnindex=0
&sortOrder=true
&projectId=-1
"@
#------------------------------------------------------------------------------
$methodUri = "/Project/GetEventsCSV"
$authServer = $server
$ServerSitePath = "/FlexiCapture12/Monitoring"

function Write-Line($str, $color = "White")
{
    Write-Host $str -ForegroundColor $color
}

function Join-Uri
{
    param([Parameter(Mandatory, ValueFromPipeline)] [string]$parent, [string]$child)
    if ($parent -eq "") {return $child;}
    if ($child -eq ""){return $parent}
    if ($parent.endswith("/") -or $parent.endswith("\\")) {$parent = $parent.substring(0,$parent.Length-1)}
    if ($child.startswith("/") -or $child.startswith("\\")) {$child = $child.substring(1,$child.Length-1)}
    return "$parent/$child"
}

function Get-AuthTicket($server, $user, $password, $tenant)
{
    $tenantSuffix=""
    if ($tenant -ne ''){ $tenantSuffix = "?tenant=$tenant"}
    $URL = Join-Uri $authServer "/FlexiCapture12/Server/FCAuth/API/Soap$tenantSuffix"
    $SOAPRequest = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><FindUser xmlns="urn:http://www.abbyy.com/FlexiCapture"><userLogin>user</userLogin></FindUser></soap:Body></soap:Envelope>'
    $Headers = @{
        'SOAPAction' = '"#FindUser"'
        'Content-Type' = 'text/xml; charset=utf-8'
        'Authorization' = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($user):$($password)")))"
    }
    try
    {
        $response1 = Invoke-WebRequest -Uri $URL -Headers $Headers -Body $SOAPRequest -Method 'POST'
        return $response1.Headers['AuthTicket']
    }
    catch{
        Write-Line -str "Couldn't get 'AuthTicket': $_" -color "Red"
        return ""
    }
}

function Download-CSVReport($server, $tenant, $authTicket, $methodUri, $requestBody, $folder, $reportFileName)
{
    $reportFullFilePath = Join-Path $folder $reportFileName
    #フォルダーをサイレント作成（存在しない場合）
    New-Item -ItemType Directory -Force -Path $folder | Out-Null
    if ($authTicket -eq "" -or $authTicket -eq $null)
    {
        Write-Line -str "Couldn't get 'CSV-Report'" -color "Red"
    }
    else
    {
        $header = @{ "Accept" = "*/*"}
        $session = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
        $session.Cookies.Add($server, [System.NET.Cookie]::new("FlexiCaptureTmpPrn$tenant", "Ticket=$authTicket"))
        $tenantInUrl=""
        if ($tenant -ne '') { $tenantInUrl = "/$tenant"}
        $uri = Join-Uri $server $ServerSitePath | Join-Uri -child $tenantInUrl | Join-Uri -child $methodUri
        try{
            $response = Invoke-WebRequest -Uri $uri -Method 'POST' -Headers $header -WebSession $session -Body $requestBody -OutFile $reportFullFilePath -MaximumRedirection 0 -ErrorAction Ignore -PassThru
            if ($response.StatusCode -lt 300)
            {
                Write-Line "CSV-Report done: $reportFullFilePath" "Green"
            }
            else
            {
                Write-Line -str "HttpStatus $($response.StatusCode) in getting CSV-Report." -color "Red"
            }
        }
        catch{
            Write-Line -str "Couldn't get CSV-Report: $_" -color "Red"
            return ""
        }
    }
}

$authTicket = Get-AuthTicket -server $server -user $user -password $password -tenant $tenant
Download-CSVReport -server $server -tenant $tenant -authTicket $authTicket -methodUri $methodUri -requestBody $requestBody -folder $folder -reportFileName $reportFileName
```
