[heartbeat] only send a heartbeat when enable_wan_branch is set

This commit is contained in:
Bart Van Der Meerssche 2011-04-27 21:20:42 +02:00
parent 0808d5db69
commit d08901f34e
1 changed files with 10 additions and 2 deletions

View File

@ -41,6 +41,9 @@ local httpclient = require 'luci.httpclient'
local FLUKSO = uci:get_all('flukso') local FLUKSO = uci:get_all('flukso')
-- WAN settings -- WAN settings
local WAN_ENABLED = true
if tonumber(FLUKSO.daemon.enable_wan_branch) == 0 then WAN_ENABLED = false end
local WAN_BASE_URL = FLUKSO.daemon.wan_base_url .. 'device/' local WAN_BASE_URL = FLUKSO.daemon.wan_base_url .. 'device/'
local WAN_KEY = '0123456789abcdef0123456789abcdef' local WAN_KEY = '0123456789abcdef0123456789abcdef'
uci:foreach('system', 'system', function(x) WAN_KEY = x.key end) -- quirky but it works uci:foreach('system', 'system', function(x) WAN_KEY = x.key end) -- quirky but it works
@ -69,6 +72,11 @@ function collect_mp()
return monitor return monitor
end end
-- terminate when WAN reporting is not set
if not WAN_ENABLED then
os.exit(2)
end
-- open the connection to the syslog deamon, specifying our identity -- open the connection to the syslog deamon, specifying our identity
nixio.openlog('heartbeat', 'pid') nixio.openlog('heartbeat', 'pid')
@ -121,7 +129,7 @@ else
end end
end end
os.exit(2) os.exit(3)
end end
-- verify the reply's digest -- verify the reply's digest
@ -129,7 +137,7 @@ hash = nixio.crypto.hmac('sha1', WAN_KEY)
hash:update(response_json) hash:update(response_json)
if call_info.headers['X-Digest'] ~= hash:final() then if call_info.headers['X-Digest'] ~= hash:final() then
nixio.syslog('err', 'Incorrect digest in the heartbeat reply. Discard response.') nixio.syslog('err', 'Incorrect digest in the heartbeat reply. Discard response.')
os.exit(3) os.exit(4)
end end
local response = luci.json.decode(response_json) local response = luci.json.decode(response_json)