-
Notifications
You must be signed in to change notification settings - Fork 0
/
UISP_AirMax_API.lua
141 lines (100 loc) · 3.83 KB
/
UISP_AirMax_API.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--[[
UNMS Proxy Monitor
Created by K. Rhodus
Version History:
1.0 - Initial Build
]]--
-----------------------------------------------------------------------------------------------------------------------------------------
-- Setup Script --
----------------------------------------------------------------------------------------------------------------------------------------
json = require("rapidjson")
UNMSdata = {}
devices = {}
tick = Timer.New()
tick.EventHandler = function()
UNMS()
end
--[[ Nevermind, Monitoring Proxies can't work without a status pin :(
Components = {}
--Find Monitoring Proxies
for _,ctl in pairs(Component.GetComponents()) do
for a,b in pairs(ctl) do
if a =="Type" then
if b=="monitoring_proxy" then
table.insert(Components,ctl.Name)
end
end
end
end
for _,ctl in ipairs(Controls.Proxy) do
ctl.Choices = Components
end
--]]
-----------------------------------------------------------------------------------------------------------------------------------------
-- Download from UNMS --
-----------------------------------------------------------------------------------------------------------------------------------------
--Multisync Status
function UNMSftn(tbl, code, data, err, headers)
if code == 200 then
tick:Start(30)
UNMSdata = json.decode(data)
--print(json.encode(UNMSdata, {pretty = true}))
devices = {} --Build devices table
for idx,ctl in ipairs(UNMSdata) do
table.insert(devices, ctl.identification.displayName)
end
table.sort(devices)
for idx,ctl in ipairs(Controls.Device) do
ctl.Choices = devices
end
update()
end
end
function UNMS()
local address = (Controls.IPAddress.String.. "/nms/api/v2.1/devices")
print("Downloading UNMS Data from: " .. address)
HttpClient.Download { Url = address, Headers = { ["Content-Type"] = "application/json" , ["x-auth-token"] = Controls.token.String} , Timeout = 30, EventHandler = UNMSftn }
end
UNMS()
-----------------------------------------------------------------------------------------------------------------------------------------
-- Update Devices --
-----------------------------------------------------------------------------------------------------------------------------------------
update = function()
for idx,ctl in ipairs(Controls.Device) do
for i,v in ipairs(UNMSdata) do
if v.identification.displayName == ctl.String then
if v.overview.status == "active" then
Controls.Status[idx].Value = 0
if type(v.overview.signal) == "function" then
Controls.Status[idx].String = ""
else
signal = tostring("Signal: "..v.overview.signal) .. " db"
if type(v.overview.uplinkCapacity) ~= "function" then
uplink = tostring("Up: "..math.floor(v.overview.uplinkCapacity * 0.000001).. "Mb")
else
uplink = ""
end
if type(v.overview.downlinkCapacity) ~= "function" then
downlink = tostring("Down: "..math.floor(v.overview.downlinkCapacity * 0.000001).. "Mb")
else
downlink = ""
end
Controls.Status[idx].String = signal.. " - "..uplink.." - "..downlink
end
else
Controls.Status[idx].Value = 6
end
break
end
end
end
end
-----------------------------------------------------------------------------------------------------------------------------------------
-- Associate Devices --
-----------------------------------------------------------------------------------------------------------------------------------------
for idx, ctl in ipairs(Controls.Device) do
ctl.EventHandler = function()
update()
end
end