diff options
-rwxr-xr-x | apt-panopticon-report-DNS.lua | 150 | ||||
-rwxr-xr-x | apt-panopticon-report-web.lua | 90 | ||||
-rwxr-xr-x | apt-panopticon.lua | 1 |
3 files changed, 80 insertions, 161 deletions
diff --git a/apt-panopticon-report-DNS.lua b/apt-panopticon-report-DNS.lua deleted file mode 100755 index c571c3d..0000000 --- a/apt-panopticon-report-DNS.lua +++ /dev/null | |||
@@ -1,150 +0,0 @@ | |||
1 | #!/usr/bin/env luajit | ||
2 | |||
3 | local args = {...} | ||
4 | |||
5 | local logFile | ||
6 | |||
7 | |||
8 | --[[ Ordered table iterator, allow to iterate on the natural order of the keys of a table. | ||
9 | From http://lua-users.org/wiki/SortedIteration | ||
10 | ]] | ||
11 | function __genOrderedIndex( t ) | ||
12 | local orderedIndex = {} | ||
13 | for key in pairs(t) do | ||
14 | table.insert( orderedIndex, key ) | ||
15 | end | ||
16 | table.sort( orderedIndex ) | ||
17 | return orderedIndex | ||
18 | end | ||
19 | function orderedNext(t, state) | ||
20 | -- Equivalent of the next function, but returns the keys in the alphabetic | ||
21 | -- order. We use a temporary ordered key table that is stored in the | ||
22 | -- table being iterated. | ||
23 | |||
24 | local key = nil | ||
25 | --print("orderedNext: state = "..tostring(state) ) | ||
26 | if state == nil then | ||
27 | -- the first time, generate the index | ||
28 | t.__orderedIndex = __genOrderedIndex( t ) | ||
29 | key = t.__orderedIndex[1] | ||
30 | else | ||
31 | -- fetch the next value | ||
32 | for i = 1,table.getn(t.__orderedIndex) do | ||
33 | if t.__orderedIndex[i] == state then | ||
34 | key = t.__orderedIndex[i+1] | ||
35 | end | ||
36 | end | ||
37 | end | ||
38 | |||
39 | if key then | ||
40 | return key, t[key] | ||
41 | end | ||
42 | |||
43 | -- no more value to return, cleanup | ||
44 | t.__orderedIndex = nil | ||
45 | return | ||
46 | end | ||
47 | function orderedPairs(t) | ||
48 | -- Equivalent of the pairs() function on tables. Allows to iterate | ||
49 | -- in order | ||
50 | return orderedNext, t, nil | ||
51 | end | ||
52 | |||
53 | |||
54 | -- Use this to dump a table to a string. | ||
55 | dumpTable = function (table, space, name) | ||
56 | local r = "" | ||
57 | -- if "" == space then r = r .. space .. name .. " =\n" else r = r .. space .. "[" .. name .. "] =\n" end | ||
58 | if "" == space then r = r .. space .. name .. " \n" else r = r .. space .. name .. "\n" end | ||
59 | -- r = r .. space .. "{\n" | ||
60 | r = r .. dumpTableSub(table, space .. " ") | ||
61 | -- if "" == space then r = r .. space .. "}\n" else r = r .. space .. "},\n" end | ||
62 | if "" == space then r = r .. space .. "\n" end | ||
63 | return r | ||
64 | end | ||
65 | dumpTableSub = function (table, space) | ||
66 | local r = "" | ||
67 | -- for k, v in pairs(table) do | ||
68 | for k, v in orderedPairs(table) do | ||
69 | -- if type(k) == "string" then k = '"' .. k .. '"' end | ||
70 | if type(v) == "table" then | ||
71 | r = r .. dumpTable(v, space, k) | ||
72 | -- elseif type(v) == "string" then | ||
73 | -- r = r .. space .. "[" .. k .. "] = '" .. v .. "';\n" | ||
74 | -- elseif type(v) == "function" then | ||
75 | -- r = r .. space .. "[" .. k .. "] = function ();\n" | ||
76 | -- elseif type(v) == "userdata" then | ||
77 | -- r = r .. space .. "userdata " .. "[" .. k .. "];\n" | ||
78 | -- elseif type(v) == "boolean" then | ||
79 | -- if (v) then | ||
80 | -- r = r .. space .. "[" .. k .. "] = true;\n" | ||
81 | -- else | ||
82 | -- r = r .. space .. "[" .. k .. "] = false;\n" | ||
83 | -- end | ||
84 | else | ||
85 | -- r = r .. space .. "[" .. k .. "] = " .. v .. ";\n" | ||
86 | r = r .. space .. k .. "\n" | ||
87 | end | ||
88 | end | ||
89 | return r | ||
90 | end | ||
91 | |||
92 | local results = {} | ||
93 | |||
94 | local log = function(v, t, s, prot, test, host) | ||
95 | local x = "" | ||
96 | if nil == prot then prot = "" end | ||
97 | if nil ~= test then x = x .. test else test = "" end | ||
98 | if nil ~= host then | ||
99 | if #x > 0 then x = x .. " " end | ||
100 | x = x .. host | ||
101 | end | ||
102 | if #x > 0 then | ||
103 | t = t .. "(" .. x .. ")" | ||
104 | if "" == test then | ||
105 | if v == 0 then results[prot].errors = results[prot].errors + 1 end | ||
106 | if v == 1 then results[prot].warnings = results[prot].warnings + 1 end | ||
107 | else | ||
108 | if v == 0 then results[prot][test].errors = results[prot][test].errors + 1 end | ||
109 | if v == 1 then results[prot][test].warnings = results[prot][test].warnings + 1 end | ||
110 | end | ||
111 | end | ||
112 | if v <= verbosity then | ||
113 | if 3 <= verbosity then t = os.date() .. " " .. t end | ||
114 | print(t .. ": " .. s) | ||
115 | end | ||
116 | if nil ~= logFile then | ||
117 | logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") | ||
118 | logFile:flush() | ||
119 | end | ||
120 | end | ||
121 | local D = function(s) log(3, "DEBUG ", s) end | ||
122 | local I = function(s) log(2, "INFO ", s) end | ||
123 | local W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end | ||
124 | local E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end | ||
125 | local C = function(s) log(-1, "CRITICAL", s) end | ||
126 | |||
127 | local mirrors = loadfile("results/mirrors.lua")() | ||
128 | local m = {} | ||
129 | |||
130 | for k, v in pairs(mirrors) do | ||
131 | mirrors[k].Protocols = nil | ||
132 | mirrors[k].FQDN = nil | ||
133 | mirrors[k].Active = nil | ||
134 | mirrors[k].Rate = nil | ||
135 | mirrors[k].BaseURL = nil | ||
136 | mirrors[k].Country = nil | ||
137 | mirrors[k].Bandwidth = nil | ||
138 | m["\n" .. k .. " DNS entries -"] = mirrors[k].IPs | ||
139 | end | ||
140 | |||
141 | |||
142 | local file, e = io.open("results/Report-DNS.txt", "w+") | ||
143 | if nil == file then C("opening mirrors file - " .. e) else | ||
144 | file:write("This DNS report lists each mirror, and the DNS entries for that \nmirror. " .. | ||
145 | "If a mirror has a CNAME, that CNAME is listed along with that \nCNAMEs DNS entries. " .. | ||
146 | "deb.devuan.org is the DNS round robin, which points \nto the mirrors that are part of the DNS-RR. " .. | ||
147 | "pkgmaster.devuan.org is the \nmaster mirror, all the others sync to it. ") | ||
148 | file:write(dumpTable(m, "", "")) | ||
149 | file:close() | ||
150 | end | ||
diff --git a/apt-panopticon-report-web.lua b/apt-panopticon-report-web.lua index 163d50f..7bb48b0 100755 --- a/apt-panopticon-report-web.lua +++ b/apt-panopticon-report-web.lua | |||
@@ -51,6 +51,28 @@ function orderedPairs(t) | |||
51 | return orderedNext, t, nil | 51 | return orderedNext, t, nil |
52 | end | 52 | end |
53 | 53 | ||
54 | -- Use this to dump a table to a string, with HTML. | ||
55 | dumpTableHTML = function (table, space, name) | ||
56 | local r = name .. "\n" | ||
57 | r = r .. dumpTableHTMLSub(table, space .. " ") | ||
58 | r = r .. space .. "" | ||
59 | return r | ||
60 | end | ||
61 | dumpTableHTMLSub = function (table, space) | ||
62 | local r = "" | ||
63 | for k, v in orderedPairs(table) do | ||
64 | if type(v) == "table" then | ||
65 | if " " == space then | ||
66 | r = r .. space .. dumpTableHTML(v, space, k .. "<ul>") .. "</ul>\n" | ||
67 | else | ||
68 | r = r .. "<li>" .. space .. dumpTableHTML(v, space, k .. "<ul>") .. "</ul></li>\n" | ||
69 | end | ||
70 | else | ||
71 | r = r .. space .. "<li>" .. k .. "</li>\n" | ||
72 | end | ||
73 | end | ||
74 | return r | ||
75 | end | ||
54 | 76 | ||
55 | local results = {} | 77 | local results = {} |
56 | 78 | ||
@@ -114,9 +136,9 @@ local status = function(host, results, typ) | |||
114 | if 0 < w then | 136 | if 0 < w then |
115 | if 0 < e then result = result .. ", " end | 137 | if 0 < e then result = result .. ", " end |
116 | if 1 == w then | 138 | if 1 == w then |
117 | result = result .. w .. " <font color='blue'><b>warning</b></font>" | 139 | result = result .. w .. " <font color='yellow'><b>warning</b></font>" |
118 | else | 140 | else |
119 | result = result .. w .. " <font color='blue'><b>warnings</b></font>" | 141 | result = result .. w .. " <font color='yellow'><b>warnings</b></font>" |
120 | end | 142 | end |
121 | end | 143 | end |
122 | if "[OK]" ~= result then | 144 | if "[OK]" ~= result then |
@@ -164,15 +186,16 @@ local collate = function(host, ip, results) | |||
164 | end | 186 | end |
165 | 187 | ||
166 | local mirrors = loadfile("results/mirrors.lua")() | 188 | local mirrors = loadfile("results/mirrors.lua")() |
189 | local m = {} | ||
167 | 190 | ||
168 | local file, e = io.open("results/Report-web.html", "w+") | 191 | local file, e = io.open("results/Report-web.html", "w+") |
169 | if nil == file then C("opening mirrors file - " .. e) else | 192 | if nil == file then C("opening mirrors file - " .. e) else |
170 | file:write( "<html><head>\n" .. | 193 | file:write( "<html><head>\n" .. |
171 | '</head><body bgcolor="black" text="white" alink="red" link="blue" vlink="purple">' .. | 194 | '</head><body bgcolor="black" text="white" alink="red" link="blue" vlink="purple">' .. |
172 | "Check date: " .. os.date("!%a %b %d %T %Z %Y") .. "\n<br>\n") | 195 | "Check date: " .. os.date("!%a %b %d %T %Z %Y") .. "\n<br>\n<table>\n") |
173 | for k, v in orderedPairs(mirrors) do | 196 | for k, v in orderedPairs(mirrors) do |
174 | local results = loadfile("results/" .. k .. ".lua")() | 197 | local results = loadfile("results/" .. k .. ".lua")() |
175 | file:write(" " .. k .. ".... ") | 198 | file:write(" <tr><th>" .. k .. "</th> ") |
176 | local IPs = v.IPs | 199 | local IPs = v.IPs |
177 | for i, u in pairs(IPs) do | 200 | for i, u in pairs(IPs) do |
178 | if "table" == type(u) then | 201 | if "table" == type(u) then |
@@ -185,15 +208,62 @@ if nil == file then C("opening mirrors file - " .. e) else | |||
185 | end | 208 | end |
186 | local http = status(k, results, "http") | 209 | local http = status(k, results, "http") |
187 | local https = status(k, results, "https") | 210 | local https = status(k, results, "https") |
188 | local dns = "[<font color='yellow'><b>skip</b></font>]" | 211 | local dns = "[<font color='gray'><b>skip</b></font>]" |
189 | local protocol = status(k, results, "Protocol") | 212 | local protocol = status(k, results, "Protocol") |
190 | local sanity = "[<font color='yellow'><b>skip</b></font>]" | 213 | local sanity = "[<font color='gray'><b>skip</b></font>]" |
191 | local integrity = "[<font color='yellow'><b>skip</b></font>]" | 214 | local integrity = "[<font color='gray'><b>skip</b></font>]" |
192 | local updated = "[<font color='yellow'><b>skip</b></font>]" | 215 | local updated = "[<font color='gray'><b>skip</b></font>]" |
193 | file:write(" http: " .. http .. " https: " .. https .. " DNS-RR: " .. dns .. " Protocol: " .. protocol .. " URL-sanity: " .. sanity .. " Integrity: " .. integrity .. " Updated: " .. updated .. "\n<br>\n") | 216 | file:write("<td>http: " .. http .. "</td><td>https: " .. https .. "</td><td>DNS-RR: " .. |
217 | dns .. "</td><td>Protocol: " .. protocol .. "</td><td>URL-sanity: " .. sanity .. | ||
218 | "</td><td>Integrity: " .. integrity .. "</td><td>Updated: " .. updated .. "</td></tr>\n") | ||
194 | end | 219 | end |
195 | file:write( "==== faulty mirrors: ====<br>\n<br>\n" .. faulty) | 220 | file:write( "</table>\n==== faulty mirrors: ====<br>\n<br>\n" .. faulty) |
196 | file:write( "\n<br>\nLast Failure: NOT WRITTEN YET<br>\n<br>") | 221 | file:write( "\n<br>\nLast Failure: NOT WRITTEN YET<br>\n<br>") |
222 | |||
223 | for k, v in pairs(mirrors) do | ||
224 | local n = {} | ||
225 | mirrors[k].Protocols = nil | ||
226 | mirrors[k].FQDN = nil | ||
227 | mirrors[k].Active = nil | ||
228 | mirrors[k].Rate = nil | ||
229 | mirrors[k].BaseURL = nil | ||
230 | mirrors[k].Country = nil | ||
231 | mirrors[k].Bandwidth = nil | ||
232 | for l, w in pairs(mirrors[k].IPs) do | ||
233 | if type(w) == "table" then | ||
234 | n[l] = {} | ||
235 | for i, u in pairs(w) do | ||
236 | local nm = "LOG_" .. k .. "_" .. i .. ".html" | ||
237 | local rfile, e = io.open("results/" .. nm, "r") | ||
238 | if nil ~= rfile then | ||
239 | rfile:close() | ||
240 | n[l]["<a href='" .. nm .. "'>" .. i .. "</a>"] = u | ||
241 | else | ||
242 | n[l][i] = u | ||
243 | end | ||
244 | end | ||
245 | else | ||
246 | local nm = "LOG_" .. k .. "_" .. l .. ".html" | ||
247 | local rfile, e = io.open("results/" .. nm, "r") | ||
248 | if nil ~= rfile then | ||
249 | rfile:close() | ||
250 | n["<a href='" .. nm .. "'>" .. l .. "</a>"] = w | ||
251 | else | ||
252 | n[l] = w | ||
253 | end | ||
254 | end | ||
255 | end | ||
256 | m[k .. " DNS entries -"] = n | ||
257 | end | ||
258 | file:write("<br>\n<br>\n<br>\n" .. | ||
259 | "<p>This DNS report lists each mirror, and the DNS entries for that mirror. " .. | ||
260 | "If a mirror has a CNAME, that CNAME is listed along with that CNAMEs DNS entries. " .. | ||
261 | "deb.devuan.org is the DNS round robin, which points to the mirrors that are part of the DNS-RR. " .. | ||
262 | "pkgmaster.devuan.org is the master mirror, all the others sync to it. " .. | ||
263 | "The links point to the log files for each FDQN / IP combination that was checked. " .. | ||
264 | "</p>\n<br><br>" | ||
265 | ) | ||
266 | file:write(dumpTableHTML(m, "", "")) | ||
197 | file:write( "\n<br>\n\n</body></html>\n") | 267 | file:write( "\n<br>\n\n</body></html>\n") |
198 | file:close() | 268 | file:close() |
199 | end | 269 | end |
diff --git a/apt-panopticon.lua b/apt-panopticon.lua index a8796c9..6b49398 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua | |||
@@ -54,7 +54,6 @@ options = | |||
54 | help = "", | 54 | help = "", |
55 | value = | 55 | value = |
56 | { | 56 | { |
57 | "DNS", | ||
58 | "email", | 57 | "email", |
59 | -- "Nagios", | 58 | -- "Nagios", |
60 | -- "Prometheus", | 59 | -- "Prometheus", |