Skip to content

Commit

Permalink
more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Derrick Petzold committed Dec 26, 2024
1 parent 09ed6fa commit dbc152e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws_log_parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def read_files(self, pathname):
if self.regex_filter:
reo = re.compile(self.regex_filter)
for path in base_path.iterdir():
if reo.match(path.name):
if reo.match(path.name) and path.is_file():
yield from self.read_file(path)
else:
for path in base_path.glob(f"**/*{self.file_suffix}"):
Expand Down
21 changes: 21 additions & 0 deletions examples/count-hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ def main():
parser.add_argument(
"--log-type",
type=lambda x: getattr(LogType, x),
default="CloudFront",
help="The the log type.",
)

parser.add_argument(
"--file-suffix",
default=".log",
help="The file suffix to filter on.",
)

parser.add_argument(
"--regex-filter",
help="The regex filter.",
)

parser.add_argument(
"--profile",
help="The aws profile to use.",
Expand All @@ -43,6 +55,12 @@ def main():
help="The aws region to use.",
)

parser.add_argument(
"--verbose",
action="store_true",
help="Enable verbose mode.",
)

args = parser.parse_args()

ip_attr = "client_ip" if args.log_type == LogType.CloudFront else "client.ip"
Expand All @@ -51,6 +69,9 @@ def main():
log_type=args.log_type,
profile=args.profile,
region=args.region,
verbose=args.verbose,
file_suffix=args.file_suffix,
regex_filter=args.regex_filter,
).read_url(args.url)

count_ips(entries, ip_attr)
Expand Down

0 comments on commit dbc152e

Please sign in to comment.