Skip to content

Commit

Permalink
prometheus-snmp-exporter: added configurationPath option (NixOS#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
oida authored and globin committed Dec 1, 2016
1 parent 321a891 commit ab03491
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions nixos/modules/services/monitoring/prometheus/snmp-exporter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ with lib;

let
cfg = config.services.prometheus.snmpExporter;
mkConfigFile = pkgs.writeText "snmp.yml" (builtins.toJSON cfg.configuration);
mkConfigFile = pkgs.writeText "snmp.yml" (if cfg.configurationPath == null then builtins.toJSON cfg.configuration else builtins.readFile cfg.configurationPath);
in {
options = {
services.prometheus.snmpExporter = {
enable = mkEnableOption "prometheus snmp exporter";
enable = mkEnableOption "Prometheus snmp exporter";

user = mkOption {
type = types.str;
Expand Down Expand Up @@ -42,11 +42,30 @@ in {
'';
};

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.attrs;
type = types.nullOr types.attrs;
default = {};
description = ''
Snmp exporter configuration as nix attribute set.
Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option.
'';
example = ''
{
"default" = {
"version" = 2;
"auth" = {
"community" = "public";
};
};
};
'';
};

Expand Down Expand Up @@ -79,6 +98,12 @@ in {
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;

assertions = singleton
{
assertion = (cfg.configurationPath == null) != (cfg.configuration == null);
message = "Please ensure you have either 'configuration' or 'configurationPath' set!";
};

systemd.services.prometheus-snmp-exporter = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
Expand Down

0 comments on commit ab03491

Please sign in to comment.