-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-- Use of this source code is governed by the Apache 2.0 license; see COPYING. | ||
|
||
module(..., package.seeall) | ||
|
||
local shm = require("core.shm") | ||
local ifmib = require("lib.ipc.shmem.iftable_mib") | ||
|
||
local ifmib_dir = '/ifmib' | ||
|
||
local function create_ifmib(stats, ifname, ifalias, log_date) | ||
-- stats can be nil in case this process is not the master | ||
-- of the device | ||
if not stats then return end | ||
if not shm.exists(ifmib_dir) then | ||
shm.mkdir(ifmib_dir) | ||
end | ||
ifmib.init_snmp( { ifDescr = ifname, | ||
ifName = ifname, | ||
ifAlias = ifalias or "NetFlow input", }, | ||
ifname:gsub('/', '-'), stats, | ||
shm.root..ifmib_dir, 5, log_date) | ||
end | ||
|
||
MIB = { | ||
config = { | ||
target_app = {required=true}, | ||
ifname = {required=true}, | ||
ifalias = {default="NetFlow input"}, | ||
log_date = {default=false}, | ||
stats = {default='shm'} | ||
} | ||
} | ||
|
||
function MIB:new (conf) | ||
local self = { | ||
initialized = false, | ||
conf = conf | ||
} | ||
return setmetatable(self, {__index=MIB}) | ||
end | ||
|
||
function MIB:tick () | ||
if self.initialized then | ||
return | ||
end | ||
|
||
local target_app = engine.app_table[self.conf.target_app] | ||
local stats = target_app and target_app[self.conf.stats] | ||
create_ifmib(stats, self.conf.ifname, self.conf.ifalias, self.conf.log_date) | ||
self.initialized = true | ||
end |