diff options
| -rw-r--r-- | README | 11 | ||||
| -rw-r--r-- | lib/remote/print.sh | 26 | ||||
| -rw-r--r-- | lib/remote/report.sh | 27 | ||||
| -rw-r--r-- | logs.lua | 3 | ||||
| -rw-r--r-- | netstat.conf | 2 | ||||
| -rwxr-xr-x | remote/check_all.sh | 2 | ||||
| -rw-r--r-- | remote/darksoft.sh | 2 | ||||
| -rw-r--r-- | remote/ipeserv.sh | 2 | ||||
| -rw-r--r-- | remote/kaas.sh | 3 | ||||
| -rwxr-xr-x | scripts/run_conky.sh | 27 | ||||
| -rwxr-xr-x | service/check_router.sh | 2 | ||||
| -rw-r--r-- | setup/adei.txt | 2 | ||||
| -rw-r--r-- | setup/domains.txt | 2 | ||||
| -rw-r--r-- | setup/remote.sh | 2 | ||||
| -rw-r--r-- | support.lua | 79 | ||||
| -rw-r--r-- | sysinfo.conf | 2 |
16 files changed, 136 insertions, 58 deletions
@@ -1,4 +1,9 @@ + Requirements - luarocks install md5 - luarocks install luafilesystem - luarocks install lrexlib-pcre
\ No newline at end of file + luarocks install md5 --lua-version 5.3 (seems not in rocks, install from gentoo) + luarocks install socket --lua-version 5.3 (seems not in rocks, install from gentoo) + luarocks install luafilesystem --lua-version 5.3 (seems not in rocks, install from gentoo) + luarocks install lrexlib-pcre --lua-version 5.3 + +Environemt: + eval "$(luarocks path --lua-version 5.3)"
\ No newline at end of file diff --git a/lib/remote/print.sh b/lib/remote/print.sh index a0fdcbe..ef9c9b8 100644 --- a/lib/remote/print.sh +++ b/lib/remote/print.sh @@ -130,9 +130,33 @@ function print_hline { echo | eol } +acolumn() { + local sep="$1" out="$2" + awk -v FS="$sep" -v SEP="$out" -v OFS='' ' + function strip(s) { gsub(/\x1B\[[0-9;?]*[ -/]*[@-~]/, "", s); return s } + { + rows[NR] = $0 + if (NF > cols) cols = NF + for (i = 1; i <= NF; i++) + if (length(strip($i)) > w[i]) w[i] = length(strip($i)) + } + END { + for (r = 1; r <= NR; r++) { + n = split(rows[r], a, FS) + for (i = 1; i <= n; i++) { + pad = w[i] - length(strip(a[i])) + printf "%s%*s", a[i], (i < n ? pad : 0), "" + if (i < n) printf "%s", SEP + } + print "" + } + }' +} + function print_table { # The problem here is that all escapes for colors are treated as normal visible symbols - sed "s/ ::: /@/g" | column -t -s "@" -o " " | eol +# sed "s/ ::: /@/g" | column -t -s "@" -o "x x" --output-width 0 | eol + sed "s/ ::: /@/g" | acolumn "@" " " | eol } function decorate_table { diff --git a/lib/remote/report.sh b/lib/remote/report.sh index 434c6aa..c4373a3 100644 --- a/lib/remote/report.sh +++ b/lib/remote/report.sh @@ -3,13 +3,22 @@ function simple_report { local filter="${2:-cat}" # Create fd12 (sending empty output), execute checks (writting extra info on fd12), print main info and store extra info into variable, wait for termination of async checks. - { - chmod +w /dev/fd/12 - eval "$generator 12>/dev/fd/12 | $filter" - report=$(cat<&12) - } 12<<EOF -EOF - wait +# { +# chmod +w /dev/fd/12 +# eval "$generator 12>/dev/fd/12 | $filter" +# report=$(cat<&12) +# } 12<<EOF +#EOF +# wait + + fifo=$(mktemp -u) ; mkfifo "$fifo" + eval "$generator 12>$fifo | $filter" & + genpid=$! + + report_text=$(cat "$fifo") + wait "$genpid" + rm -f "$fifo" + } @@ -30,7 +39,7 @@ function standart_report { configure_palete "$palete" simple_report "$generator" "$filter" - print "$report" + print "$report_text" echo finish } @@ -38,7 +47,7 @@ function standart_report { function report { # Eval breaks output for some reason - case $report in + case $report_style in simple_report) simple_report "$@" ;; @@ -1,4 +1,5 @@ -require "luarocks.require" +-- require "luarocks.require" + rex_pcre = require "rex_pcre" do diff --git a/netstat.conf b/netstat.conf index dfd9174..4e463a5 100644 --- a/netstat.conf +++ b/netstat.conf @@ -53,7 +53,7 @@ ${color white}KaaS/Router ${goto 160}${lua_parse check_service_ router iperouter ${color yellow}Servers ${hr}${lua set_width $template2}${lua set_timeout $template3} ${color white}ipepdvsrv1 ${goto 160}${lua_parse check_server_status ipepdvsrv1.ipe.kit.edu} ${color white}ipepdvsrv2 ${goto 160}${lua_parse check_server_status ipepdvsrv2.ipe.kit.edu} -${color white}ipepdvarchive ${goto 160}${lua_parse check_server_status ipepdvarchive.ipe.kit.edu} +#${color white}ipepdvarchive ${goto 160}${lua_parse check_server_status ipepdvarchive.ipe.kit.edu} ${color white}ipekatrin1 ${goto 160}${lua_parse check_server_status ipekatrin1.ipe.kit.edu 22 uptime} ${color white}ipekatrin2 ${goto 160}${lua_parse check_server_status ipekatrin2.ipe.kit.edu 22 uptime} ${color white}ipekatrin3 ${goto 160}${lua_parse check_server_status ipekatrin3.ipe.kit.edu 22 uptime} diff --git a/remote/check_all.sh b/remote/check_all.sh index a506c82..83b8bd8 100755 --- a/remote/check_all.sh +++ b/remote/check_all.sh @@ -2,7 +2,7 @@ . lib/remote/status.sh -report="short_report" +report_style="short_report" run darksoft.sh run ipeserv.sh diff --git a/remote/darksoft.sh b/remote/darksoft.sh index 09823fa..d7949a5 100644 --- a/remote/darksoft.sh +++ b/remote/darksoft.sh @@ -1,6 +1,6 @@ #! /bin/bash -[ -z $report ] && source lib/remote/status.sh +[ -z $report_style ] && source lib/remote/status.sh function check_darksoft { check "DarkSoft" "darksoft.org" "check_server_status <host> vpn/192.168.21.1" "check_server_ traffic <host> 20 50" diff --git a/remote/ipeserv.sh b/remote/ipeserv.sh index a152076..a4ace97 100644 --- a/remote/ipeserv.sh +++ b/remote/ipeserv.sh @@ -1,6 +1,6 @@ #! /bin/bash -[ -z $report ] && source lib/remote/status.sh +[ -z $report_style ] && source lib/remote/status.sh function check_ipe { # check "katrin" "katrin.kit.edu" "check_server_status <host>" diff --git a/remote/kaas.sh b/remote/kaas.sh index 31f6661..ec042f2 100644 --- a/remote/kaas.sh +++ b/remote/kaas.sh @@ -1,7 +1,6 @@ #! /bin/bash -[ -z $report ] && source lib/remote/status.sh - +[ -z $report_style ] && source lib/remote/status.sh function check_kaas { check "KaaS" "kaas.kit.edu" "check_service kaas <host> 3" diff --git a/scripts/run_conky.sh b/scripts/run_conky.sh index 7648259..e718851 100755 --- a/scripts/run_conky.sh +++ b/scripts/run_conky.sh @@ -1,16 +1,19 @@ #!/bin/bash if [ "$1" != "start" ]; then - killall -9 conky - killall -9 rainlendar2 - killall -9 rainlendar2.bin + killall -9 conky &> /dev/null + killall -9 rainlendar2 &> /dev/null + killall -9 rainlendar2.bin &> /dev/null fi if [ "$1" != "stop" ]; then - python2 /opt/scripts/unlock.py gui || exit +#No way to do it anymore + python /opt/scripts/unlock.py gui || exit - killall -9 gpg-agent - pass test + killall -9 gpg-agent &> /dev/null + + /opt/scripts/restart-gpg.sh + pass test > /dev/null conky -q -d -c /etc/conky/sysinfo.conf conky -q -d -c /etc/conky/netstat.conf @@ -20,5 +23,15 @@ if [ "$1" != "stop" ]; then # todo should be loaded before forecast sleep 0.3 conky -q -d -c /etc/conky/forecast.conf - /opt/rainlendar2/rainlendar2 --quiet & + + +# sleep 1 +# ps xa | grep gpg-agent | grep -v gpg &> /dev/null +# if [ $? -ne 0 ]; then +# /opt/scripts/restart-gpg.sh +# fi + + +# Temporarily disabled. Only 2.16 works with google now and we don't have license. Might worth buying if use desktop again. +# /opt/rainlendar2/rainlendar2 --quiet & fi diff --git a/service/check_router.sh b/service/check_router.sh index f241f64..f188836 100755 --- a/service/check_router.sh +++ b/service/check_router.sh @@ -49,7 +49,7 @@ done #fi # VPN check -ssh -xa darksoft.org ping -W 2 -c 2 192.168.31.1 &> /dev/null +ssh -xa master.suren.me ping -W 2 -c 2 192.168.31.1 &> /dev/null if [ $? -ne 0 ]; then echo "Can't verify availability of UFO tunnel" [ $healthy -eq 1 ] && healthy=2 diff --git a/setup/adei.txt b/setup/adei.txt index 9c95888..2e2a2d9 100644 --- a/setup/adei.txt +++ b/setup/adei.txt @@ -3,4 +3,4 @@ kaas http://adei-katrin.kaas.kit.edu/adei/ detector http://192.168.110.67/adei/ crd http://adei.crd.yerphi.am/adei/ pcebessadei.competence-e.kit.edu http://pcebessadei.competence-e.kit.edu/adei-battery/ -imkmastadei.ka.fzk.de http://imkmastadei.ka.fzk.de/adei/ +imkmastadei.ka.fzk.de http://imkmastadei.imk-tro.kit.edu/adei/ diff --git a/setup/domains.txt b/setup/domains.txt index 4c119ab..c919d76 100644 --- a/setup/domains.txt +++ b/setup/domains.txt @@ -1,2 +1,2 @@ -imkmastadei ka.fzk.de +imkmastadei imk-tro.kit.edu pcebessadei competence-e.kit.edu diff --git a/setup/remote.sh b/setup/remote.sh index c172415..5470e9c 100644 --- a/setup/remote.sh +++ b/setup/remote.sh @@ -3,7 +3,7 @@ timeout=2 fold=120 palete='blue' parallel=0 -report="standart_report" +report_style="standart_report" # Helpers diff --git a/support.lua b/support.lua index 984d677..9b6735b 100644 --- a/support.lua +++ b/support.lua @@ -1,6 +1,7 @@ -require "luarocks.require" -require "md5" -require "lfs" +-- require "luarocks.require" +md5=require "md5" +lfs=require "lfs" +socket=require "socket" home = os.getenv( "HOME" ) @@ -10,10 +11,12 @@ c_timer_init = -1 do function conky_eval(...) + local arg = table.pack(...) return conky_parse(table.concat(arg, " ")) end function conky_multiply_line(times, ...) + local arg = table.pack(...) local str = table.concat(arg, " ") local tbl = {} for i=1,times,1 do @@ -50,7 +53,7 @@ do --]] local list = split(",", ips) for i, item in ipairs(list) do - if (string.match(item, "141\.52\.64")) then + if (string.match(item, "141%.52%.64")) then return item end end @@ -108,6 +111,7 @@ do function conky_check_server_status(server, port, ...) port = port or 22 + local arg = table.pack(...) local name = string.format("%s:%i", server, port); if (c_timer < 0) then @@ -133,6 +137,7 @@ do end f:close() end + if (result_check_server_status[name] == nil) then local res if (math.abs(c_timer)%2 > 0) then @@ -154,12 +159,17 @@ do elseif (c_timer == 0) then result_check_server_status[name] = check_server_status(server, port, arg) end - - return result_check_server_status[name]; + return (result_check_server_status[name] == nil) and "" or result_check_server_status[name] end - function check_server_status(server, port, additional) + function check_server_status(server, port, ...) port = port or 22 + local arg = table.pack(...) + local additional + + if arg ~= nil then + additional = arg[1] + end local res local cmd = string.format("/etc/conky/scripts/ping.pl %s:%i %i", server, port, timeout) @@ -168,7 +178,7 @@ do res = -1 else local data = cmdf:read("*a") - res = tonumber(data) + res = (data == nil) and -1 or tonumber(data) cmdf:close() end @@ -183,6 +193,10 @@ do return "${color red}*" end end + + if res == nil then + res = -1 + end if (res > 0) then online[server] = true @@ -196,13 +210,13 @@ do else local res = {} local line = cmdf:read("*l") - while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + while line do + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end line = cmdf:read("*l") - end + end -- res = cmdf:read("*a") cmdf:close() @@ -217,7 +231,7 @@ do end for i, service in ipairs(additional) - do + do cmd = string.format("ssh -x -p %i -o ConnectTimeout=%i root@%s /opt/scripts/check_%s_status.sh 2>&1 | fold -w %i", port, timeout, server, service, width) cmdf = cmd_popen(server, port, cmd) if (cmdf == nil) then @@ -226,7 +240,7 @@ do local res = {} local line = cmdf:read("*l") while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end @@ -239,9 +253,9 @@ do local s = 0 local extra = "" - local m1, m2 = string.match(info, "^\(%d+\)\(%s.+\)$") + local m1, m2 = string.match(info, "^(%d+)(%s.+)$") if (m1 == nil) then - m1 = string.match(info, "^\%d+$"); + m1 = string.match(info, "^(%d+)"); end if (m1 == nil) then table.insert(res, info) @@ -278,10 +292,11 @@ do online[server] = false res = string.format("${color red}* ") end - for i, service in ipairs(additional) do - res = res .. " " - end - + if (additional ~= nil) then + for i, service in ipairs(additional) do + res = res .. " " + end + end return res end end @@ -331,7 +346,7 @@ do local res = {} line = cmdf:read("*l") while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end @@ -341,7 +356,7 @@ do local info = table.remove(res) - local t1, t2, t3 = string.match(info, "^\(%d+\)%s+\(%d+\)%s+\(%d+\)") + local t1, t2, t3 = string.match(info, "^(%d+)%s+(%d+)%s+(%d+)") local s = tonumber(t1) if (s == nil) then @@ -387,6 +402,7 @@ do function conky_check_server_(service, server, port, ...) port = port or 22 + local arg = table.pack(...) local name = string.format("%s:%i:%s", server, port, service) if (c_timer < 0) then if (c_timer == -1) then @@ -420,6 +436,7 @@ do end function conky_check_service_(service, id, ...) + local arg = table.pack(...) local name = string.format("%s:%s", service, id) if (c_timer < 0) then if (c_timer == -1) then @@ -477,8 +494,14 @@ do local res = {} line = cmdf:read("*l") + if (line == nil) then + -- we can try another iteration? + socket.select(nil, nil, timeout) + line = cmdf:read("*l") + end + while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end @@ -488,7 +511,7 @@ do if (service == "traffic") then if (res[1]) then - local t1, t2, t3 = string.match(res[1], "^\(%d+\)%s+\(%d+\)%s+\(%d+\)") + local t1, t2, t3 = string.match(res[1], "^(%d+)%s+(%d+)%s+(%d+)") if (t1 and t2 and t3) then if ((opts) and (opts[1])) then yellow = tonumber(opts[1]) @@ -503,6 +526,8 @@ do else return "${color red}" .. res[1] end + else + return "${color red}?" end end @@ -512,7 +537,8 @@ do function check_service_(service, id, opts) - local cmd = string.format("/etc/conky/service/check_%s.sh %s %s 2>&1", service, id, table.concat(opts, " ")) + local optlist = ((opts == nil) and "" or table.concat(opts, " ")) + local cmd = string.format("/etc/conky/service/check_%s.sh %s %s 2>&1", service, id, optlist) cmdf = cmd_popen(service, id, cmd) if (cmdf == nil) then return "${color red}?" @@ -522,7 +548,7 @@ do local local_res = {} line = cmdf:read("*l") while line do - local t, m1 = string.match(line, "^\(\*?\)\(.*[^%s]\)%s*$") + local t, m1 = string.match(line, "^(%*?)(.*[^%s])%s*$") if (m1) then if (t == nil) or (t == '') then table.insert(res, m1) @@ -541,9 +567,10 @@ do local msg = '' if (info) then - t1, t2, msg = string.match(info, "^\(%d+\)%s+\(%d+\)\(.*\)") + t1, t2, msg = string.match(info, "^(%d+)%s+(%d+)(.*)") end + local s = tonumber(t1) if (s == nil) then table.insert(res, info) diff --git a/sysinfo.conf b/sysinfo.conf index ba0cd4b..ee5a48c 100644 --- a/sysinfo.conf +++ b/sysinfo.conf @@ -38,7 +38,7 @@ lua_load /etc/conky/support.lua # 7 - networking # 8 - ping + remote scripts template2 45 -template3 2 +template3 4 template5 120 template6 300 template7 600 |
