From 7a8fdb894665b3ce8aec4ef7193a1d13327a76d0 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 13 Nov 2019 20:38:42 +1000 Subject: Clean up the reports, and merge the DNS report into the web report. Include links to the logs. Tweak the colours a little. Put the results into a table, for better readability. --- apt-panopticon-report-DNS.lua | 150 ------------------------------------------ apt-panopticon-report-web.lua | 90 ++++++++++++++++++++++--- apt-panopticon.lua | 1 - 3 files changed, 80 insertions(+), 161 deletions(-) delete mode 100755 apt-panopticon-report-DNS.lua 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 @@ -#!/usr/bin/env luajit - -local args = {...} - -local logFile - - ---[[ Ordered table iterator, allow to iterate on the natural order of the keys of a table. - From http://lua-users.org/wiki/SortedIteration - ]] -function __genOrderedIndex( t ) - local orderedIndex = {} - for key in pairs(t) do - table.insert( orderedIndex, key ) - end - table.sort( orderedIndex ) - return orderedIndex -end -function orderedNext(t, state) - -- Equivalent of the next function, but returns the keys in the alphabetic - -- order. We use a temporary ordered key table that is stored in the - -- table being iterated. - - local key = nil - --print("orderedNext: state = "..tostring(state) ) - if state == nil then - -- the first time, generate the index - t.__orderedIndex = __genOrderedIndex( t ) - key = t.__orderedIndex[1] - else - -- fetch the next value - for i = 1,table.getn(t.__orderedIndex) do - if t.__orderedIndex[i] == state then - key = t.__orderedIndex[i+1] - end - end - end - - if key then - return key, t[key] - end - - -- no more value to return, cleanup - t.__orderedIndex = nil - return -end -function orderedPairs(t) - -- Equivalent of the pairs() function on tables. Allows to iterate - -- in order - return orderedNext, t, nil -end - - --- Use this to dump a table to a string. -dumpTable = function (table, space, name) - local r = "" --- if "" == space then r = r .. space .. name .. " =\n" else r = r .. space .. "[" .. name .. "] =\n" end - if "" == space then r = r .. space .. name .. " \n" else r = r .. space .. name .. "\n" end --- r = r .. space .. "{\n" - r = r .. dumpTableSub(table, space .. " ") --- if "" == space then r = r .. space .. "}\n" else r = r .. space .. "},\n" end - if "" == space then r = r .. space .. "\n" end - return r -end -dumpTableSub = function (table, space) - local r = "" --- for k, v in pairs(table) do - for k, v in orderedPairs(table) do --- if type(k) == "string" then k = '"' .. k .. '"' end - if type(v) == "table" then - r = r .. dumpTable(v, space, k) --- elseif type(v) == "string" then --- r = r .. space .. "[" .. k .. "] = '" .. v .. "';\n" --- elseif type(v) == "function" then --- r = r .. space .. "[" .. k .. "] = function ();\n" --- elseif type(v) == "userdata" then --- r = r .. space .. "userdata " .. "[" .. k .. "];\n" --- elseif type(v) == "boolean" then --- if (v) then --- r = r .. space .. "[" .. k .. "] = true;\n" --- else --- r = r .. space .. "[" .. k .. "] = false;\n" --- end - else --- r = r .. space .. "[" .. k .. "] = " .. v .. ";\n" - r = r .. space .. k .. "\n" - end - end - return r -end - -local results = {} - -local log = function(v, t, s, prot, test, host) - local x = "" - if nil == prot then prot = "" end - if nil ~= test then x = x .. test else test = "" end - if nil ~= host then - if #x > 0 then x = x .. " " end - x = x .. host - end - if #x > 0 then - t = t .. "(" .. x .. ")" - if "" == test then - if v == 0 then results[prot].errors = results[prot].errors + 1 end - if v == 1 then results[prot].warnings = results[prot].warnings + 1 end - else - if v == 0 then results[prot][test].errors = results[prot][test].errors + 1 end - if v == 1 then results[prot][test].warnings = results[prot][test].warnings + 1 end - end - end - if v <= verbosity then - if 3 <= verbosity then t = os.date() .. " " .. t end - print(t .. ": " .. s) - end - if nil ~= logFile then - logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") - logFile:flush() - end -end -local D = function(s) log(3, "DEBUG ", s) end -local I = function(s) log(2, "INFO ", s) end -local W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end -local E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end -local C = function(s) log(-1, "CRITICAL", s) end - -local mirrors = loadfile("results/mirrors.lua")() -local m = {} - -for k, v in pairs(mirrors) do - mirrors[k].Protocols = nil - mirrors[k].FQDN = nil - mirrors[k].Active = nil - mirrors[k].Rate = nil - mirrors[k].BaseURL = nil - mirrors[k].Country = nil - mirrors[k].Bandwidth = nil - m["\n" .. k .. " DNS entries -"] = mirrors[k].IPs -end - - -local file, e = io.open("results/Report-DNS.txt", "w+") -if nil == file then C("opening mirrors file - " .. e) else - file:write("This DNS report lists each mirror, and the DNS entries for that \nmirror. " .. - "If a mirror has a CNAME, that CNAME is listed along with that \nCNAMEs DNS entries. " .. - "deb.devuan.org is the DNS round robin, which points \nto the mirrors that are part of the DNS-RR. " .. - "pkgmaster.devuan.org is the \nmaster mirror, all the others sync to it. ") - file:write(dumpTable(m, "", "")) - file:close() -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) return orderedNext, t, nil end +-- Use this to dump a table to a string, with HTML. +dumpTableHTML = function (table, space, name) + local r = name .. "\n" + r = r .. dumpTableHTMLSub(table, space .. " ") + r = r .. space .. "" + return r +end +dumpTableHTMLSub = function (table, space) + local r = "" + for k, v in orderedPairs(table) do + if type(v) == "table" then + if " " == space then + r = r .. space .. dumpTableHTML(v, space, k .. "\n" + else + r = r .. "
  • " .. space .. dumpTableHTML(v, space, k .. "
  • \n" + end + else + r = r .. space .. "
  • " .. k .. "
  • \n" + end + end + return r +end local results = {} @@ -114,9 +136,9 @@ local status = function(host, results, typ) if 0 < w then if 0 < e then result = result .. ", " end if 1 == w then - result = result .. w .. " warning" + result = result .. w .. " warning" else - result = result .. w .. " warnings" + result = result .. w .. " warnings" end end if "[OK]" ~= result then @@ -164,15 +186,16 @@ local collate = function(host, ip, results) end local mirrors = loadfile("results/mirrors.lua")() +local m = {} local file, e = io.open("results/Report-web.html", "w+") if nil == file then C("opening mirrors file - " .. e) else file:write( "\n" .. '' .. - "Check date: " .. os.date("!%a %b %d %T %Z %Y") .. "\n
    \n") + "Check date: " .. os.date("!%a %b %d %T %Z %Y") .. "\n
    \n\n") for k, v in orderedPairs(mirrors) do local results = loadfile("results/" .. k .. ".lua")() - file:write(" " .. k .. ".... ") + file:write(" ") local IPs = v.IPs for i, u in pairs(IPs) do if "table" == type(u) then @@ -185,15 +208,62 @@ if nil == file then C("opening mirrors file - " .. e) else end local http = status(k, results, "http") local https = status(k, results, "https") - local dns = "[skip]" + local dns = "[skip]" local protocol = status(k, results, "Protocol") - local sanity = "[skip]" - local integrity = "[skip]" - local updated = "[skip]" - file:write(" http: " .. http .. " https: " .. https .. " DNS-RR: " .. dns .. " Protocol: " .. protocol .. " URL-sanity: " .. sanity .. " Integrity: " .. integrity .. " Updated: " .. updated .. "\n
    \n") + local sanity = "[skip]" + local integrity = "[skip]" + local updated = "[skip]" + file:write("\n") end - file:write( "==== faulty mirrors: ====
    \n
    \n" .. faulty) + file:write( "
    " .. k .. "http: " .. http .. "https: " .. https .. "DNS-RR: " .. + dns .. "Protocol: " .. protocol .. "URL-sanity: " .. sanity .. + "Integrity: " .. integrity .. "Updated: " .. updated .. "
    \n==== faulty mirrors: ====
    \n
    \n" .. faulty) file:write( "\n
    \nLast Failure: NOT WRITTEN YET
    \n
    ") + + for k, v in pairs(mirrors) do + local n = {} + mirrors[k].Protocols = nil + mirrors[k].FQDN = nil + mirrors[k].Active = nil + mirrors[k].Rate = nil + mirrors[k].BaseURL = nil + mirrors[k].Country = nil + mirrors[k].Bandwidth = nil + for l, w in pairs(mirrors[k].IPs) do + if type(w) == "table" then + n[l] = {} + for i, u in pairs(w) do + local nm = "LOG_" .. k .. "_" .. i .. ".html" + local rfile, e = io.open("results/" .. nm, "r") + if nil ~= rfile then + rfile:close() + n[l]["" .. i .. ""] = u + else + n[l][i] = u + end + end + else + local nm = "LOG_" .. k .. "_" .. l .. ".html" + local rfile, e = io.open("results/" .. nm, "r") + if nil ~= rfile then + rfile:close() + n["" .. l .. ""] = w + else + n[l] = w + end + end + end + m[k .. " DNS entries -"] = n + end + file:write("
    \n
    \n
    \n" .. + "

    This DNS report lists each mirror, and the DNS entries for that mirror. " .. + "If a mirror has a CNAME, that CNAME is listed along with that CNAMEs DNS entries. " .. + "deb.devuan.org is the DNS round robin, which points to the mirrors that are part of the DNS-RR. " .. + "pkgmaster.devuan.org is the master mirror, all the others sync to it. " .. + "The links point to the log files for each FDQN / IP combination that was checked. " .. + "

    \n

    " + ) + file:write(dumpTableHTML(m, "", "")) file:write( "\n
    \n\n\n") file:close() 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 = help = "", value = { - "DNS", "email", -- "Nagios", -- "Prometheus", -- cgit v1.1