検証環境
RTX1210 BootROM Ver. 1.04
RTX1210 FlashROM Table Ver. 1.00
RTX1210 Rev.14.01.38 (Fri Jul 10 09:41:02 2020)
経緯
Lua on RTX1210して遊ぼうと思ったのは河野哲治氏のコラムを読んだのがきっかけ。
Lua未経験だったので、自分の理解のために写経を始めるうちに、Slack投稿などを外部化してこんなシリーズ投稿が生まれた。
前提
watch_login.lua
watch_login.lua
--
-- watch_login.lua
-- Login monitoring
--
require "strict"
local slack = require "slack"
ptn = "Log%l%l%l* "
local function log(priority, message)
if priority == "DEBUG" then
rt.syslog("notice", message)
else
rt.syslog("info", message)
slack.post(priority, message)
end
end
local function find_string(syslog_message)
if string.find(syslog_message, "succeeded") ~= nil then
return "INFO", "Login Succeeded."
end
if string.find(syslog_message, "failed") ~= nil then
return "WARN", "Login Failed."
end
if string.find(syslog_message, "Logout") ~= nil then
return "INFO", "Logout."
end
if string.find(syslog_message, "restricted") ~= nil then
return "ERROR", "Login Restricted."
end
end
while true do
local rtn, str = rt.syslogwatch(ptn, 1)
if rtn and str then
rt.syslog("debug", "(watch_login.lua) Found log: " .. str[1])
local priority, message = find_string(str[1])
if message then
log("INFO", "(watch_login.lua) " .. message)
else
log("INFO", "(watch_login.lua) Found: " .. str[1]) -- (1)
end
end
end
(1): どうも "Log%l%l%l* "
ではログファイルのローテートなども拾ってしまうらしく、不意に message
が nil
になる。
スケジュール
schedule at 1 startup * lua /lua/watch_login.lua
こんな感じで、起動時に実行されるように設定。
次回予告
CPUの使用率や筐体内温度を監視してみる。