diff options
Diffstat (limited to 'syslog-model.lua')
-rw-r--r-- | syslog-model.lua | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/syslog-model.lua b/syslog-model.lua index 1d402d3..6fa4bce 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -6,6 +6,7 @@ require("getopts") require("format") local configfile = "/etc/conf.d/syslog" +local config = {} local function get_version() local cmd = "/sbin/apk_version -v -s busybox | cut -d ' ' -f 1" @@ -30,10 +31,10 @@ function getstatus() local status = {} status.version = get_version() status.enabled = procps.pidof("syslogd") - if not ((opts["SYSLOGD_OPTS"]["-R"] ~= "") and not (opts["SYSLOGD_OPTS"]["-L"])) then + if (opts["SYSLOGD_OPTS"]) and not ((opts["SYSLOGD_OPTS"]["-R"] ~= "") and not (opts["SYSLOGD_OPTS"]["-L"])) then status.logfile = opts["SYSLOGD_OPTS"]["-O"] end - if (opts["SYSLOGD_OPTS"]["-R"]) and (opts["SYSLOGD_OPTS"]["-R"] ~= "") then + if (opts["SYSLOGD_OPTS"]) and (opts["SYSLOGD_OPTS"]["-R"]) and (opts["SYSLOGD_OPTS"]["-R"] ~= "") then status.remote = opts["SYSLOGD_OPTS"]["-R"] end return status @@ -42,25 +43,35 @@ end function get_filedetails() local filedetails = {} local path = configfile - filedetails.details = fs.stat(path) - filedetails.content = fs.read_file(path) + if (fs.is_file(path)) then + filedetails.details = fs.stat(path) + filedetails.content = fs.read_file(path) + else + filedetails.details = {path="File is missing", size="0",mtime=""} + filedetails.content = "" + end return filedetails end function getconfig() local errors = {} errors["SYSLOGD_OPTS"] = {} errors["KLOGD_OPTS"] = {} - local config = getopts.getoptsfromfile(configfile) + if (fs.is_file(configfile)) then + config = getopts.getoptsfromfile(configfile) + else + config['SYSLOGD_OPTS']={} + end config["SYSLOGD_OPTS"]["-O"] = config["SYSLOGD_OPTS"]["-O"] or "/var/log/messages" config["SYSLOGD_OPTS"]["-l_list"] = getloglevels() config["SYSLOGD_OPTS"]["-R"] = config["SYSLOGD_OPTS"]["-R"] or "" + config["SYSLOGD_OPTS"]["-s"] = config["SYSLOGD_OPTS"]["-s"] or "" + config["SYSLOGD_OPTS"]["-b"] = config["SYSLOGD_OPTS"]["-b"] or "" if (config["SYSLOGD_OPTS"]["-l"]) and ((tonumber(config["SYSLOGD_OPTS"]["-l"]) == nil) or (tonumber(config["SYSLOGD_OPTS"]["-l"]) > 8)) then errors["SYSLOGD_OPTS"]["-l"] = "Log value is out of range. Please select one of the above." else config["SYSLOGD_OPTS"]["-l"] = config["SYSLOGD_OPTS"]["-l"] or 8 end - return config, errors end |