summaryrefslogtreecommitdiffstats
path: root/support.lua
diff options
context:
space:
mode:
Diffstat (limited to 'support.lua')
-rw-r--r--support.lua79
1 files changed, 53 insertions, 26 deletions
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)