

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Hitung perujuk, alamat IP, atau aturan yang cocok
<a name="query-examples-waf-logs-count"></a>

Contoh di bagian ini meminta jumlah item log yang menarik.
+ [Count the number of referrers that contain a specified term](#waf-example-count-referrers-with-specified-term)
+ [Count all matched IP addresses in the last 10 days that have matched excluded rules](#waf-example-count-matched-ip-addresses)
+ [Group all counted managed rules by the number of times matched](#waf-example-group-managed-rules-by-times-matched)
+ [Group all counted custom rules by number of times matched](#waf-example-group-custom-rules-by-times-matched)

**Example — Hitung jumlah perujuk yang berisi istilah tertentu**  
Kueri berikut menghitung jumlah perujuk yang berisi istilah “amazon” untuk rentang tanggal yang ditentukan.  

```
WITH test_dataset AS 
  (SELECT header FROM waf_logs
    CROSS JOIN UNNEST(httprequest.headers) AS t(header) WHERE "date" >= '2021/03/01'
    AND "date" < '2021/03/31')
SELECT COUNT(*) referer_count 
FROM test_dataset 
WHERE LOWER(header.name)='referer' AND header.value LIKE '%amazon%'
```

**Example — Hitung semua alamat IP yang cocok dalam 10 hari terakhir yang telah cocok dengan aturan yang dikecualikan**  
Kueri berikut menghitung jumlah kali dalam 10 hari terakhir bahwa alamat IP cocok aturan dikecualikan dalam grup aturan.   

```
WITH test_dataset AS 
  (SELECT * FROM waf_logs 
    CROSS JOIN UNNEST(rulegrouplist) AS t(allrulegroups))
SELECT 
  COUNT(*) AS count, 
  "httprequest"."clientip", 
  "allrulegroups"."excludedrules",
  "allrulegroups"."ruleGroupId"
FROM test_dataset 
WHERE allrulegroups.excludedrules IS NOT NULL AND from_unixtime(timestamp/1000) > now() - interval '10' day
GROUP BY "httprequest"."clientip", "allrulegroups"."ruleGroupId", "allrulegroups"."excludedrules"
ORDER BY count DESC
```

**Example — Kelompokkan semua aturan terkelola yang dihitung dengan berapa kali dicocokkan**  
Jika Anda menetapkan tindakan aturan grup aturan ke Hitung dalam konfigurasi ACL web Anda sebelum 27 Oktober 2022, AWS WAF simpan penggantian Anda di web ACL JSON sebagai. `excludedRules` Sekarang, pengaturan JSON untuk mengganti aturan ke Count ada di `ruleActionOverrides` pengaturan. Untuk informasi selengkapnya, lihat [Penggantian tindakan di grup aturan di Panduan AWS WAF](https://docs.aws.amazon.com/waf/latest/developerguide/web-acl-rule-group-override-options.html) *Pengembang*. Untuk mengekstrak aturan terkelola dalam mode Hitung dari struktur log baru, kueri `nonTerminatingMatchingRules` di `ruleGroupList` bagian alih-alih `excludedRules` bidang, seperti pada contoh berikut.  

```
SELECT
 count(*) AS count,
 httpsourceid,
 httprequest.clientip,
 t.rulegroupid, 
 t.nonTerminatingMatchingRules
FROM "waf_logs" 
CROSS JOIN UNNEST(rulegrouplist) AS t(t) 
WHERE action <> 'BLOCK' AND cardinality(t.nonTerminatingMatchingRules) > 0 
GROUP BY t.nonTerminatingMatchingRules, action, httpsourceid, httprequest.clientip, t.rulegroupid 
ORDER BY "count" DESC 
Limit 50
```

**Example — Kelompokkan semua aturan kustom yang dihitung dengan berapa kali cocok**  
Kelompok kueri berikut semua menghitung aturan kustom dengan berapa kali cocok.  

```
SELECT
  count(*) AS count,
         httpsourceid,
         httprequest.clientip,
         t.ruleid,
         t.action
FROM "waf_logs" 
CROSS JOIN UNNEST(nonterminatingmatchingrules) AS t(t) 
WHERE action <> 'BLOCK' AND cardinality(nonTerminatingMatchingRules) > 0 
GROUP BY t.ruleid, t.action, httpsourceid, httprequest.clientip 
ORDER BY "count" DESC
Limit 50
```

Untuk informasi tentang lokasi log untuk aturan kustom dan grup aturan terkelola, lihat [Memantau dan menyetel](https://docs.aws.amazon.com/waf/latest/developerguide/web-acl-testing-activities.html) di *Panduan AWS WAF Pengembang*.