about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus/exporters/snmp.nix
diff options
context:
space:
mode:
authorWilliButz <wbutz@cyberfnord.de>2018-03-09 21:33:09 +0100
committerWilliButz <wbutz@cyberfnord.de>2018-03-22 14:46:17 +0100
commitf4d03b5c9cf2b694792dec88e3ca805cf7b43e3c (patch)
tree3cb553f10849b086f3c15ad3de2dfc55243d31c8 /nixos/modules/services/monitoring/prometheus/exporters/snmp.nix
parentf2bd9d4745041fe0c0a49803094dd625ebd27342 (diff)
downloadnixlib-f4d03b5c9cf2b694792dec88e3ca805cf7b43e3c.tar
nixlib-f4d03b5c9cf2b694792dec88e3ca805cf7b43e3c.tar.gz
nixlib-f4d03b5c9cf2b694792dec88e3ca805cf7b43e3c.tar.bz2
nixlib-f4d03b5c9cf2b694792dec88e3ca805cf7b43e3c.tar.lz
nixlib-f4d03b5c9cf2b694792dec88e3ca805cf7b43e3c.tar.xz
nixlib-f4d03b5c9cf2b694792dec88e3ca805cf7b43e3c.tar.zst
nixlib-f4d03b5c9cf2b694792dec88e3ca805cf7b43e3c.zip
nixos/prometheus-exporters: rewrite and restructure
- prometheus exporters are now configured with
  `services.prometheus.exporters.<name>`
- the exporters are now defined by attribute sets
  from which the options for each exporter are generated
- most of the exporter definitions are used unchanged,
  except for some changes that should't have any impact
  on the functionality.
Diffstat (limited to 'nixos/modules/services/monitoring/prometheus/exporters/snmp.nix')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/snmp.nix71
1 files changed, 71 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/snmp.nix b/nixos/modules/services/monitoring/prometheus/exporters/snmp.nix
new file mode 100644
index 000000000000..404cd0a1896b
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/snmp.nix
@@ -0,0 +1,71 @@
+{ config, lib, pkgs }:
+
+with lib;
+
+let
+  cfg = config.services.prometheus.exporters.snmp;
+in
+{
+  port = 9116;
+  extraOpts = {
+    configurationPath = mkOption {
+      type = types.nullOr types.path;
+      default = null;
+      description = ''
+        Path to a snmp exporter configuration file. Mutually exclusive with 'configuration' option.
+      '';
+      example = "./snmp.yml";
+    };
+
+    configuration = mkOption {
+      type = types.nullOr types.attrs;
+      default = {};
+      description = ''
+        Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option.
+      '';
+      example = ''
+        {
+          "default" = {
+            "version" = 2;
+            "auth" = {
+              "community" = "public";
+            };
+          };
+        };
+      '';
+    };
+
+    logFormat = mkOption {
+      type = types.str;
+      default = "logger:stderr";
+      description = ''
+        Set the log target and format.
+      '';
+    };
+
+    logLevel = mkOption {
+      type = types.enum ["debug" "info" "warn" "error" "fatal"];
+      default = "info";
+      description = ''
+        Only log messages with the given severity or above.
+      '';
+    };
+  };
+  serviceOpts = let
+    configFile = if cfg.configurationPath != null
+                 then cfg.configurationPath
+                 else "${pkgs.writeText "snmp-eporter-conf.yml" (builtins.toJSON cfg.configuration)}";
+    in {
+    serviceConfig = {
+      DynamicUser = true;
+      ExecStart = ''
+        ${pkgs.prometheus-snmp-exporter.bin}/bin/snmp_exporter \
+          -config.file ${configFile} \
+          -log.format ${cfg.logFormat} \
+          -log.level ${cfg.logLevel} \
+          -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
+          ${concatStringsSep " \\\n  " cfg.extraFlags}
+      '';
+    };
+  };
+}