-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple example for rsdos reading
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Example code that uses the AvroRsdosReader extension class to count | ||
# DOS attacks via a perDos callback method | ||
|
||
import sys | ||
from pyavro_stardust.rsdos import AvroRsdosReader, RsdosAttribute, \ | ||
AvroRsdos | ||
|
||
count = 0 | ||
attack_pkts = 0 | ||
|
||
def perDosCallback(rsdos, userarg): | ||
global count, attack_pkts | ||
|
||
count += 1 | ||
dos = rsdos.asDict() | ||
attack_pkts += dos['packet_count'] | ||
|
||
# Ideally, we'd do things with the other fields in 'dos' as well, | ||
# but this is just intended to be a very simple example | ||
|
||
def run(): | ||
# sys.argv[1] must be a valid wandio path -- e.g. a swift URL or | ||
# a path to a file on disk | ||
reader = AvroRsdosReader(sys.argv[1]) | ||
reader.start() | ||
|
||
# This will read all of the attack records and call `perDosCallback` on | ||
# each one | ||
reader.perAvroRecord(perDosCallback) | ||
reader.close() | ||
|
||
# Display our final results | ||
print("Attacks", count, " Packets:", attack_pkts) | ||
|
||
run() |