summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus/exporters/mikrotik.nix
diff options
context:
space:
mode:
authorMartin Milata <martin@martinmilata.cz>2020-03-05 22:39:38 +0100
committerMartin Milata <martin@martinmilata.cz>2020-03-06 10:39:05 +0100
commit421a18f42b93be350ca31cfd5fafd68f1caadeef (patch)
tree9bc7b179d450c05c1f928496cd8302726d7ed221 /nixos/modules/services/monitoring/prometheus/exporters/mikrotik.nix
parentade67bd0520232c2a5e9f00ace3cb871fa22a9a7 (diff)
downloadnixpkgs-421a18f42b93be350ca31cfd5fafd68f1caadeef.tar
nixpkgs-421a18f42b93be350ca31cfd5fafd68f1caadeef.tar.gz
nixpkgs-421a18f42b93be350ca31cfd5fafd68f1caadeef.tar.bz2
nixpkgs-421a18f42b93be350ca31cfd5fafd68f1caadeef.tar.lz
nixpkgs-421a18f42b93be350ca31cfd5fafd68f1caadeef.tar.xz
nixpkgs-421a18f42b93be350ca31cfd5fafd68f1caadeef.tar.zst
nixpkgs-421a18f42b93be350ca31cfd5fafd68f1caadeef.zip
nixos/prometheus-mikrotik-exporter: init
Diffstat (limited to 'nixos/modules/services/monitoring/prometheus/exporters/mikrotik.nix')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/mikrotik.nix66
1 files changed, 66 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/mikrotik.nix b/nixos/modules/services/monitoring/prometheus/exporters/mikrotik.nix
new file mode 100644
index 00000000000..62c2cc56847
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/mikrotik.nix
@@ -0,0 +1,66 @@
+{ config, lib, pkgs, options }:
+
+with lib;
+
+let
+  cfg = config.services.prometheus.exporters.mikrotik;
+in
+{
+  port = 9436;
+  extraOpts = {
+    configFile = mkOption {
+      type = types.nullOr types.path;
+      default = null;
+      description = ''
+        Path to a mikrotik exporter configuration file. Mutually exclusive with
+        <option>configuration</option> option.
+      '';
+      example = literalExample "./mikrotik.yml";
+    };
+
+    configuration = mkOption {
+      type = types.nullOr types.attrs;
+      default = null;
+      description = ''
+        Mikrotik exporter configuration as nix attribute set. Mutually exclusive with
+        <option>configFile</option> option.
+
+        See <link xlink:href="https://github.com/nshttpd/mikrotik-exporter/blob/master/README.md"/>
+        for the description of the configuration file format.
+      '';
+      example = literalExample ''
+        {
+          devices = [
+            {
+              name = "my_router";
+              address = "10.10.0.1";
+              user = "prometheus";
+              password = "changeme";
+            }
+          ];
+          features = {
+            bgp = true;
+            dhcp = true;
+            routes = true;
+            optics = true;
+          };
+        }
+      '';
+    };
+  };
+  serviceOpts = let
+    configFile = if cfg.configFile != null
+                 then cfg.configFile
+                 else "${pkgs.writeText "mikrotik-exporter.yml" (builtins.toJSON cfg.configuration)}";
+    in {
+    serviceConfig = {
+      # -port is misleading name, it actually accepts address too
+      ExecStart = ''
+        ${pkgs.prometheus-mikrotik-exporter}/bin/mikrotik-exporter \
+          -config-file=${escapeShellArg configFile} \
+          -port=${cfg.listenAddress}:${toString cfg.port} \
+          ${concatStringsSep " \\\n  " cfg.extraFlags}
+      '';
+    };
+  };
+}