Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinit.lua
More file actions
Latest commit
86 lines (67 loc) · 2.57 KB
/
Copy pathinit.lua
File metadata and controls
86 lines (67 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
localframework=require('framework')
localCommandOutputDataSource=framework.CommandOutputDataSource
localPollerCollection=framework.PollerCollection
localDataSourcePoller=framework.DataSourcePoller
localPlugin=framework.Plugin
localos=require('os')
localtable=require('table')
localstring=require('string')
localisEmpty=framework.string.isEmpty
localclone=framework.table.clone
localparams=framework.params
localcommands= {
linux= { path='/bin/ping', args= {'-n', '-w 2', '-c 1'} },
win32= { path='C:/windows/system32/ping.exe', args= {'-n', '1', '-w', '3000'} },
darwin= { path='/sbin/ping', args= {'-n', '-t 2', '-c 1'} }
}
localping_command=commands[string.lower(os.type())]
ifping_command==nilthen
print("_bevent:"..(Plugin.nameorparams.name)..":"..(Plugin.versionorparams.version)..":Your platform is not supported. We currently support Linux, Windows and OSX|t:error|tags:lua,plugin"..(Plugin.tagsandframework.string.concat(Plugin.tags, ',') orparams.tags))
process:exit(-1)
end
localfunctioncreatePollers (params, cmd)
localpollers=PollerCollection:new()
for_, iteminipairs(params.items) do
cmd=clone(cmd)
table.insert(cmd.args, item.host)
cmd.info=item.source
localdata_source=CommandOutputDataSource:new(cmd)
localpoll_interval=tonumber(item.pollIntervalorparams.pollInterval) *1000
localpoller=DataSourcePoller:new(poll_interval, data_source)
pollers:add(poller)
end
returnpollers
end
localfunctionparseOutput(context, output)
assert(output~=nil, 'parseOutput expect some data')
ifisEmpty(output) then
context:emit('error', 'Unable to obtain any output.')
return
end
if (string.find(output, "unknown host") orstring.find(output, "could not find host.")) then
context:emit('error', 'The host ' ..context.args[#context.args] ..' was not found.')
return
end
localindex
localprevIndex=0
whiletruedo
index=string.find(output, '\n', prevIndex+1)
ifnotindexthenbreakend
localline=string.sub(output, prevIndex, index-1)
local_, _, time=string.find(line, "time=([0-9]*%.?[0-9]+)")
iftimethen
returntonumber(time)
end
prevIndex=index
end
return-1
end
localpollers=createPollers(params, ping_command)
localplugin=Plugin:new(params, pollers)
functionplugin:onParseValues(data)
localresult= {}
localvalue=parseOutput(self, data['output'])
result['PING_RESPONSETIME'] = { value=value, source=data['info'] }
returnresult
end
plugin:run()