Created
February 2, 2021 21:15
-
-
Save mccutchen/ca9f36c269a8b6a62143fc757474d028 to your computer and use it in GitHub Desktop.
Revisions
-
mccutchen created this gist
Feb 2, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/usr/bin/env python3 import argparse import subprocess import sys import urllib.parse def main(env: str, services: [str]) -> int: filters = [f"env:{env}"] if services: filters.append(" OR ".join(f"service:{svc_name(s)}" for s in services)) params = { "query": " ".join(filters), } url = f"https://app.datadoghq.com/logs?{urllib.parse.urlencode(params)}" print(url) return subprocess.call(["open", url]) def svc_name(s: str): """ Allow service to be specified as any of service apps/service apps/service/ /path/to/apps/service/ The form with a trailing slash is likely when using tab completion in the terminal. """ return s.strip("/").split("/")[-1] if __name__ == "__main__": parser = argparse.ArgumentParser(description="Open datadog logs") parser.add_argument("env", metavar="ENV", type=str, help="environment") parser.add_argument( "services", metavar="SERVICE", type=str, nargs="*", help="service (optional, can specify more than one)", ) args = parser.parse_args() sys.exit(main(args.env, args.services))