forked from thirty8super/win_service_test
-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.lua
72 lines (61 loc) · 2.18 KB
/
init.lua
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
local os = require('os')
local io = require('io')
local json = require('json')
local timer = require('timer')
--
-- Read and parse the plugin file.
--
plugin_file = io.open('plugin.json', 'r')
plugin_json = plugin_file:read("*all")
plugin_info = json.parse(plugin_json)
plugin_file:close()
--
-- Read the parameter file. It will contain an array of items which define
-- the counter metrics to collect.
--
param_file = io.open('param.json', 'r')
params_json = param_file:read("*all")
params = json.parse(params_json)
param_file:close()
--
-- Loop through each metric and store the parameters. Currently supported are
-- counter= The counter path
-- factor= The multiplication factor for the counter value.
--
local services = {}
for _,item in pairs(params.items) do
services[item.service] = {auto_restart = item.auto_restart, event_on_state_change = item.event_on_state_change, event_on_restart = item.event_on_restart}
end
--
-- Create the .ini file that the meter will parse.
-- The filename needs to be plugin_services.ini
-- Creating the .ini file is the purpose of the plugin.
-- What ever after this is to make sure that the plugin does not exit.
--
file = io.open("plugin_services.ini", "w")
-- To facillitate setup, we just use a default 5 sec interval timer.
file:write("interval_sec=5\n")
for k, v in pairs(services) do
file:write("[".. k .. "]\n")
if (v.auto_restart ~= nil) then
file:write(" auto_restart=".. tostring(v.auto_restart).."\n")
end
if (v.event_on_state_change ~= nil) then
file:write(" event_on_state_change=".. tostring(v.event_on_state_change).."\n")
end
if (v.event_on_restart ~= nil) then
file:write(" event_on_restart=".. tostring(v.event_on_restart).."\n")
end
end
file:close()
--Plugin start event.
print ("_bevent:"..plugin_info.name.." version " .. plugin_info.version .. " Started|t:info")
--Dummy function to be called after every polling interval.
--
function dummy()
--Do Nothing.
end
--Setting the polling interval. This will make sure that the dummy function is called after the specified
--interval is expired. This is to make sure that the plugin does not exit. If the plugin exits
--the meter will restart the plugin.
timer.setInterval(300000, dummy)