diff options
author | onefang | 2019-12-02 06:28:30 +1000 |
---|---|---|
committer | onefang | 2019-12-02 06:28:30 +1000 |
commit | 3829c9b7962f11e760361deb764fc96af1345c62 (patch) | |
tree | 5d3dde39d99934cc5a21ca7f60f096603d048e19 | |
parent | Add more report stuff. (diff) | |
download | apt-panopticon-3829c9b7962f11e760361deb764fc96af1345c62.zip apt-panopticon-3829c9b7962f11e760361deb764fc96af1345c62.tar.gz apt-panopticon-3829c9b7962f11e760361deb764fc96af1345c62.tar.bz2 apt-panopticon-3829c9b7962f11e760361deb764fc96af1345c62.tar.xz |
Merge email and web report scripts.
-rwxr-xr-x | apt-panopticon-report-email-web.lua (renamed from apt-panopticon-report-web.lua) | 193 | ||||
-rwxr-xr-x | apt-panopticon-report-email.lua | 292 | ||||
-rwxr-xr-x | apt-panopticon.lua | 3 |
3 files changed, 157 insertions, 331 deletions
diff --git a/apt-panopticon-report-web.lua b/apt-panopticon-report-email-web.lua index fb41341..60027d0 100755 --- a/apt-panopticon-report-web.lua +++ b/apt-panopticon-report-email-web.lua | |||
@@ -4,6 +4,7 @@ local args = {...} | |||
4 | 4 | ||
5 | verbosity = -1 | 5 | verbosity = -1 |
6 | local logFile | 6 | local logFile |
7 | local html = false | ||
7 | 8 | ||
8 | 9 | ||
9 | --[[ Ordered table iterator, allow to iterate on the natural order of the keys of a table. | 10 | --[[ Ordered table iterator, allow to iterate on the natural order of the keys of a table. |
@@ -77,17 +78,21 @@ end | |||
77 | local plurals = function(e, w) | 78 | local plurals = function(e, w) |
78 | local result = "" | 79 | local result = "" |
79 | if 1 == e then | 80 | if 1 == e then |
80 | result = e .. " <font color='red'><b>error</b></font>" | 81 | result = e .. " error" |
81 | elseif e ~= 0 then | 82 | elseif e ~= 0 then |
82 | result = e .. " <font color='red'><b>errors</b></font>" | 83 | result = e .. " errors" |
83 | end | 84 | end |
85 | if ("" ~= result) and html then result = "<font color='red'><b>" .. result .. "</b></font>" end | ||
86 | -- result = " " .. result | ||
84 | if 0 < w then | 87 | if 0 < w then |
85 | if 0 < e then result = result .. ", " end | 88 | if 0 < e then result = result .. ", " end |
86 | if 1 == w then | 89 | if 1 == w then |
87 | result = result .. w .. " <font color='yellow'><b>warning</b></font>" | 90 | result = result .. w .. " warning" |
88 | else | 91 | else |
89 | result = result .. w .. " <font color='yellow'><b>warnings</b></font>" | 92 | result = result .. w .. " warnings" |
90 | end | 93 | end |
94 | if ("" ~= result) and html then result = "<font color='yellow'><b>" .. result .. "</b></font>" end | ||
95 | -- result = " " .. result | ||
91 | end | 96 | end |
92 | if "" ~= result then result = " (" .. result .. ")" end | 97 | if "" ~= result then result = " (" .. result .. ")" end |
93 | return result | 98 | return result |
@@ -127,7 +132,11 @@ local revDNS = function(dom, IP) | |||
127 | if "deb.devuan.org" ~= dom then | 132 | if "deb.devuan.org" ~= dom then |
128 | if nil ~= mirrors["deb.devuan.org"] then | 133 | if nil ~= mirrors["deb.devuan.org"] then |
129 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][IP] then | 134 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][IP] then |
130 | return "<font color='purple'><b>DNS-RR</b></font>" | 135 | if html then |
136 | return "<font color='purple'><b>DNS-RR</b></font>" | ||
137 | else | ||
138 | return "DNS-RR" | ||
139 | end | ||
131 | end | 140 | end |
132 | end | 141 | end |
133 | else | 142 | else |
@@ -184,26 +193,42 @@ local status = function(host, results, typ) | |||
184 | end | 193 | end |
185 | 194 | ||
186 | if to then | 195 | if to then |
187 | if s then | 196 | result = "[TIMEOUT" |
188 | result = "[<font color='blue'><b>TIMEOUT</b></font>]" | 197 | if not s then result = result .. "*" end |
189 | else | 198 | if html then |
190 | result = "[<font color='darkblue'><b>TIMEOUT *</b></font>]" | 199 | if s then |
200 | result = "[<font color='blue'><b>TIMEOUT</b></font>" | ||
201 | else | ||
202 | result = "[<font color='darkblue'><b>TIMEOUT*</b></font>" | ||
203 | end | ||
191 | end | 204 | end |
192 | elseif 0 < e then | 205 | elseif 0 < e then |
193 | if s then | 206 | result = "[FAILED" |
194 | result = "[<font color='red'><b>FAILED</b></font>]" | 207 | if not s then result = result .. "*" end |
208 | if html then | ||
209 | if s then | ||
210 | result = "[<font color='red'><b>FAILED</b></font>" | ||
211 | else | ||
212 | result = "[<font color='darkred'><b>FAILED*</b></font>" | ||
213 | end | ||
214 | end | ||
215 | if html then | ||
216 | faulty = faulty .. host .. " (" .. typ .. ")<br>\n" | ||
195 | else | 217 | else |
196 | result = "[<font color='darkred'><b>FAILED *</b></font>]" | 218 | faulty = faulty .. host .. " (" .. typ .. ")\n" |
197 | end | 219 | end |
198 | faulty = faulty .. host .. " (" .. typ .. ")<br>\n" | ||
199 | else | 220 | else |
200 | if s then | 221 | result = "[OK" |
201 | result = "[<font color='lime'><b>OK</b></font>]" | 222 | if not s then result = result .. "*" end |
202 | else | 223 | if html then |
203 | result = "[<font color='darkgreen'><b>OK *</b></font>]" | 224 | if s then |
225 | result = "[<font color='lime'><b>OK</b></font>" | ||
226 | else | ||
227 | result = "[<font color='darkgreen'><b>OK*</b></font>" | ||
228 | end | ||
204 | end | 229 | end |
205 | end | 230 | end |
206 | return result .. plurals(e, w) | 231 | return result .. plurals(e, w) .. "]" |
207 | end | 232 | end |
208 | 233 | ||
209 | local collate = function(host, ip, results) | 234 | local collate = function(host, ip, results) |
@@ -254,19 +279,113 @@ local logCount = function(domain, ip) | |||
254 | if nil ~= l:match("><b>WARNING ") then warnings = warnings + 1 end | 279 | if nil ~= l:match("><b>WARNING ") then warnings = warnings + 1 end |
255 | end | 280 | end |
256 | rfile:close() | 281 | rfile:close() |
257 | if nil == ip then | 282 | if html then |
258 | log = "<a href='" .. nm .. "'>" .. domain .. "</a>" | 283 | if nil == ip then |
259 | else | 284 | log = "<a href='" .. nm .. "'>" .. domain .. "</a>" |
260 | log = "<a href='" .. nm .. "'>" .. ip .. "</a>" | 285 | else |
286 | log = "<a href='" .. nm .. "'>" .. ip .. "</a>" | ||
287 | end | ||
261 | end | 288 | end |
262 | log = log .. plurals(errors, warnings) | 289 | log = log .. plurals(errors, warnings) |
263 | end | 290 | end |
264 | return log | 291 | return log |
265 | end | 292 | end |
266 | 293 | ||
267 | local file, e = io.open("results/Report-web.html", "w+") | 294 | |
268 | if nil == file then C("opening mirrors file - " .. e) else | 295 | html = false |
269 | file:write( "<html><head><title>apt-panopticon results</title>\n" .. | 296 | local email, e = io.open("results/Report-email.txt", "w+") |
297 | if nil == email then C("opening mirrors file - " .. e) else | ||
298 | email:write( "Dear Mirror Admins,\n\n" .. | ||
299 | "This is the status of the mirror servers in the Devuan package mirror network.\n\n" .. | ||
300 | "The full list of Devuan package mirrors is available at the URL:\n\n" .. | ||
301 | " https://pkgmaster.devuan.org/mirror_list.txt\n\n" .. | ||
302 | 'Please contact "mirrors@devuan.org" if any of the information \nin the file above needs to be amended. \n\n' .. | ||
303 | "The full results of the mirror checking is available at the URL:\n\n" .. | ||
304 | " https://sledjhamr.org/apt-panopticon/results/Report-web.html\n\n" .. | ||
305 | "Due to the nature of the tests, some errors or warnings will be \ncounted several times. " .. | ||
306 | "Refer to the logs on the web page for details.\n\n" .. | ||
307 | "Please see below the current status of the Devuan Package Mirror \nnetwork:\n\n" .. | ||
308 | "==== package mirror status " .. os.date("!%Y-%m-%d %H:%M") .. " GMT ====\n" .. | ||
309 | "[skip] means that the test hasn't been written yet.\n\n") | ||
310 | for k, v in orderedPairs(mirrors) do | ||
311 | local results = loadfile("results/" .. k .. ".lua")() | ||
312 | email:write(k .. "....\n") | ||
313 | local IPs = v.IPs | ||
314 | for i, u in pairs(IPs) do | ||
315 | if "table" == type(u) then | ||
316 | for h, t in pairs(u) do | ||
317 | results = collate(k, h, results) | ||
318 | end | ||
319 | else | ||
320 | results = collate(k, i, results) | ||
321 | end | ||
322 | end | ||
323 | local ftp = "[skip]" | ||
324 | local http = status(k, results, "http") | ||
325 | local https = status(k, results, "https") | ||
326 | local rsync = "[skip]" | ||
327 | local dns = "" | ||
328 | local protocol = status(k, results, "Protocol") | ||
329 | local sanity = "[skip]" | ||
330 | local integrity = status(k, results, "Integrity") | ||
331 | local updated = status(k, results, "Updated") | ||
332 | |||
333 | -- DNS-RR test. | ||
334 | if ("deb.devuan.org" ~= k) and (nil ~= mirrors["deb.devuan.org"]) then | ||
335 | for l, w in pairs(mirrors[k].IPs) do | ||
336 | if type(w) == "table" then | ||
337 | for i, u in pairs(w) do | ||
338 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then | ||
339 | local log = logCount("deb.devuan.org", i) | ||
340 | if "" ~= log then | ||
341 | if "" == dns then dns = " " else dns = dns .. " " end | ||
342 | dns = dns .. logCount("deb.devuan.org", i) | ||
343 | else | ||
344 | if "" == dns then dns = " " else dns = dns .. " " end | ||
345 | dns = dns .. i | ||
346 | end | ||
347 | end | ||
348 | end | ||
349 | else | ||
350 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][l] then | ||
351 | local log = logCount("deb.devuan.org", l) | ||
352 | if "" ~= log then | ||
353 | if "" == dns then dns = " " else dns = dns .. " " end | ||
354 | dns = dns .. log | ||
355 | else | ||
356 | if "" == dns then dns = " " else dns = dns .. " " end | ||
357 | dns = dns .. l | ||
358 | end | ||
359 | end | ||
360 | end | ||
361 | end | ||
362 | if "" == dns then dns = "[no]" end | ||
363 | dns = " DNS-RR: " .. dns | ||
364 | end | ||
365 | |||
366 | email:write( " ftp: " .. ftp .. " http: " .. http .. " https: " .. https .." rsync: " .. rsync .. "\n" .. | ||
367 | " " .. dns .. "\n" .. | ||
368 | " Protocol: " .. protocol .. " URL-sanity: " .. sanity .. " Integrity: " .. integrity .. "\n" .. | ||
369 | " Updated: " .. updated .. "\n") | ||
370 | end | ||
371 | email:write( "\n==== faulty mirrors: ====\n" .. faulty) | ||
372 | email:write( "\n-------------------------\n\n" .. | ||
373 | "* This means that this protocol isn't actually supported, but the test was run ayway.\n\n" .. | ||
374 | "Thanks for your precious help in ensuring that Devuan GNU+Linux \nremains a universal, stable, dependable, free operating system.\n\n" .. | ||
375 | "You can get the source code from https://sledjhamr.org/cgit/apt-panopticon/about/ .\n\n" .. | ||
376 | "Love\n\n" .. | ||
377 | "The Dev1Devs\n\n") | ||
378 | email:close() | ||
379 | end | ||
380 | |||
381 | |||
382 | results = {} | ||
383 | m = {} | ||
384 | faulty = "" | ||
385 | html = true | ||
386 | local web, e = io.open("results/Report-web.html", "w+") | ||
387 | if nil == web then C("opening mirrors file - " .. e) else | ||
388 | web:write( "<html><head><title>apt-panopticon results</title>\n" .. | ||
270 | '</head><body bgcolor="black" text="white">' .. | 389 | '</head><body bgcolor="black" text="white">' .. |
271 | "<h1>Welcome to the apt-panopticon results page.</h1>\n" .. | 390 | "<h1>Welcome to the apt-panopticon results page.</h1>\n" .. |
272 | "<p>This is the status of the mirror servers in the Devuan package mirror network.</p>\n" .. | 391 | "<p>This is the status of the mirror servers in the Devuan package mirror network.</p>\n" .. |
@@ -274,11 +393,11 @@ if nil == file then C("opening mirrors file - " .. e) else | |||
274 | "<a href='https://pkgmaster.devuan.org/mirror_list.txt'>https://pkgmaster.devuan.org/mirror_list.txt</a></p>\n" .. | 393 | "<a href='https://pkgmaster.devuan.org/mirror_list.txt'>https://pkgmaster.devuan.org/mirror_list.txt</a></p>\n" .. |
275 | "<p>Due to the nature of the tests, some errors or warnings will be counted several times. " .. | 394 | "<p>Due to the nature of the tests, some errors or warnings will be counted several times. " .. |
276 | "The links in the table and DNS list go to the detailed testing logs.</p>\n\n" .. | 395 | "The links in the table and DNS list go to the detailed testing logs.</p>\n\n" .. |
277 | "<hr>\n<h2>==== package mirror status " .. os.date("!%Y-%m-%d %H:%M") .. " GMT: ====</h2>\n<table>\n" .. | 396 | "<hr>\n<h2>==== package mirror status " .. os.date("!%Y-%m-%d %H:%M") .. " GMT ====</h2>\n<table>\n" .. |
278 | 397 | ||
279 | "<p>[<font color='red'><b>FAILED</b></font>] or [<font color='lime'><b>OK</b></font>]" .. | 398 | "<p>[<font color='red'><b>FAILED</b></font>] or [<font color='lime'><b>OK</b></font>]" .. |
280 | " means the tested thing is supported for that mirror.</p>\n" .. | 399 | " means the tested thing is supported for that mirror.</p>\n" .. |
281 | "<p>[<font color='darkred'><b>FAILED *</b></font>] or [<font color='darkgreen'><b>OK *</b></font>]" .. | 400 | "<p>[<font color='darkred'><b>FAILED*</b></font>] or [<font color='darkgreen'><b>OK*</b></font>]" .. |
282 | " means the tested thing is unsupported for that mirror, but might have been tested anyway.</p>\n" .. | 401 | " means the tested thing is unsupported for that mirror, but might have been tested anyway.</p>\n" .. |
283 | "<p>[<font color='blue'><b>TIMEOUT</b></font>] or [<font color='darkblue'><b>TIMEOUT</b></font>]" .. | 402 | "<p>[<font color='blue'><b>TIMEOUT</b></font>] or [<font color='darkblue'><b>TIMEOUT</b></font>]" .. |
284 | " means the server had too many timeouts, and tests where aborted, so there is no result for this test.</p>" .. | 403 | " means the server had too many timeouts, and tests where aborted, so there is no result for this test.</p>" .. |
@@ -294,10 +413,10 @@ if nil == file then C("opening mirrors file - " .. e) else | |||
294 | local results = loadfile("results/" .. k .. ".lua")() | 413 | local results = loadfile("results/" .. k .. ".lua")() |
295 | local active = "" | 414 | local active = "" |
296 | if "yes" == v.Active then | 415 | if "yes" == v.Active then |
297 | file:write(" <tr><th>" .. k .. "</th> ") | 416 | web:write(" <tr><th>" .. k .. "</th> ") |
298 | else | 417 | else |
299 | if nil == v.Active then active = 'nil' else active = v.Active end | 418 | if nil == v.Active then active = 'nil' else active = v.Active end |
300 | file:write(" <tr style='background-color:dimgrey'><th>" .. k .. "</th> ") | 419 | web:write(" <tr style='background-color:dimgrey'><th>" .. k .. "</th> ") |
301 | end | 420 | end |
302 | local IPs = v.IPs | 421 | local IPs = v.IPs |
303 | for i, u in pairs(IPs) do | 422 | for i, u in pairs(IPs) do |
@@ -353,15 +472,15 @@ if nil == file then C("opening mirrors file - " .. e) else | |||
353 | if "" == dns then dns = "[<font color='grey'><b>no</b></font>]" end | 472 | if "" == dns then dns = "[<font color='grey'><b>no</b></font>]" end |
354 | end | 473 | end |
355 | 474 | ||
356 | file:write("<td>" .. ftp .. " </td><td>" .. http .. " </td><td>" .. https .. " </td><td>" .. rsync .. " </td><td>" .. dns .. | 475 | web:write("<td>" .. ftp .. " </td><td>" .. http .. " </td><td>" .. https .. " </td><td>" .. rsync .. " </td><td>" .. dns .. |
357 | " </td><td>" .. protocol .. " </td><td>" .. sanity .. | 476 | " </td><td>" .. protocol .. " </td><td>" .. sanity .. |
358 | " </td><td>" .. integrity .. " </td><td>" .. updated .. "</td></tr>\n") | 477 | " </td><td>" .. integrity .. " </td><td>" .. updated .. "</td></tr>\n") |
359 | if "" ~= v.Active then | 478 | if "" ~= v.Active then |
360 | file:write("<tr><td style='background-color:dimgrey'>" .. active .. "</td></tr>\n") | 479 | web:write("<tr><td style='background-color:dimgrey'>" .. active .. "</td></tr>\n") |
361 | end | 480 | end |
362 | end | 481 | end |
363 | file:write( "</table>\n<br>\n<h2>==== faulty mirrors: ====</h2>\n" .. faulty) | 482 | web:write( "</table>\n<br>\n<h2>==== faulty mirrors: ====</h2>\n" .. faulty) |
364 | file:write( "<br>\n<br>\n<h2>==== DNS and logs: ====</h2>\n") | 483 | web:write( "<br>\n<br>\n<h2>==== DNS and logs: ====</h2>\n") |
365 | 484 | ||
366 | for k, v in pairs(mirrors) do | 485 | for k, v in pairs(mirrors) do |
367 | local log = k | 486 | local log = k |
@@ -388,7 +507,7 @@ if nil == file then C("opening mirrors file - " .. e) else | |||
388 | end | 507 | end |
389 | m[log .. " DNS entries -"] = n | 508 | m[log .. " DNS entries -"] = n |
390 | end | 509 | end |
391 | file:write( "<p>This lists each mirror, and the DNS entries for that mirror. " .. | 510 | web:write( "<p>This lists each mirror, and the DNS entries for that mirror. " .. |
392 | "The links point to the testing log files for " .. logCount("apt-panopticon") .. " for each domain name / IP combination that was tested. " .. | 511 | "The links point to the testing log files for " .. logCount("apt-panopticon") .. " for each domain name / IP combination that was tested. " .. |
393 | "If a mirror has a CNAME, that CNAME is listed along with that CNAMEs DNS entries. " .. | 512 | "If a mirror has a CNAME, that CNAME is listed along with that CNAMEs DNS entries. " .. |
394 | "deb.devuan.org is the DNS round robin, which points to the mirrors that are part of the DNS-RR. " .. | 513 | "deb.devuan.org is the DNS round robin, which points to the mirrors that are part of the DNS-RR. " .. |
@@ -396,11 +515,11 @@ if nil == file then C("opening mirrors file - " .. e) else | |||
396 | "pkgmaster.devuan.org is the master mirror, all the others sync to it. " .. | 515 | "pkgmaster.devuan.org is the master mirror, all the others sync to it. " .. |
397 | "</p>\n" | 516 | "</p>\n" |
398 | ) | 517 | ) |
399 | file:write(dumpTableHTML(m, "", "")) | 518 | web:write(dumpTableHTML(m, "", "")) |
400 | file:write( "\n<br>\n<hr>\n\n" .. | 519 | web:write( "\n<br>\n<hr>\n\n" .. |
401 | "<p>The <a href='Report-email.txt'>email report</a>. " .. | 520 | "<p>The <a href='Report-email.txt'>email report</a>. " .. |
402 | "All <a href='../results'>the logs and other output</a>. " .. | 521 | "All <a href='../results'>the logs and other output</a>. " .. |
403 | "You can get the <a href='https://sledjhamr.org/cgit/apt-panopticon/about/'>source code here</a>.</p>" .. | 522 | "You can get the <a href='https://sledjhamr.org/cgit/apt-panopticon/about/'>source code here</a>.</p>" .. |
404 | "</body></html>\n") | 523 | "</body></html>\n") |
405 | file:close() | 524 | web:close() |
406 | end | 525 | end |
diff --git a/apt-panopticon-report-email.lua b/apt-panopticon-report-email.lua deleted file mode 100755 index 53db16f..0000000 --- a/apt-panopticon-report-email.lua +++ /dev/null | |||
@@ -1,292 +0,0 @@ | |||
1 | #!/usr/bin/env luajit | ||
2 | |||
3 | local args = {...} | ||
4 | |||
5 | verbosity = -1 | ||
6 | local logFile | ||
7 | |||
8 | |||
9 | --[[ Ordered table iterator, allow to iterate on the natural order of the keys of a table. | ||
10 | From http://lua-users.org/wiki/SortedIteration | ||
11 | ]] | ||
12 | function __genOrderedIndex( t ) | ||
13 | local orderedIndex = {} | ||
14 | for key in pairs(t) do | ||
15 | table.insert( orderedIndex, key ) | ||
16 | end | ||
17 | table.sort( orderedIndex ) | ||
18 | return orderedIndex | ||
19 | end | ||
20 | function orderedNext(t, state) | ||
21 | -- Equivalent of the next function, but returns the keys in the alphabetic | ||
22 | -- order. We use a temporary ordered key table that is stored in the | ||
23 | -- table being iterated. | ||
24 | |||
25 | local key = nil | ||
26 | --print("orderedNext: state = "..tostring(state) ) | ||
27 | if state == nil then | ||
28 | -- the first time, generate the index | ||
29 | t.__orderedIndex = __genOrderedIndex( t ) | ||
30 | key = t.__orderedIndex[1] | ||
31 | else | ||
32 | -- fetch the next value | ||
33 | for i = 1,table.getn(t.__orderedIndex) do | ||
34 | if t.__orderedIndex[i] == state then | ||
35 | key = t.__orderedIndex[i+1] | ||
36 | end | ||
37 | end | ||
38 | end | ||
39 | |||
40 | if key then | ||
41 | return key, t[key] | ||
42 | end | ||
43 | |||
44 | -- no more value to return, cleanup | ||
45 | t.__orderedIndex = nil | ||
46 | return | ||
47 | end | ||
48 | function orderedPairs(t) | ||
49 | -- Equivalent of the pairs() function on tables. Allows to iterate | ||
50 | -- in order | ||
51 | return orderedNext, t, nil | ||
52 | end | ||
53 | |||
54 | |||
55 | local plurals = function(e, w) | ||
56 | local result = "" | ||
57 | if 1 == e then | ||
58 | result = e .. " error" | ||
59 | elseif e ~= 0 then | ||
60 | result = e .. " errors" | ||
61 | end | ||
62 | if 0 < w then | ||
63 | if 0 < e then result = result .. ", " end | ||
64 | if 1 == w then | ||
65 | result = result .. w .. " warning" | ||
66 | else | ||
67 | result = result .. w .. " warnings" | ||
68 | end | ||
69 | end | ||
70 | if "" ~= result then result = " (" .. result .. ")" end | ||
71 | return result | ||
72 | end | ||
73 | |||
74 | local results = {} | ||
75 | |||
76 | local log = function(v, t, s, prot, test, host) | ||
77 | local x = "" | ||
78 | if nil == prot then prot = "" end | ||
79 | if nil ~= test then x = x .. test else test = "" end | ||
80 | if nil ~= host then | ||
81 | if #x > 0 then x = x .. " " end | ||
82 | x = x .. host | ||
83 | end | ||
84 | if #x > 0 then | ||
85 | t = t .. "(" .. x .. ")" | ||
86 | end | ||
87 | if v <= verbosity then | ||
88 | if 3 <= verbosity then t = os.date() .. " " .. t end | ||
89 | print(t .. ": " .. s) | ||
90 | end | ||
91 | if nil ~= logFile then | ||
92 | logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") | ||
93 | logFile:flush() | ||
94 | end | ||
95 | end | ||
96 | local D = function(s) log(3, "DEBUG ", s) end | ||
97 | local I = function(s) log(2, "INFO ", s) end | ||
98 | local W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end | ||
99 | local E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end | ||
100 | local C = function(s) log(-1, "CRITICAL", s) end | ||
101 | |||
102 | local faulty = "" | ||
103 | local status = function(host, results, typ) | ||
104 | local result = "" | ||
105 | local e = 0 | ||
106 | local w = 0 | ||
107 | if nil ~= results[typ] then | ||
108 | e = results[typ].errors | ||
109 | w = results[typ].warnings | ||
110 | for k, v in pairs(results[typ]) do | ||
111 | if "table" == type(v) then | ||
112 | e = e + v.errors | ||
113 | w = w + v.warnings | ||
114 | end | ||
115 | end | ||
116 | else | ||
117 | for k, v in pairs(results) do | ||
118 | if "table" == type(v) then | ||
119 | for i, u in pairs(v) do | ||
120 | if "table" == type(u) then | ||
121 | if typ == i then | ||
122 | e = e + u.errors | ||
123 | w = w + u.warnings | ||
124 | end | ||
125 | end | ||
126 | end | ||
127 | end | ||
128 | end | ||
129 | end | ||
130 | |||
131 | if 0 < e then result = e .. " errors" end | ||
132 | if 1 == e then result = e .. " error" end | ||
133 | if 0 < w then | ||
134 | if 0 < e then result = result .. ", " end | ||
135 | if 1 == w then | ||
136 | result = result .. w .. " warning" | ||
137 | else | ||
138 | result = result .. w .. " warnings" | ||
139 | end | ||
140 | end | ||
141 | if "[OK]" ~= result then | ||
142 | if 0 < e then | ||
143 | result = "[FAILED] (" .. result .. ")" | ||
144 | faulty = faulty .. host .. " (" .. typ .. ")\n" | ||
145 | elseif 0 < w then | ||
146 | result = "[OK] (" .. result .. ")" | ||
147 | else | ||
148 | result = "[OK]" | ||
149 | end | ||
150 | end | ||
151 | return result | ||
152 | end | ||
153 | |||
154 | local collate = function(host, ip, results) | ||
155 | local f = "results/" .. host .. "_" .. ip .. ".lua" | ||
156 | local rfile, e = io.open(f, "r") | ||
157 | if nil == rfile then I("opening " .. f .. " file - " .. e) else | ||
158 | rfile:close() | ||
159 | local rs = loadfile(f)() | ||
160 | for k, v in pairs(rs) do | ||
161 | if "table" == type(v) then | ||
162 | for i, u in pairs(v) do | ||
163 | if "table" == type(u) then | ||
164 | for h, t in pairs(u) do | ||
165 | local a = results[k][h] | ||
166 | if nil == a then a = 0 end | ||
167 | results[k][h] = a + t | ||
168 | end | ||
169 | else | ||
170 | local a = results[k][i] | ||
171 | if nil == a then a = 0 end | ||
172 | results[k][i] = a + u | ||
173 | end | ||
174 | end | ||
175 | else | ||
176 | local a = results[k] | ||
177 | if nil == a then a = 0 end | ||
178 | results[k] = a + v | ||
179 | end | ||
180 | end | ||
181 | end | ||
182 | return results | ||
183 | end | ||
184 | |||
185 | local mirrors = loadfile("results/mirrors.lua")() | ||
186 | |||
187 | local logCount = function(domain, ip) | ||
188 | local nm = "LOG_" .. domain | ||
189 | local log = "" | ||
190 | local extra = "" | ||
191 | if nil ~= ip then nm = nm .. "_" .. ip end | ||
192 | nm = nm .. ".html" | ||
193 | local rfile, e = io.open("results/" .. nm, "r") | ||
194 | if nil ~= rfile then | ||
195 | local errors = 0 | ||
196 | local warnings = 0 | ||
197 | for l in rfile:lines() do | ||
198 | if nil ~= l:match("><b>ERROR ") then errors = errors + 1 end | ||
199 | if nil ~= l:match("><b>WARNING ") then warnings = warnings + 1 end | ||
200 | end | ||
201 | rfile:close() | ||
202 | -- if nil == ip then | ||
203 | -- log = "<a href='" .. nm .. "'>" .. domain .. "</a>" | ||
204 | -- else | ||
205 | -- log = "<a href='" .. nm .. "'>" .. ip .. "</a>" | ||
206 | -- end | ||
207 | log = log .. plurals(errors, warnings) | ||
208 | end | ||
209 | return log | ||
210 | end | ||
211 | |||
212 | local file, e = io.open("results/Report-email.txt", "w+") | ||
213 | if nil == file then C("opening mirrors file - " .. e) else | ||
214 | file:write( "Dear Mirror Admins,\n\n" .. | ||
215 | "The full list of Devuan package mirrors is available at the URL:\n\n" .. | ||
216 | " https://pkgmaster.devuan.org/mirror_list.txt\n\n" .. | ||
217 | 'Please contact "mirrors@devuan.org" if any of the information \nin the file above needs to be amended. \n\n' .. | ||
218 | "The full results of the mirror checking is available at the URL:\n\n" .. | ||
219 | " https://sledjhamr.org/apt-panopticon/results/Report-web.html\n\n" .. | ||
220 | "Due to the nature of the tests, some errors or warnings will be \ncounted several times. " .. | ||
221 | "Refer to the logs on the web page for details.\n\n" .. | ||
222 | "Please see below the current status of the Devuan Package Mirror \nnetwork:\n\n" .. | ||
223 | "---- BEGIN MIRROR-STATUS " .. os.date("!%Y-%m-%d %H:%M") .. " GMT ----\n") | ||
224 | for k, v in orderedPairs(mirrors) do | ||
225 | local results = loadfile("results/" .. k .. ".lua")() | ||
226 | file:write(k .. "....\n") | ||
227 | local IPs = v.IPs | ||
228 | for i, u in pairs(IPs) do | ||
229 | if "table" == type(u) then | ||
230 | for h, t in pairs(u) do | ||
231 | results = collate(k, h, results) | ||
232 | end | ||
233 | else | ||
234 | results = collate(k, i, results) | ||
235 | end | ||
236 | end | ||
237 | local ftp = "[skip]" | ||
238 | local http = status(k, results, "http") | ||
239 | local https = status(k, results, "https") | ||
240 | local rsync = "[skip]" | ||
241 | local dns = "" | ||
242 | local protocol = status(k, results, "Protocol") | ||
243 | local sanity = "[skip]" | ||
244 | local integrity = status(k, results, "Integrity") | ||
245 | local updated = status(k, results, "Updated") | ||
246 | |||
247 | -- DNS-RR test. | ||
248 | if ("deb.devuan.org" ~= k) and (nil ~= mirrors["deb.devuan.org"]) then | ||
249 | for l, w in pairs(mirrors[k].IPs) do | ||
250 | if type(w) == "table" then | ||
251 | for i, u in pairs(w) do | ||
252 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then | ||
253 | local log = logCount("deb.devuan.org", i) | ||
254 | if "" ~= log then | ||
255 | if "" == dns then dns = " " else dns = dns .. " " end | ||
256 | dns = dns .. logCount("deb.devuan.org", i) | ||
257 | else | ||
258 | if "" == dns then dns = " " else dns = dns .. " " end | ||
259 | dns = dns .. i | ||
260 | end | ||
261 | end | ||
262 | end | ||
263 | else | ||
264 | if nil ~= mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][l] then | ||
265 | local log = logCount("deb.devuan.org", l) | ||
266 | if "" ~= log then | ||
267 | if "" == dns then dns = " " else dns = dns .. " " end | ||
268 | dns = dns .. log | ||
269 | else | ||
270 | if "" == dns then dns = " " else dns = dns .. " " end | ||
271 | dns = dns .. l | ||
272 | end | ||
273 | end | ||
274 | end | ||
275 | end | ||
276 | if "" == dns then dns = "[no]" end | ||
277 | dns = " DNS-RR: " .. dns | ||
278 | end | ||
279 | |||
280 | file:write( " ftp: " .. ftp .. " http: " .. http .. " https: " .. https .." rsync: " .. rsync .. "\n" .. | ||
281 | " " .. dns .. "\n" .. | ||
282 | " Protocol: " .. protocol .. " URL-sanity: " .. sanity .. " Integrity: " .. integrity .. "\n" .. | ||
283 | " Updated: " .. updated .. "\n") | ||
284 | end | ||
285 | file:write( "\n==== faulty mirrors: ====\n" .. faulty) | ||
286 | file:write( "\n---- END MIRROR-STATUS ----\n\n" .. | ||
287 | "Thanks for your precious help in ensuring that Devuan GNU+Linux \nremains a universal, stable, dependable, free operating system.\n\n" .. | ||
288 | "You can get the source code from https://sledjhamr.org/cgit/apt-panopticon/about/ ." .. | ||
289 | "Love\n\n" .. | ||
290 | "The Dev1Devs\n\n") | ||
291 | file:close() | ||
292 | end | ||
diff --git a/apt-panopticon.lua b/apt-panopticon.lua index 5d9ed82..96f6d62 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua | |||
@@ -60,11 +60,10 @@ options = | |||
60 | help = "", | 60 | help = "", |
61 | value = | 61 | value = |
62 | { | 62 | { |
63 | "email", | 63 | "email-web", |
64 | -- "Nagios", | 64 | -- "Nagios", |
65 | -- "Prometheus", | 65 | -- "Prometheus", |
66 | -- "RRD", | 66 | -- "RRD", |
67 | "web", | ||
68 | }, | 67 | }, |
69 | }, | 68 | }, |
70 | } | 69 | } |