summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2010-01-12 13:59:22 (GMT)
committerChristian Pointner <equinox@helsinki.at>2010-01-12 13:59:22 (GMT)
commit8385776d0e7998168f3f0b23a37aececcd5fd3c5 (patch)
tree4601798a3ef3dc57347c9feb8f6b6da975ccce09
parent09a4632f7ae58f11d73dcbbbb7e69b397a40b9f6 (diff)
moved from mode-leds to mode-watch
mode-watch sends email on change
-rw-r--r--luaclient.c1
-rw-r--r--mode-watch.lua (renamed from mode-leds.lua)52
-rw-r--r--openwrt/rhctl/Makefile4
-rw-r--r--openwrt/rhctl/files/rhctl.config6
4 files changed, 38 insertions, 25 deletions
diff --git a/luaclient.c b/luaclient.c
index 3861977..c721138 100644
--- a/luaclient.c
+++ b/luaclient.c
@@ -49,6 +49,7 @@ static const luaL_Reg anylike_lualibs[] = {
{LUA_TABLIBNAME, luaopen_table},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
+ {LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_LOGLIBNAME, luaopen_log},
{LUA_SIGNALLIBNAME, luaopen_signal},
diff --git a/mode-leds.lua b/mode-watch.lua
index 2c7e61c..26ef870 100644
--- a/mode-leds.lua
+++ b/mode-watch.lua
@@ -36,33 +36,45 @@ function clear_leds()
os.execute("/sbin/led.sh clear standby")
end
+function send_mail(address, subject, bodytext)
+ local fp = assert(io.popen("/usr/sbin/mini_sendmail -smailrelay -fnoreply@helsinki.at " .. address, "w"))
+
+ fp:write("Subject: " .. subject .. "\n")
+ fp:write("To: " .. address .. "\n")
+ fp:write("\n")
+ fp:write(bodytext)
+ fp:write("\n")
+ fp:close()
+end
+
+current_mode = "master"
+
function process_cmd(message)
log.printf(log.DEBUG, "received message: '%s'", message)
- local capture = string.match(message, "Current Mode: (%a+)")
- if(capture) then
- if(capture == "Master") then
- set_master_led()
- return 0
- else
- if(capture == "Standby") then
- set_standby_led()
- return 0
+ local new_mode = nil
+ local exps = { "Current Mode: (%a+)", "new Mode: (%a+)" }
+ for _, exp in ipairs(exps) do
+ new_mode = string.match(message, exp)
+ if(new_mode) then
+ new_mode = string.lower(new_mode)
+ if(new_mode == "master") then
+ set_master_led()
+ break
+ else
+ if(new_mode == "standby") then
+ set_standby_led()
+ break
+ end
end
end
end
- local capture = string.match(message, "new Mode: (%a+)")
- if(capture) then
- if(capture == "master") then
- set_master_led()
- return 0
- else
- if(capture == "standby") then
- set_standby_led()
- return 0
- end
- end
+ if(new_mode and new_mode ~= current_mode) then
+ log.printf(log.NOTICE, "mode is now " .. new_mode)
+ send_mail("logs@helsinki.at", "RHCTL mode changed to " .. new_mode,
+ "RHCTL just switched from " .. current_mode .. " to " .. new_mode)
+ current_mode = new_mode
end
return 0
diff --git a/openwrt/rhctl/Makefile b/openwrt/rhctl/Makefile
index 22bbbd6..1dce71d 100644
--- a/openwrt/rhctl/Makefile
+++ b/openwrt/rhctl/Makefile
@@ -18,7 +18,7 @@ PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://localhost/
-PKG_MD5SUM:=b746704c89869f23537d0d8e7d976357
+PKG_MD5SUM:=9a964f0045f4604056def35d6f1b5beb
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
@@ -31,7 +31,7 @@ define Package/rhctl
TITLE:=Radio Helsinki control tools
URL:=http://www.helsinki.at
MAINTAINER:=Christian Pointner <equinox@helsinki.at>
- DEPENDS:=+liblua +libuci-lua +udev +udevtrigger
+ DEPENDS:=+liblua +luasocket +udev +udevtrigger
endef
define Package/rhctl/conffiles
diff --git a/openwrt/rhctl/files/rhctl.config b/openwrt/rhctl/files/rhctl.config
index 7d3f06f..1ca5a58 100644
--- a/openwrt/rhctl/files/rhctl.config
+++ b/openwrt/rhctl/files/rhctl.config
@@ -35,7 +35,7 @@ config 'heartbeatclient'
config 'luaclient'
# option disabled 1
- option name 'mode-leds'
- option log 'syslog:3,luaclient-mode-leds,daemon'
+ option name 'mode-watch'
+ option log 'syslog:3,luaclient-mode-watch,daemon'
option command_sock '/var/run/rhctl/switchctl.sock'
- option lua_file '/usr/share/rhctl/mode-leds.lua'
+ option lua_file '/usr/share/rhctl/mode-watch.lua'