Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

log-search: Search for user-ids.

Alex Vandiver056895cc33d2
diff --git a/scripts/log-search b/scripts/log-search
index 2e8e04d0035..b85b2dbdc80 100755
--- a/scripts/log-search
+++ b/scripts/log-search
@@ -143,6 +143,7 @@ PYTHON_LOG_LINE_RE = re.compile(
class FilterType(Enum):
HOSTNAME = auto()
CLIENT_IP = auto()
+ USER_ID = auto()
def main() -> None:
@@ -181,12 +182,15 @@ def main() -> None:
# invalid. However, we expect the input here to already be
# reasonably well-formed.
filter = args.filter
- if re.match(r"\d{1,3}(\.\d{1,3}){3}$", filter):
+
+ if re.match(r"\d+$", filter):
+ if args.nginx:
+ raise parser().error("Cannot parse user-ids with nginx logs; try without --nginx")
+ string_filter = lambda m: m["user_id"] == filter
+ filter_type = FilterType.USER_ID
+ elif re.match(r"\d{1,3}(\.\d{1,3}){3}$", filter):
string_filter = lambda m: m["ip"] == filter
filter_type = FilterType.CLIENT_IP
- elif re.match(r"\d{1,3}\.(\d{1,3}\.){0,2}$", filter):
- string_filter = lambda m: m["ip"].startswith(filter)
- filter_type = FilterType.CLIENT_IP
elif re.match(r"([a-f0-9:]+:+){1,7}[a-f0-9]+$", filter):
string_filter = lambda m: m["ip"] == filter
filter_type = FilterType.CLIENT_IP
@@ -294,10 +298,21 @@ def print_line(
color = FAIL
url = f"{BOLD}{match['path']}"
if filter_type != FilterType.HOSTNAME:
- url = "https://" + match["hostname"] + url
+ hostname = match["hostname"]
+ if not args.nginx:
+ if hostname == "root":
+ hostname = "zulip.com"
+ else:
+ hostname += ".zulipchat.com"
+ url = "https://" + hostname + url
+
+ user_id = ""
+ if not args.nginx and match["user_id"] is not None:
+ user_id = match["user_id"] + "@"
parts = [
ts,
+ f"{user_id:7}" if not args.nginx and filter_type != FilterType.USER_ID else None,
f"{match['ip']:39}" if filter_type != FilterType.CLIENT_IP else None,
indicator + match["code"],
f"{match['method']:6}",