From f54228d708964e6a04d5e28f307e63067b242384 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 10 May 2024 12:34:00 -0700 Subject: [PATCH] status: add TLS to page --- framework/ndn-testbed-status/src/App.vue | 78 ++++++++++----------- framework/ndn-testbed-status/src/testbed.ts | 41 +++++++++++ framework/status-json.py | 2 + 3 files changed, 80 insertions(+), 41 deletions(-) create mode 100644 framework/ndn-testbed-status/src/testbed.ts diff --git a/framework/ndn-testbed-status/src/App.vue b/framework/ndn-testbed-status/src/App.vue index a8f9d7b..a29bfd0 100644 --- a/framework/ndn-testbed-status/src/App.vue +++ b/framework/ndn-testbed-status/src/App.vue @@ -10,6 +10,9 @@ Revision Status + TLS Expiry + WSS + Host OS Kernel Arch @@ -44,7 +47,17 @@ {{ router.status?.revision }} - {{ getFromNow(router.status?.timestamp) }} + {{ getFromNowStr(router.status?.timestamp, 'seconds') }} + + {{ getFromNowStr(router.status?.tls?.expiry, 'days') || router.status?.tls?.error }} + + {{ router.status?.['ws-tls'] ? 'OK' : '' }} + {{ router.status?.host_info?.os }} {{ router.status?.host_info?.kernel }} @@ -65,7 +78,7 @@ {{ router.status?.ndnping[node.shortname] || '' }} @@ -86,42 +99,6 @@ const ROUTERS_JSON = '/ndn/edu/ucla/file-server/routers.json'; const STATUS_SFX = '/file-server/status.json'; const TESTBED_REPO = 'https://github.com/UCLA-IRL/testbed'; -interface IRouter { - host: string; - ip_addresses: string[]; - name: string; - position: [number, number]; - prefix: string; - shortname: string; - fetching?: boolean; - error?: boolean; - status?: IStatus; -}; - -interface IStatus { - timestamp: number; - revision: string; - host_info?: { - kernel: string; - os: string; - arch: string; - docker_version: string; - }, - services: Record; - nfd: { - version: string; - uptime: string; - }, - nlsr: { - version: string; - }, - ndnping: Record, -}; - export default defineComponent({ name: 'App', @@ -193,11 +170,24 @@ export default defineComponent({ return `${TESTBED_REPO}/commit/${router.status!.revision}`; }, - getFromNow(timestamp: number | undefined) { + getFromNow(timestamp: T) { + if (!timestamp) return timestamp; + + return timestamp - Date.now() / 1000; + }, + + getFromNowStr(timestamp: number | undefined | null, unit: Intl.RelativeTimeFormatUnit) { if (!timestamp) return String(); - const diff = Math.round(Date.now() / 1000 - timestamp); - return `${diff}s`; + let diff = this.getFromNow(timestamp); + switch (unit) { + case 'days': + diff /= 60 * 60 * 24; + break; + } + + const rtf = new Intl.RelativeTimeFormat('en', { style: 'short' }); + return rtf.format(Math.round(diff), unit); }, }, }); @@ -240,6 +230,9 @@ table thead th { td { background-color: white; + max-width: 360px; + text-overflow: ellipsis; + overflow: hidden; } td.error, td:has(.error) { background-color: #ffaaaa !important; @@ -250,6 +243,9 @@ td.okay { td.warning { background-color: #ffffaa; } +td.blue { + background-color: #aaaaff; +} a { color: blue; diff --git a/framework/ndn-testbed-status/src/testbed.ts b/framework/ndn-testbed-status/src/testbed.ts new file mode 100644 index 0000000..c979b6a --- /dev/null +++ b/framework/ndn-testbed-status/src/testbed.ts @@ -0,0 +1,41 @@ +interface IRouter { + host: string; + ip_addresses: string[]; + name: string; + position: [number, number]; + neightbors: string[]; + prefix: string; + shortname: string; + fetching?: boolean; + error?: boolean; + status?: IStatus; +} + +interface IStatus { + timestamp: number; + revision: string; + host_info?: { + kernel: string; + os: string; + arch: string; + docker_version: string; + }, + tls: { + expiry: number | null, + error: string | null, + }, + 'ws-tls': boolean, + services: Record; + nfd: { + version: string; + uptime: string; + }, + nlsr: { + version: string; + }, + ndnping: Record, +} \ No newline at end of file diff --git a/framework/status-json.py b/framework/status-json.py index 7daa18b..f8d656d 100644 --- a/framework/status-json.py +++ b/framework/status-json.py @@ -108,6 +108,7 @@ def get_tls_expiry(hostname: str, port: int) -> int: return int(expiry_date.timestamp()) def get_tls_status(host: dict): + print('Getting TLS status', file=sys.stderr) result = { 'expiry': None, 'error': None } try: result['expiry'] = get_tls_expiry(host['ansible_host'], 443) @@ -116,6 +117,7 @@ def get_tls_status(host: dict): return result def get_ws_tls_status(host: dict) -> bool: + print('Getting websocket status', file=sys.stderr) url = f"https://{host['ansible_host']}/ws/" try: with urllib.request.urlopen(url, timeout=3):