From e2e770c58d33f9a1d87076bd12ce42ce7ac2c6dd Mon Sep 17 00:00:00 2001
From: Florian Sesser <florian@privatestorage.io>
Date: Fri, 28 May 2021 11:21:43 +0000
Subject: [PATCH] Add hosts mapping

... so Grafana shows us names instead of VPN IP addresses.

Avoiding catastrophy: It's all about minimizing cognitive overhead.
---
 morph/grid/local/grid.nix     | 9 ++++++++-
 morph/lib/make-monitoring.nix | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/morph/grid/local/grid.nix b/morph/grid/local/grid.nix
index 3f4f5243..8f72dd95 100644
--- a/morph/grid/local/grid.nix
+++ b/morph/grid/local/grid.nix
@@ -8,6 +8,12 @@ import ../../lib/make-grid.nix {
   let
     sshUsers = import ../../../../PrivateStorageSecrets/localdev-users.nix;
     vpnClientIPs = [ "172.23.23.11" "172.23.23.12" "172.23.23.13" ]; # TBD: derive automatically
+    hostsMap = {
+      "172.23.23.1"  = [ "monitoring1" "monitoring1.monitoringvpn" ];
+      "172.23.23.11" = [ "payments1" "payments1.monitoringvpn" ];
+      "172.23.23.12" = [ "storage1" "storage1.monitoringvpn" ];
+      "172.23.23.13" = [ "storage2" "storage2.monitoringvpn" ];
+    };
   in {
     "payments1" = import ../../lib/make-issuer.nix (rec {
       publicIPv4 = "192.168.67.21";
@@ -37,8 +43,9 @@ import ../../lib/make-grid.nix {
       publicIPv4 = "192.168.67.24";
       monitoringvpnIPv4 = "172.23.23.1";
       inherit vpnClientIPs;
+      inherit hostsMap;
       inherit sshUsers;
-      nodeExporterTargets = [ "172.23.23.1" "172.23.23.11" "172.23.23.12" "172.23.23.13" ]; # TBD: derive automatically
+      nodeExporterTargets = [ "monitoring1" "payments1" "storage1" "storage2" ]; # TBD: derive automatically
       nginxExporterTargets = [ ];
       hardware = import ./virtual-hardware.nix ({ inherit publicIPv4; });
       stateVersion = "19.09";
diff --git a/morph/lib/make-monitoring.nix b/morph/lib/make-monitoring.nix
index b8242446..4c1e6916 100644
--- a/morph/lib/make-monitoring.nix
+++ b/morph/lib/make-monitoring.nix
@@ -11,6 +11,7 @@
 , vpnClientIPs
 , nodeExporterTargets
 , nginxExporterTargets
+, hostsMap ? {}
 , ... }:
 
 # This doesn't work yet:
@@ -75,4 +76,6 @@ rec {
   };
 
   system.stateVersion = stateVersion;
+
+  networking.hosts = hostsMap;
 }
-- 
GitLab