104 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <!DOCTYPE html>
 | |
| <html lang="en">
 | |
| <head>
 | |
| 	<title>Status</title>
 | |
| 	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
 | |
| 	<style>
 | |
| 		td > span.badge {
 | |
| 			display: inline-block;
 | |
| 			width: 20px;
 | |
| 			cursor: default;
 | |
| 			margin-right: 2px;
 | |
| 		}
 | |
| 	</style>
 | |
| </head>
 | |
| <body>
 | |
| 	<div class="container my-3 bg-light rounded p-4 border shadow">
 | |
| 		<div class="text-center mb-3">
 | |
| 			<div class="display-4">Status</div>
 | |
| 		</div>
 | |
| 		<div class="table-responsive">
 | |
| 			<table class="table">
 | |
| 				<thead>
 | |
| 					<tr>
 | |
| 						<th scope="col">Name</th>
 | |
| 						<th scope="col">Status</th>
 | |
| 						<th scope="col">Hostname</th>
 | |
| 						<th scope="col">Response time</th>
 | |
| 					</tr>
 | |
| 				</thead>
 | |
| 				<tbody id="results">
 | |
| 				</tbody>
 | |
| 			</table>
 | |
| 		</div>
 | |
| 	</div>
 | |
| 
 | |
| 	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 | |
| 	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
 | |
| 	<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
 | |
| 
 | |
| 	<script>
 | |
| 		const OK = "<span class='badge badge-success' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>✓</span>";
 | |
| 		const NOK = "<span class='badge badge-danger' title='__RESPONSE_TIME____CONDITIONS____ERRORS__'>X</span>";
 | |
| 
 | |
| 		function generateServiceResultBox(serviceResult) {
 | |
| 			let output = (serviceResult.success ? OK : NOK);
 | |
| 			output = output.replace("__RESPONSE_TIME__", "Response time:\n" + parseInt(serviceResult.duration/1000000) + "ms");
 | |
| 			let conditions = "";
 | |
| 			for (let conditionResultIndex in serviceResult['condition-results']) {
 | |
| 				let conditionResult = serviceResult['condition-results'][conditionResultIndex];
 | |
| 				conditions += "\n- " + (conditionResult.success ? "✓" : "X") + " ~ " + conditionResult.condition;
 | |
| 			}
 | |
| 			output = output.replace("__CONDITIONS__", "\n\nConditions:" + conditions);
 | |
| 			if (serviceResult['errors'].length > 0) {
 | |
| 				let errors = "";
 | |
| 				for (let errorIndex in serviceResult['errors']) {
 | |
| 					errors += "\n- " + serviceResult['errors'][errorIndex];
 | |
| 				}
 | |
| 				output = output.replace("__ERRORS__", "\n\nErrors: " + errors);
 | |
| 			} else {
 | |
| 				output = output.replace("__ERRORS__", "");
 | |
| 			}
 | |
| 			return output;
 | |
| 		}
 | |
| 		
 | |
| 		function refreshTable() {
 | |
| 			$.getJSON("/api/v1/results", function (data) {
 | |
| 				let tableBody = "";
 | |
| 				for (let serviceName in data) {
 | |
| 					let serviceStatusOverTime = "";
 | |
| 					let hostname = data[serviceName][data[serviceName].length-1].hostname 
 | |
| 					let minResponseTime = null;
 | |
| 					let maxResponseTime = null;
 | |
| 					for (let key in data[serviceName]) {
 | |
| 						let serviceResult = data[serviceName][key];
 | |
| 						console.log(serviceResult);
 | |
| 						serviceStatusOverTime = generateServiceResultBox(serviceResult) + serviceStatusOverTime;
 | |
| 						const responseTime = parseInt(serviceResult.duration/1000000);
 | |
| 						if (minResponseTime == null || minResponseTime > responseTime) {
 | |
| 							minResponseTime = responseTime;
 | |
| 						}
 | |
| 						if (maxResponseTime == null || maxResponseTime < responseTime) {
 | |
| 							maxResponseTime = responseTime;
 | |
| 						}
 | |
| 					}
 | |
| 					tableBody += ""
 | |
| 						+ "<tr>"
 | |
| 						+ "  <td>" + serviceName + "</td>"
 | |
| 						+ "  <td>" + serviceStatusOverTime + "</td>"
 | |
| 						+ "  <td><a href=\"//" + hostname + "\">" + hostname + "</a></td>"
 | |
| 						+ "  <td>" + (minResponseTime === maxResponseTime ? minResponseTime : (minResponseTime + "-" + maxResponseTime)) + "ms</td>"
 | |
| 						+ "</tr>";
 | |
| 				}
 | |
| 				$("#results").html(tableBody);
 | |
| 			});
 | |
| 		}
 | |
| 
 | |
| 		refreshTable();
 | |
| 		setInterval(function() {
 | |
| 			refreshTable();
 | |
| 		}, 10000);
 | |
| 	</script>
 | |
| </body>
 | |
| </html>
 |