From 4befdc8e690ed2110407698d77d287c73013d629 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 7 Sep 2009 14:41:44 +0000 Subject: Fixed bug with ip command by setting PATH for io.popen calls in health. --- health-model.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/health-model.lua b/health-model.lua index f505ea7..0389346 100644 --- a/health-model.lua +++ b/health-model.lua @@ -5,17 +5,19 @@ require("fs") require("date") require("format") +local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " + -- ############################################################### -- Private functions local function querycmd ( cmdline ) - local cmd = io.popen( format.escapespecialcharacters(cmdline) ) + local cmd = io.popen( path..format.escapespecialcharacters(cmdline) ) local cmd_result = cmd:read("*a") or "unknown" cmd:close() return cmd_result end local function indexversion ( ) - local cmd = io.popen( "/sbin/apk version --index 2>/dev/null" ) + local cmd = io.popen( path.."apk version --index 2>/dev/null" ) local cmd_result = cmd:read("*a") if cmd_result == "" then cmd_result = nil end cmd:close() @@ -24,7 +26,7 @@ end local function diskfree ( media ) if not (media) then media = "" end - local cmd = io.popen( "df -h " .. format.escapespecialcharacters(media) ) + local cmd = io.popen( path.."df -h " .. format.escapespecialcharacters(media) ) local cmd_result = cmd:read("*a") or "unknown" cmd:close() return cmd_result @@ -41,14 +43,14 @@ end -- Public functions get_system = function (self) local system = {} - system.uptime = cfe({ value=querycmd("/usr/bin/uptime"), label="Uptime" }) - system.date = cfe({ value=querycmd("/bin/date"), label="Date" }) + system.uptime = cfe({ value=querycmd("uptime"), label="Uptime" }) + system.date = cfe({ value=querycmd("date"), label="Date" }) local indexver = indexversion() system.version = cfe({ value=indexver or fs.read_file("/etc/alpine-release") or "Unknown", label="Version" }) system.timezone = cfe({ value=date.what_tz(), label="Time Zone" }) - system.uname = cfe({ value=querycmd("/bin/uname -a"), label="UName" }) - system.memory = cfe({ value=querycmd("/usr/bin/free"), label="Memory usage" }) - system.memory.used = getpercentage(querycmd("/usr/bin/free"), "Total:", 3, 4) + system.uname = cfe({ value=querycmd("uname -a"), label="UName" }) + system.memory = cfe({ value=querycmd("free"), label="Memory usage" }) + system.memory.used = getpercentage(querycmd("free"), "Total:", 3, 4) return cfe({ type="group", value=system }) end @@ -86,14 +88,14 @@ end get_network = function (self) local network = {} - network.interfaces = cfe({ value=querycmd("/bin/ip addr"), label="Interfaces" }) - network.routes = cfe({ value=querycmd("/bin/ip route"), label="Routes" }) + network.interfaces = cfe({ value=querycmd("ip addr"), label="Interfaces" }) + network.routes = cfe({ value=querycmd("ip route"), label="Routes" }) return cfe({ type="group", value=network }) end get_modules = function (self) local modules = {} - modules.list = cfe({ value=querycmd("/sbin/lsmod"), label="Modules List" }) + modules.list = cfe({ value=querycmd("lsmod"), label="Modules List" }) return cfe({ type="group", value=modules }) end -- cgit v1.2.3