Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated framework #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions modules/framework.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ local factory = function (class)
end
end

framework.version = '0.10.0'
framework.version = '0.11.0'
framework.boundary = boundary
framework.params = boundary.param or json.parse(fs.readFileSync('param.json')) or {}
framework.plugin_params = boundary.plugin or json.parse(fs.readFileSync('plugin.json')) or {}
Expand Down Expand Up @@ -96,7 +96,7 @@ Logger.ERROR = 40
Logger.WARNING = 30
Logger.INFO = 20
Logger.DEBUG = 10
Logger.NOTSET = 0
Logger.NOTSET = 60

Logger.level_map = {
critical = Logger.CRITICAL,
Expand All @@ -123,13 +123,17 @@ function Logger:initialize(stream, level)
end

function Logger:isEnabledFor(level)
return level <= self.level
return level >= self.level
end

function Logger:setLevel(level)
self.level = level or Logger.NOTSET
end

function Logger:getLevel()
return self.level
end

function Logger:dump(args)
return args and utils.dump(args, nil, true) or ''
end
Expand Down Expand Up @@ -1207,12 +1211,17 @@ end

function DataSourcePoller:_poll(callback)
local success, err = pcall(function ()
self.dataSource:fetch(self, callback)
self.dataSource:fetch(self, function(...)
-- capture the fetch result and then schedule the next poll.
-- This eliminates the possibility of getting called before finishing
callback(...)
timer.setTimeout(self.pollInterval, function () self:_poll(callback) end)
end)
end)
if not success then
self:emit('error', err)
timer.setTimeout(self.pollInterval, function () self:_poll(callback) end)
end
timer.setTimeout(self.pollInterval, function () self:_poll(callback) end)
end

--- Start polling for data.
Expand Down Expand Up @@ -1291,11 +1300,23 @@ function Plugin:printCritical(title, host, source, msg)
end

function Plugin.formatMessage(name, version, title, host, source, msg)
if title and title ~= "" then title = '-'..title else title = "" end
local ver = '';
local nm ='';
if name and name ~= "" then
nm = name;
end
if version and version ~= "" then
ver = ' version '..version
end
if (nm == '' and ver == '') then
if title and title ~= "" then title = title else title = "" end
else
if title and title ~= "" then title = '-'..title else title = "" end
end
if msg and msg ~= "" then msg = '|m:'..msg else msg = "" end
if host and host ~= "" then host = '|h:'..host else host = "" end
if source and source ~= "" then source = '|s:'..source else source = "" end
return string.format('%s version %s%s%s%s%s', name, version, title, msg, host, source)
return string.format('%s%s%s%s%s%s', nm, ver, title, msg, host, source)
end

function Plugin.formatTags(tags)
Expand Down Expand Up @@ -1802,7 +1823,7 @@ function FileReaderDataSource:fetch(context, func, params)
self:emit('error', 'The "' .. self.path .. '" was not found.')
else
local success, result = pcall(fs.readFileSync, self.path)
if not success then
if not success then
self:emit('error', failure)
else
func(result)
Expand All @@ -1819,4 +1840,3 @@ framework.PollerCollection = PollerCollection
framework.MeterDataSource = MeterDataSource

return framework

2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.9.0",
"version": "0.9.1",
"tags": "TCP RTT",
"meterVersionRequired": "4.5.1",
"description": "Displays TCP round trip time on a source",
Expand Down