From a2e6d61d91b135d7ea14a99bbb52ee9e2114c6d3 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Thu, 18 Aug 2016 13:49:52 -0700 Subject: [PATCH] scrape possible remote access IP and report with health checks This will simplify remote access as the IP will be displayed on the dashboard with the rest of the health checks. Bonus: use
 to ascii-format health check info on the dashboard

Fixes https://github.com/flutter/cocoon/issues/36
---
 agent/lib/src/commands/ci.dart       | 21 +++++++++++++++++++++
 app/lib/components/status_table.dart |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/agent/lib/src/commands/ci.dart b/agent/lib/src/commands/ci.dart
index b0435acc2c..4cac4b8174 100644
--- a/agent/lib/src/commands/ci.dart
+++ b/agent/lib/src/commands/ci.dart
@@ -131,6 +131,8 @@ class ContinuousIntegrationCommand extends Command {
       results['able-to-perform-health-check'] = new HealthCheckResult.error(e, s);
     }
 
+    results['ssh-connectivity'] = await _scrapeRemoteAccessInfo();
+
     return results;
   }
 
@@ -197,3 +199,22 @@ Future getFlutterAt(String revision) async {
 
   await getFlutter(revision);
 }
+
+/// Returns the IP address for remote (SSH) access to this agent.
+///
+/// Uses `ipconfig getifaddr en0`.
+///
+/// Always returns [new HealthCheckResult.success] regardless of whether an IP
+/// is available or not. Having remote access to an agent is not a prerequisite
+/// for being able to perform Cocoon tasks. It's only there to make maintenance
+/// convenient. The goal is only to report available IPs as part of the health
+/// check.
+Future _scrapeRemoteAccessInfo() async {
+  String ip = (await eval('ipconfig', ['getifaddr', 'en0'], canFail: true)).trim();
+
+  return new HealthCheckResult.success(ip.isEmpty
+    ? 'No IP found for remote (SSH) access to this client. '
+      'Did you forget to plug the Ethernet cable?'
+    : 'Possible remote access IP: $ip'
+  );
+}
diff --git a/app/lib/components/status_table.dart b/app/lib/components/status_table.dart
index 022bc47c0a..af368e9ff8 100644
--- a/app/lib/components/status_table.dart
+++ b/app/lib/components/status_table.dart
@@ -41,7 +41,7 @@ import 'package:http/http.dart' as http;
     {{agentHealthCheckAge(displayedAgentStatus.healthCheckTimestamp)}}
   
   
Details:
-
{{displayedAgentStatus.healthDetails}}
+
{{displayedAgentStatus.healthDetails}}