- Add generator lua scripts lua

Fri, 07 Aug 2020 02:27:15 -0600

author
Glitchvid <Glitchvid@glitchvid.com>
date
Fri, 07 Aug 2020 02:27:15 -0600
branch
lua
changeset 15
c9ab7ec6476f
parent 14
642c06ca1266
child 16
46ca054d370f

- Add generator lua scripts

lua/genstats.lua file | annotate | diff | comparison | revisions
lua/htmltemplates.lua file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lua/genstats.lua	Fri Aug 07 02:27:15 2020 -0600
@@ -0,0 +1,91 @@
+--[[---------------------------------PURPOSE-----------------------------------
+	Generates static pages with embeded Grafana iframes.
+---------------------------------------------------------------------------]]--
+
+-- Ugly stuff to let us load packages from our passed file directory.
+local function FilePath()
+	local str = debug.getinfo(2, "S").source:sub(2)
+	return str:match("(.*[/\\])") or "."
+end
+package.path = package.path .. ";" .. FilePath() .. "/?.lua"
+
+local HTML = require("htmltemplates") -- HTML is messy, hide it away.
+
+local timeScales = {}
+timeScales[1] = {"24 Hours", "now-24h", "now"}
+timeScales[2] = {"7 Days", "now-7d", "now"}
+timeScales[3] = {"30 Days", "now-30d", "now"}
+timeScales[4] = {"1 Year", "now-1y", "now"}
+timeScales[5] = {"2 Years", "now-2y", "now"}
+
+local panels = {}
+-- Transit
+panels[1] = {name="Cogent", id="24", type="transit"}
+panels[2] = {name="Comcast", id="26", type="transit"}
+panels[3] = {name="NTT", id="30", url="NTT", type="transit"}
+panels[4] = {name="XO", id="2", type="transit"}
+-- Exchanges
+panels[5] = {name="Any2", id="13", type="exchange"}
+panels[6] = {name="SIX", id="34", url="SIX", type="exchange"}
+panels[7] = {name="SLIX", id="28", url="SLIX", type="exchange"}
+panels[8] = {name="HE", id="63", url="HE", type="exchange"}
+-- Endpoints
+panels[9] = {name="Colind", id="38", type="endpoint"}
+panels[10] = {name="Google DNS", id="42", url="google", type="endpoint"}
+panels[11] = {name="DAL05 (Softlayer)", id="46", url="dal05", type="endpoint"}
+panels[12] = {name="NFO (LA)", id="51", url="nfola", type="endpoint"}
+panels[13] = {name="NFO (SJ)", id="52", url="nfosj", type="endpoint"}
+panels[14] = {name="C7 (SLC)", id="56", url="c7slc", type="endpoint"}
+panels[15] = {name="Zarth (CHI)", id="60", url="zarth", type="endpoint"}
+
+
+local function GenerateSection(timescale, panel)
+	local section = "" .. HTML.section
+	section = string.gsub(section, "$TIMESCALEENGLISH", tostring(timescale[1]))
+	section = string.gsub(section, "$FROM", tostring(timescale[2]))
+	section = string.gsub(section, "$TO", tostring(timescale[3]))
+	section = string.gsub(section, "$PANELID", tostring(panel.id))
+	return section
+end
+
+local function GeneratePanel(panel)
+	-- Header, page title, and body text
+	local pagetitle = string.upper(panel.name) .. " LATENCY (NACL)"
+	local output = ""
+	output	=	output .. HTML.header .. pagetitle .. HTML.headertail
+	output	=	output .. HTML.bodycontenthead .. pagetitle .. HTML.bodycontenttail
+
+	-- Generate and append sections
+	output	=	output ..	HTML.linkboxbegin
+
+	for i=1, #timeScales do
+		local timescale = timeScales[i]
+		local section = GenerateSection(timescale, panel)
+		output	=	output .. section
+	end
+
+	output	=	output .. HTML.linkboxtail
+	-- Finish
+	output	=	output .. HTML.tail
+	return output
+end
+
+local function WriteHTML(panel)
+	local file, code = io.open( ( FilePath() .. "latency/" .. ( panel.url or string.lower(panel.name) ) ) .. ".html", "w")
+	if not file then 
+		return nil 
+	end
+	file:write(GeneratePanel(panel))
+	return file, code
+end
+
+-- Do the do!
+for i=1, #panels do
+	local panel = panels[i]
+	local didWrite = WriteHTML(panel)
+	if didWrite == nil then
+		os.execute("mkdir " .. FilePath() .. "latency")
+		WriteHTML(panel)
+	end
+	print("Wrote: " .. (panel.url or string.lower(panel.name)) .. ".html" )
+end
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lua/htmltemplates.lua	Fri Aug 07 02:27:15 2020 -0600
@@ -0,0 +1,63 @@
+local templates = {}
+
+templates.header =	[[
+<!DOCTYPE html>
+<html>
+	
+<head> 
+<meta name=viewport content="width=device-width, initial-scale=1" charset="UTF-8">
+<link rel="icon" type="image/png" href="https://static.glitchvid.com/favicon.png">
+<link rel="stylesheet" href="../styles.css">
+<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
+<title>
+			]]
+
+templates.headertail =	[[
+
+</title>
+</head>
+]]
+
+templates.bodycontenthead =	[[
+<body bgcolor="#1a1a1a">
+<h1 class="gvidnet">
+			]]
+
+templates.bodycontenttail =	[[
+
+</h1>
+
+]]
+
+templates.linkboxbegin =	[[
+<div class="linkbox">
+
+]]
+
+templates.linkboxtail =	[[
+
+</div>
+]]
+
+templates.tail =	[[
+
+</body>
+</html>
+]]
+
+templates.section =	[[
+<section class="links" id="$TIMESCALEENGLISH">
+	<a href="#$TIMESCALEENGLISH">
+		<h4>
+			$TIMESCALEENGLISH
+		</h4>
+	</a>
+	<ul class="list">
+		<li>
+			<iframe src="https://grafana.nacl.glitchvid.com/d-solo/39mqm44Zz/render-template-dashboard?orgId=2&refresh=5m&var-interval=5m&from=$FROM&to=$TO&panelId=$PANELID" width="817" height="240" frameborder="0"></iframe>
+		</li>
+	</ul>
+</section>
+]]
+
+return templates
\ No newline at end of file

mercurial