From 1ad214d1d45c737b6a12a33cc87314c8dc230b9a Mon Sep 17 00:00:00 2001 From: Blallo Date: Sat, 23 Mar 2019 19:09:38 +0100 Subject: [PATCH] New rec-client script. --- circolog-resources/rec-client.sh | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 circolog-resources/rec-client.sh diff --git a/circolog-resources/rec-client.sh b/circolog-resources/rec-client.sh new file mode 100755 index 0000000..2388f81 --- /dev/null +++ b/circolog-resources/rec-client.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +SESSION="circolog" +TAIL="ctl" +DAEMON="d" +DWINDOW="${SESSION}:${DAEMON}" +TAILWINDOW="${SESSION}:${TAIL}" + +d_send_command() { + tmux send-keys -t "${DWINDOW}.${1}" "${2}" Enter +} + +tail_send_command() { + tmux send-keys -t "${TAILWINDOW}.${1}" "${2}" Enter +} + +digit_command() { + local input=$2 + for (( i=0; i<${#input}; i++ )) + do + sleep 0.1 + tmux send-keys -t "${TAILWINDOW}.${1}" "${input:$i:1}" + done + sleep 2 + tmux send-keys -t "${TAILWINDOW}.${1}" Enter +} + +digit_comment() { + local input=$2 + for (( i=0; i<${#input}; i++ )) + do + sleep 0.1 + tmux send-keys -t "${TAILWINDOW}.${1}" "${input:$i:1}" + done + sleep 2 + for (( i=0; i<${#input}; i++ )) + do + tmux send-keys -t "${TAILWINDOW}.${1}" "C-h" + done +} + +config() { + tmux new -s $SESSION -n $TAIL -d + tmux new-window -t $SESSION -n $DAEMON + tmux split-window -v -t $DWINDOW + tmux set-option -t $SESSION status off + + d_send_command 0 "circologd" + tail_send_command 0 "bash" + tail_send_command 0 "PS1='my-server ~ '" + tail_send_command 0 "clear" +} + +logger_send() { + d_send_command 1 "logger -n 127.0.0.1 -P 9514 --rfc5424=nohost -t oper -d -p user.${2:-5} ${1}" +} + +start_ctl() { + sleep 3; + digit_comment 0 "Let's take a look at circolog-tail, the circologd client to read and *filter* logs." + digit_command 0 "circolog-tail" + sleep 2 + logger_send "This is a log message from some program." + sleep 2 + logger_send "This is an error. Look at these nice colors we have." "3" + sleep 2 + logger_send "This is a debug message." "7" + sleep 4 + tail_send_command 0 "C-c" + sleep 1 + digit_comment 0 "Let's see how to filter. The syntax is SQL-alike." + sleep 1 + digit_command 0 "circolog-tail -where 'msg LIKE \"%error%\"'" +} + +attach_session() { + tmux attach -t $TAILWINDOW +} + +cleanup() { + send_command 0 "C-c" + tmux kill-session -t $SESSION +} + +trap cleanup 2 15 +config +start_ctl & +attach_session