Created
August 11, 2015 23:45
-
-
Save mochipon/92cb3a9dfaf6e9a45968 to your computer and use it in GitHub Desktop.
YAMAHA ルータで NAT テーブルと DHCP サーバのプールの使用状況を syslog に吐き出すヤツ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------## 設定値 ##-------------------------------- | |
-- 監視間隔(1 - 864000 秒) | |
idle_time = 30 | |
-- 使用状況を監視する IP マスカレードの NAT ディスクリプタ番号(1 - 2147483647) | |
nat_descriptor = 1000 | |
-- メールの送信に失敗した時に出力する SYSLOG のレベル(info, debug, notice) | |
log_level = "info" | |
----------------------## 設定値ここまで ##---------------------------- | |
------------------------------------------------------------ | |
-- IP マスカレードの使用ポート数を返す関数 -- | |
------------------------------------------------------------ | |
function natmsq_use_status(id) | |
local rtn, str, num | |
local cmd = "show nat descriptor address " .. tostring(id) | |
local ptn = "(%d+) used." | |
rtn, str = rt.command(cmd) | |
if (rtn) and (str) then | |
num = str:match(ptn) | |
if (num) then | |
num = tonumber(num) | |
end | |
else | |
str = cmd .. " -> failed to execute\r\n" | |
end | |
return rtn, num | |
end | |
------------------------------------------------------------ | |
-- DHCP サーバのリース数を返す関数 -- | |
------------------------------------------------------------ | |
function dhcp_use_status() | |
local rtn, str, num | |
local cmd = "show status dhcp" | |
local ptn = "Leased: (%d+)" | |
rtn, str = rt.command(cmd) | |
if (rtn) and (str) then | |
num = str:match(ptn) | |
if (num) then | |
num = tonumber(num) | |
end | |
else | |
str = cmd .. " -> failed to execute\r\n" | |
end | |
return rtn, num | |
end | |
------------------------------------------------------------ | |
-- メインルーチン -- | |
------------------------------------------------------------ | |
local rtn, nat_use, dhcp_use | |
while (true) do | |
rtn, nat_use = natmsq_use_status(nat_descriptor) | |
if (rtn) then | |
if (nat_use) then | |
rt.syslog(log_level, string.format("nat descriptor used: %d", nat_use)) | |
end | |
end | |
rtn, dhcp_use = dhcp_use_status() | |
if (rtn) then | |
if (dhcp_use) then | |
rt.syslog(log_level, string.format("dhcp leased: %d", dhcp_use)) | |
end | |
end | |
rt.sleep(idle_time) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment