diff options
Diffstat (limited to '')
-rw-r--r-- | src/scripts/README.md | 5 | ||||
-rw-r--r-- | src/scripts/dhclient-summary.lnav | 23 | ||||
-rwxr-xr-x | src/scripts/dump-pid.sh | 13 | ||||
-rw-r--r-- | src/scripts/lnav-pop-view.lnav | 21 | ||||
-rw-r--r-- | src/scripts/partition-by-boot.lnav | 12 | ||||
-rw-r--r-- | src/scripts/rename-stdin.lnav | 12 | ||||
-rw-r--r-- | src/scripts/scripts.am | 12 | ||||
-rw-r--r-- | src/scripts/search-for.lnav | 7 |
8 files changed, 105 insertions, 0 deletions
diff --git a/src/scripts/README.md b/src/scripts/README.md new file mode 100644 index 0000000..e06d609 --- /dev/null +++ b/src/scripts/README.md @@ -0,0 +1,5 @@ +# Scripts + +This directory contains the built-in lnav scripts. The files are +turned into C using `bin2c` and compiled into the executable. New scripts +need to be added to the [scripts.am](scripts.am) file. diff --git a/src/scripts/dhclient-summary.lnav b/src/scripts/dhclient-summary.lnav new file mode 100644 index 0000000..87d0c1a --- /dev/null +++ b/src/scripts/dhclient-summary.lnav @@ -0,0 +1,23 @@ +# +# @synopsis: dhclient-summary +# @description: Generate a summary of DHCP addresses bound in this log +# + +:echo DHCP leases over time: +:echo +;SELECT ip AS IP, start_time AS "Start Time", + printf("% 24s", CASE + WHEN end_time IS NULL THEN printf("%s%s%s", $ansi_green, 'Active', $ansi_norm) + ELSE + printf("%s%.02f%s hours", $ansi_bold, (julianday(end_time) - julianday(start_time)) * 24, $ansi_norm) + END) AS Duration + FROM + (WITH lease_times AS + (SELECT min(log_time) AS start_time, ip FROM + (SELECT log_time, regexp_match('bound to (\S+) --', log_text) AS ip FROM syslog_log WHERE ip IS NOT NULL) + GROUP BY ip ORDER BY start_time ASC) + SELECT start_time, + (SELECT lt2.start_time AS end_time FROM lease_times AS lt2 WHERE lt1.start_time < lt2.start_time LIMIT 1) AS end_time, + ip + FROM lease_times AS lt1) +:write-table-to - diff --git a/src/scripts/dump-pid.sh b/src/scripts/dump-pid.sh new file mode 100755 index 0000000..f17630c --- /dev/null +++ b/src/scripts/dump-pid.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +IN_PID=`cat` + +if test "${IN_PID}" -gt 0 > /dev/null 2>&1 && \ + kill -0 $IN_PID > /dev/null 2>&1; then + echo "== ps ==" + ps uewww -p $IN_PID + echo "== lsof ==" + lsof -p $IN_PID +else + echo "error: inaccessible process -- $IN_PID" > /dev/stderr +fi diff --git a/src/scripts/lnav-pop-view.lnav b/src/scripts/lnav-pop-view.lnav new file mode 100644 index 0000000..89037e1 --- /dev/null +++ b/src/scripts/lnav-pop-view.lnav @@ -0,0 +1,21 @@ +# +# @synopsis: lnav-pop-view +# @description: Pop the top view on the view stack +# + +;SELECT rowid as row_to_delete, name as last_view_name, CASE name + WHEN 'db' THEN $keymap_def_db_view + WHEN 'histogram' THEN $keymap_def_hist_view + WHEN 'text' THEN $keymap_def_text_view + ELSE '' + END as view_alt_msg FROM lnav_view_stack ORDER BY rowid DESC LIMIT 1; +;SELECT top_time as last_top_time FROM lnav_views WHERE name = $last_view_name; +;DELETE FROM lnav_view_stack WHERE rowid = $row_to_delete; +;SELECT name AS new_top_view_name FROM lnav_view_stack ORDER BY rowid DESC LIMIT 1; +;SELECT top_time AS old_top_time FROM lnav_views WHERE name = $new_top_view_name; +;UPDATE lnav_views SET top_time = $last_top_time WHERE + $1 = 'x51' AND + name = $new_top_view_name AND + $last_top_time IS NOT NULL; +:eval :alt-msg ${view_alt_msg} +:echo diff --git a/src/scripts/partition-by-boot.lnav b/src/scripts/partition-by-boot.lnav new file mode 100644 index 0000000..e052774 --- /dev/null +++ b/src/scripts/partition-by-boot.lnav @@ -0,0 +1,12 @@ +# +# DO NOT EDIT THIS FILE, IT WILL BE OVERWRITTEN! +# +# @synopsis: partition-by-boot +# @description: Partition the log view based on boot messages from the Linux kernel. +# + +;UPDATE syslog_log + SET log_part = 'Boot: ' || log_time + WHERE log_text LIKE '%kernel:%Linux version%'; + +;SELECT 'Created ' || changes() || ' partitions(s)'; diff --git a/src/scripts/rename-stdin.lnav b/src/scripts/rename-stdin.lnav new file mode 100644 index 0000000..10a54b6 --- /dev/null +++ b/src/scripts/rename-stdin.lnav @@ -0,0 +1,12 @@ +# +# @synopsis: rename-stdin <name> +# @description: Give a symbolic name to the standard-input file +# + +;SELECT raise_error('expecting the new name for stdin as the first argument') WHERE $1 IS NULL +;SELECT raise_error('no data was redirected to lnav''s standard-input') + WHERE (SELECT count(1) FROM lnav_file WHERE filepath='stdin') = 0 + +;UPDATE lnav_file SET filepath=$1 WHERE filepath='stdin' + +;SELECT 'info: renamed stdin to ' || $1 AS msg diff --git a/src/scripts/scripts.am b/src/scripts/scripts.am new file mode 100644 index 0000000..50e10fd --- /dev/null +++ b/src/scripts/scripts.am @@ -0,0 +1,12 @@ + +BUILTIN_LNAVSCRIPTS = \ + $(srcdir)/scripts/dhclient-summary.lnav \ + $(srcdir)/scripts/lnav-pop-view.lnav \ + $(srcdir)/scripts/partition-by-boot.lnav \ + $(srcdir)/scripts/rename-stdin.lnav \ + $(srcdir)/scripts/search-for.lnav \ + $() + +BUILTIN_SHSCRIPTS = \ + $(srcdir)/scripts/dump-pid.sh \ + $() diff --git a/src/scripts/search-for.lnav b/src/scripts/search-for.lnav new file mode 100644 index 0000000..022ca78 --- /dev/null +++ b/src/scripts/search-for.lnav @@ -0,0 +1,7 @@ +# +# @synopsis: search-for +# @description: Start a search for the given string. +# + +;UPDATE lnav_views SET search = $__all__ WHERE name = ( + SELECT name FROM lnav_view_stack ORDER BY ROWID DESC LIMIT 1) |