log-search: Add a filter by path.

This commit is contained in:
Alex Vandiver 2022-05-04 17:28:37 -07:00 committed by Tim Abbott
parent df47c5a750
commit 67e641f37d
1 changed files with 7 additions and 2 deletions

View File

@ -56,7 +56,7 @@ def parser() -> argparse.ArgumentParser:
)
filtering = parser.add_argument_group("Filtering")
filtering.add_argument("filter", help="IP address, hostname, or user-id to search for")
filtering.add_argument("filter", help="IP address, hostname, user-id, or path to search for")
filtering.add_argument(
"--all-lines",
"-L",
@ -154,6 +154,7 @@ class FilterType(Enum):
HOSTNAME = auto()
CLIENT_IP = auto()
USER_ID = auto()
PATH = auto()
def main() -> None:
@ -219,8 +220,12 @@ def main() -> None:
filter = filter.lower()
string_filter = lambda m: m["hostname"] == filter
filter_type = FilterType.HOSTNAME
elif re.match(r"/\S*$", filter):
string_filter = lambda m: m["path"] == filter
filter_type = FilterType.PATH
args.all_lines = True
else:
raise RuntimeError(f"Can't parse {filter} as an IP, hostname, or user-id.")
raise RuntimeError(f"Can't parse {filter} as an IP, hostname, user-id, or path.")
assert filter_type is not None
try: