diff options
Diffstat (limited to '')
-rwxr-xr-x | src/scripts/com.vmware.btresolver.py | 60 | ||||
-rwxr-xr-x | src/scripts/docker-url-handler.lnav | 62 | ||||
-rw-r--r-- | src/scripts/journald-url-handler.lnav | 33 | ||||
-rw-r--r-- | src/scripts/lnav-copy-text.lnav | 15 | ||||
-rwxr-xr-x | src/scripts/pcap_log-converter.sh | 13 | ||||
-rwxr-xr-x | src/scripts/piper-url-handler.lnav | 8 | ||||
-rw-r--r-- | src/scripts/scripts.am | 6 |
7 files changed, 197 insertions, 0 deletions
diff --git a/src/scripts/com.vmware.btresolver.py b/src/scripts/com.vmware.btresolver.py new file mode 100755 index 0000000..b5c7deb --- /dev/null +++ b/src/scripts/com.vmware.btresolver.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +import sys +import html +import time +import json +import urllib.request + +sys.stderr.write("reading stdin\n") +inj = json.load(sys.stdin) +sys.stderr.write("reading stdin done\n") + +if False: + print("Hello, World!") + sys.exit() + +RESOLVING_SERVICE_URL = "http://btresolver.eng.vmware.com:80/" +DEFAULT_TIMEOUT = 10 + +req_url = "%s%s" % (RESOLVING_SERVICE_URL, "async_resolve_text_bts") +log_msg = inj['log_msg'] +index = log_msg.find('[context]') +if index != -1: + log_msg = log_msg[index:] +body = json.dumps([log_msg]) +req = urllib.request.Request(req_url, body.encode('utf-8')) +resp = urllib.request.urlopen(req, timeout=DEFAULT_TIMEOUT) +resolve_content = json.loads(resp.read()) + +sys.stderr.write("resolve %s\n" % resolve_content) +if not resolve_content['success']: + print(resolve_content['errorString']) + sys.exit(1) + +time.sleep(0.5) + +delay = 1 + +done = False +while not done: + get_url = "%s%s" % (RESOLVING_SERVICE_URL, "get_task") + body = resolve_content['returnValue']['TaskIds'][0] + get_req = urllib.request.Request(get_url, body.encode('utf-8')) + get_resp = urllib.request.urlopen(get_req, timeout=DEFAULT_TIMEOUT) + get_content = json.loads(get_resp.read()) + sys.stderr.write("get %s\n" % get_content) + if get_content['returnValue']['state'] == 'RUNNING': + if get_content['returnValue']['exception'] is None: + time.sleep(delay) + if delay < 10: + delay = delay * 2 + else: + print("<pre>\n%s</pre>" % html.escape(get_content['returnValue']['exception'])) + done = True + elif get_content['returnValue']['state'] == 'COMPLETED': + if get_content['returnValue'].get('output') is not None: + print("<pre>\n%s</pre>" % html.escape(get_content['returnValue']['output'])) + elif get_content['returnValue'].get('exception') is not None: + print("<pre>\n%s</pre>" % html.escape(get_content['returnValue']['exception'])) + done = True diff --git a/src/scripts/docker-url-handler.lnav b/src/scripts/docker-url-handler.lnav new file mode 100755 index 0000000..a8e9597 --- /dev/null +++ b/src/scripts/docker-url-handler.lnav @@ -0,0 +1,62 @@ +# +# @synopsis: docker-url-handler +# @description: Internal script to handle opening docker/podman URLs +# + +;SELECT jget(url, '/scheme') AS docker_scheme, + jget(url, '/host') AS docker_hostname, + jget(url, '/path') AS docker_path + FROM (SELECT parse_url($1) AS url) + +;SELECT substr($docker_path, 2) AS docker_relpath + +;SELECT CASE + $docker_hostname + WHEN 'compose' THEN ( + SELECT group_concat( + printf( + ':sh --name=%s %s-compose -f %s logs --no-log-prefix -f %s', + compose_services.key, + $docker_scheme, + $docker_relpath, + compose_services.key + ), + char(10) + ) AS cmds + FROM fstat($docker_relpath) AS st, + regexp_capture( + ifnull( + st.data, + raise_error( + 'Cannot read compose configuration: ' || $docker_relpath, + st.error + ) + ), + '(?m)(?:^---$)?((?:(?:.|\n)(?!^(?:---|\.\.\.)$))+)' + ) AS ydoc, + json_each( + yaml_to_json( + ydoc.content + ), + '$.services' + ) as compose_services + WHERE ydoc.match_index = 0 + AND ydoc.capture_index = 1 + ) + ELSE CASE + $docker_path + WHEN '/' THEN printf( + ':sh %s logs -f %s', + $docker_scheme, + $docker_hostname + ) + ELSE printf( + ':sh %s exec %s tail -n +0 -F "%s"', + $docker_scheme, + $docker_hostname, + $docker_path + ) + END + END AS cmds + +:eval ${cmds} diff --git a/src/scripts/journald-url-handler.lnav b/src/scripts/journald-url-handler.lnav new file mode 100644 index 0000000..904237c --- /dev/null +++ b/src/scripts/journald-url-handler.lnav @@ -0,0 +1,33 @@ +# +# @synopsis: journald-url-handler +# @description: Internal script to handle opening journald URLs +# + +;SELECT + jget(url, '/scheme') AS jscheme, + jget(url, '/host') AS jhost, + jget(url, '/parameters') as jparams + FROM (SELECT parse_url($1) AS url) + +;SELECT + printf(':sh journalctl --output=json -f %s %s', + CASE $jhost + WHEN 'localhost' THEN + '' + ELSE + '-m ' || $jhost + END, + (SELECT group_concat( + CASE length(key) + WHEN 1 THEN + '-' || key || ' ' + ELSE + '--' || key || '=' + END || + value, + ' ') + FROM json_each($jparams) + ) + ) AS cmds + +:eval ${cmds} diff --git a/src/scripts/lnav-copy-text.lnav b/src/scripts/lnav-copy-text.lnav new file mode 100644 index 0000000..541409e --- /dev/null +++ b/src/scripts/lnav-copy-text.lnav @@ -0,0 +1,15 @@ +# +# @synopsis: lnav-copy-text +# @description: Copy text from the top view +# + +;SELECT jget(selected_text, '/value') AS content FROM lnav_top_view +;SELECT CASE + WHEN $content IS NULL THEN + ':write-to -' + ELSE + ':echo -n ${content}' + END AS cmd + +:redirect-to /dev/clipboard +:eval ${cmd} diff --git a/src/scripts/pcap_log-converter.sh b/src/scripts/pcap_log-converter.sh new file mode 100755 index 0000000..80148e9 --- /dev/null +++ b/src/scripts/pcap_log-converter.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Check that tshark is installed and return a nice message. +if ! command -v tshark > /dev/null; then + echo "pcap support requires 'tshark' v3+ to be installed" > /dev/stderr + exit 1 +fi + +# We want tshark output to come in UTC +export TZ=UTC + +# Use tshark to convert the pcap file into a JSON-lines log file +exec tshark -T ek -P -V -t ad -r $2 diff --git a/src/scripts/piper-url-handler.lnav b/src/scripts/piper-url-handler.lnav new file mode 100755 index 0000000..f186767 --- /dev/null +++ b/src/scripts/piper-url-handler.lnav @@ -0,0 +1,8 @@ +# +# @synopsis: piper-url-handler +# @description: Internal script to handle opening piper URLs +# + +;SELECT jget(url, '/host') AS uhost FROM (SELECT parse_url($1) AS url) + +:open ${LNAV_WORK_DIR}/piper/$uhost/out.* diff --git a/src/scripts/scripts.am b/src/scripts/scripts.am index 50e10fd..32d0cd8 100644 --- a/src/scripts/scripts.am +++ b/src/scripts/scripts.am @@ -1,12 +1,18 @@ BUILTIN_LNAVSCRIPTS = \ $(srcdir)/scripts/dhclient-summary.lnav \ + $(srcdir)/scripts/docker-url-handler.lnav \ + $(srcdir)/scripts/journald-url-handler.lnav \ + $(srcdir)/scripts/lnav-copy-text.lnav \ $(srcdir)/scripts/lnav-pop-view.lnav \ $(srcdir)/scripts/partition-by-boot.lnav \ + $(srcdir)/scripts/piper-url-handler.lnav \ $(srcdir)/scripts/rename-stdin.lnav \ $(srcdir)/scripts/search-for.lnav \ $() BUILTIN_SHSCRIPTS = \ + $(srcdir)/scripts/com.vmware.btresolver.py \ $(srcdir)/scripts/dump-pid.sh \ + $(srcdir)/scripts/pcap_log-converter.sh \ $() |