mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	log-search: Search for user-ids.
This commit is contained in:
		
				
					committed by
					
						
						Alex Vandiver
					
				
			
			
				
	
			
			
			
						parent
						
							b355a0a63e
						
					
				
				
					commit
					056895cc33
				
			@@ -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}",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user