Skip to content

Commit

Permalink
status: add TLS to page
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed May 10, 2024
1 parent b528f62 commit f54228d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 41 deletions.
78 changes: 37 additions & 41 deletions framework/ndn-testbed-status/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<th>Revision</th>
<th>Status</th>

<th>TLS Expiry</th>
<th>WSS</th>

<th>Host OS</th>
<th>Kernel</th>
<th>Arch</th>
Expand Down Expand Up @@ -44,7 +47,17 @@
{{ router.status?.revision }}
</a>
</td>
<td>{{ getFromNow(router.status?.timestamp) }}</td>
<td :class="{
warning: getFromNow(router.status?.timestamp ?? 0) < -1800,
}">{{ getFromNowStr(router.status?.timestamp, 'seconds') }}</td>
<td :class="{
warning: (router.status?.tls?.expiry ?? -1) < 0,
okay: getFromNow(router.status?.tls?.expiry ?? -1) > 7 * 86400,
}">{{ getFromNowStr(router.status?.tls?.expiry, 'days') || router.status?.tls?.error }}</td>
<td :class="{ okay: router.status?.['ws-tls']}">
{{ router.status?.['ws-tls'] ? 'OK' : '' }}
</td>
<td>{{ router.status?.host_info?.os }}</td>
<td>{{ router.status?.host_info?.kernel }}</td>
Expand All @@ -65,7 +78,7 @@
<td v-for="node in routers" :class="{
error: !router.status?.ndnping[node.shortname],
okay: (router.shortname != node.shortname) && (router.status?.ndnping[node.shortname] ?? 0 > 0),
warning: (router.shortname == node.shortname),
blue: (router.shortname == node.shortname),
}">
{{ router.status?.ndnping[node.shortname] || '' }}
</td>
Expand All @@ -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<string, {
image: string;
status: string;
running: boolean;
}>;
nfd: {
version: string;
uptime: string;
},
nlsr: {
version: string;
},
ndnping: Record<string, number | null>,
};
export default defineComponent({
name: 'App',
Expand Down Expand Up @@ -193,11 +170,24 @@ export default defineComponent({
return `${TESTBED_REPO}/commit/${router.status!.revision}`;
},
getFromNow(timestamp: number | undefined) {
getFromNow<T extends number>(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);
},
},
});
Expand Down Expand Up @@ -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;
Expand All @@ -250,6 +243,9 @@ td.okay {
td.warning {
background-color: #ffffaa;
}
td.blue {
background-color: #aaaaff;
}
a {
color: blue;
Expand Down
41 changes: 41 additions & 0 deletions framework/ndn-testbed-status/src/testbed.ts
Original file line number Diff line number Diff line change
@@ -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<string, {
image: string;
status: string;
running: boolean;
}>;
nfd: {
version: string;
uptime: string;
},
nlsr: {
version: string;
},
ndnping: Record<string, number | null>,
}
2 changes: 2 additions & 0 deletions framework/status-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit f54228d

Please sign in to comment.