次の表は、サポートされる比較演算子と値の例です。フィルターは、{"key":"<field>","operator":"<comparison_operator>","value":"<value>"} の形式でエスケープした JSON 文字列として追加します。
-
各データセットのフィールド一覧は、データセット を参照してください。
-
比較演算子は、式が true を返すために、値がログ行のフィールドとどのように関係する必要があるかを定義します。
-
値は、フィールドに紐づくデータです。
| 名前 | 演算子 | String | Int | Bool | Array | Object | 例 |
|---|---|---|---|---|---|---|---|
| 等しい | eq |
✅ | ✅ | ✅ | ❌ | ❌ | {"key":"ClientRequestHost","operator":"eq","value":"example.com"} |
| 等しくない | !eq |
✅ | ✅ | ✅ | ❌ | ❌ | {"key":"ClientCountry","operator":"!eq","value":"ca"} |
| より小さい | lt |
❌ | ✅ | ❌ | ❌ | ❌ | {"key":"BotScore","operator":"lt","value":"30"} |
| 以下 | leq |
❌ | ✅ | ❌ | ❌ | ❌ | {"key":"BotScore","operator":"leq","value":"30"} |
| より大きい | gt |
❌ | ✅ | ❌ | ❌ | ❌ | {"key":"BotScore","operator":"gt","value":"30"} |
| 以上 | geq |
❌ | ✅ | ❌ | ❌ | ❌ | {"key":"BotScore","operator":"geq","value":"30"} |
| 次で始まる | startsWith |
✅ | ❌ | ❌ | ❌ | ❌ | {"key":"ClientRequestPath","operator":"startsWith","value":"/foo"} |
| 次で終わる | endsWith |
✅ | ❌ | ❌ | ❌ | ❌ | {"key":"ClientRequestPath","operator":"endsWith","value":"/foo"} |
| 次で始まらない | !startsWith |
✅ | ❌ | ❌ | ❌ | ❌ | {"key":"ClientRequestPath","operator":"!startsWith","value":"/foo"} |
| 次で終わらない | !endsWith |
✅ | ❌ | ❌ | ❌ | ❌ | {"key":"ClientRequestPath","operator":"!endsWith","value":"/foo"} |
| 含む | contains |
✅ | ❌ | ❌ | ✅ | ❌ | {"key":"ClientRequestPath","operator":"contains","value":"/static"} |
| 含まない | !contains |
✅ | ❌ | ❌ | ✅ | ❌ | {"key":"ClientRequestPath","operator":"!contains","value":"/static"} |
| 値が集合に含まれる | in |
✅ | ✅ | ❌ | ❌ | ❌ | {"key":"EdgeResponseStatus","operator":"in","value":[200,201]} |
| 値が集合に含まれない | !in |
✅ | ✅ | ❌ | ❌ | ❌ | {"key":"EdgeResponseStatus","operator":"!in","value":[200,201]} |
filter フィールドには、演算子約 30 個、約 1000 バイトの制限があります。この値を超えるとエラーが返されます。
-
フィルターは
AND、ORの論理演算子でつなげられます。 -
論理演算子は入れ子にできます。
論理演算子の使い方の例を次に示します。X、Y、Z はフィルター条件を表します。
-
X AND Y AND Z -
{"where":{"and":[{X},{Y},{Z}]}} -
X OR Y OR Z -
{"where":{"or":[{X},{Y},{Z}]}} -
X AND (Y OR Z) -
{"where":{"and":[{X}, {"or":[{Y},{Z}]}]}} -
(X AND Y) OR Z -
{"where":{"or":[{"and": [{X},{Y}]},{Z}]}}
Logpush のフィルターは除外リストではなく、通過ゲートとして働きます。複数の条件を AND でつなぐ場合:
- ログがプッシュされるには、すべての条件が TRUE である必要があります。
- 1 つでも FALSE の条件があれば、そのログは除外されます。
よくある誤解は、フィルターを include logs matching ALL conditions ではなく exclude logs matching ALL conditions と解釈することです。
フィルターは API または Cloudflare ダッシュボードで設定できます。フィルターの使用は任意ですが、使う場合は where キーを含める必要があります。
cURL で API にリクエストする例です。
Required API token permissions
At least one of the following token permissions is required:Logs Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/logpush/jobs" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "static-assets",
"output_options": {
"field_names": [
"ClientIP",
"EdgeStartTimestamp",
"RayID"
],
"sample_rate": 0.1,
"timestamp_format": "rfc3339",
"CVE-2021-44228": true
},
"dataset": "http_requests",
"filter": "{\"where\":{\"and\":[{\"key\":\"ClientRequestPath\",\"operator\":\"contains\",\"value\":\"/static\"},{\"key\":\"ClientRequestHost\",\"operator\":\"eq\",\"value\":\"example.com\"}]}}",
"destination_conf": "s3://<BUCKET_PATH>?region=us-west-2/"
}'ダッシュボードでフィルターを設定するには、次の手順を実行します。
-
Cloudflare ダッシュボードで、アカウントまたはドメイン(ゾーン)レベルの Logpush ページを開きます。
アカウントの場合: Logpush を開く ↗
ドメイン(ゾーン)の場合: Logpush を開く ↗
-
ストレージサービスへプッシュするデータセットを選択します。選択に応じて、それぞれ アカウントスコープのデータセット と ゾーンスコープのデータセット を利用できます。
-
Select data fields の下の Filter セクションで、フィルターを設定できます。
-
データセットフィールド、演算子、Value を選択します。
-
さらにフィルターを追加する場合は、
ANDとORの論理演算子でつなぎます。 -
Next を選択して、Logpush ジョブの設定を続けます。