Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prometheus-snmp-exporter: 0.22.0 -> 0.25.0 #251882

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nixos/doc/manual/release-notes/rl-2405.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m
- `security.pam.enableSSHAgentAuth` now requires `services.openssh.authorizedKeysFiles` to be non-empty,
which is the case when `services.openssh.enable` is true. Previously, `pam_ssh_agent_auth` silently failed to work.

- The configuration format for `services.prometheus.exporters.snmp` changed with release 0.23.0.
The module now includes an optional config check, that is enabled by default, to make the change obvious before any deployment.
More information about the configuration syntax change is available in the [upstream repository](https://github.com/prometheus/snmp_exporter/blob/b75fc6b839ee3f3ccbee68bee55f1ae99555084a/auth-split-migration.md).

## Other Notable Changes {#sec-release-24.05-notable-changes}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
47 changes: 39 additions & 8 deletions nixos/modules/services/monitoring/prometheus/exporters/snmp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ with lib;

let
cfg = config.services.prometheus.exporters.snmp;

# This ensures that we can deal with string paths, path types and
# store-path strings with context.
coerceConfigFile = file:
if (builtins.isPath file) || (lib.isStorePath file) then
file
else
(lib.warn ''
${logPrefix}: configuration file "${file}" is being copied to the nix-store.
If you would like to avoid that, please set enableConfigCheck to false.
'' /. + file);

checkConfig = file:
pkgs.runCommandLocal "checked-snmp-exporter-config.yml" {
nativeBuildInputs = [ pkgs.buildPackages.prometheus-snmp-exporter ];
} ''
ln -s ${coerceConfigFile file} $out
snmp_exporter --dry-run --config.file $out
'';
in
{
port = 9116;
Expand All @@ -24,15 +43,23 @@ in
Snmp exporter configuration as nix attribute set. Mutually exclusive with 'configurationPath' option.
'';
example = {
"default" = {
"version" = 2;
"auth" = {
"community" = "public";
};
auths.public_v2 = {
community = "public";
version = 2;
};
};
};

enableConfigCheck = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Whether to run a correctness check for the configuration file. This depends
on the configuration file residing in the nix-store. Paths passed as string will
be copied to the store.
'';
};

logFormat = mkOption {
type = types.enum ["logfmt" "json"];
default = "logfmt";
Expand All @@ -50,9 +77,13 @@ in
};
};
serviceOpts = let
configFile = if cfg.configurationPath != null
then cfg.configurationPath
else "${pkgs.writeText "snmp-exporter-conf.yml" (builtins.toJSON cfg.configuration)}";
uncheckedConfigFile = if cfg.configurationPath != null
then cfg.configurationPath
else "${pkgs.writeText "snmp-exporter-conf.yml" (builtins.toJSON cfg.configuration)}";
configFile = if cfg.enableConfigCheck then
checkConfig uncheckedConfigFile
else
uncheckedConfigFile;
in {
serviceConfig = {
ExecStart = ''
Expand Down
8 changes: 5 additions & 3 deletions nixos/tests/prometheus-exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1392,9 +1392,11 @@ let
snmp = {
exporterConfig = {
enable = true;
configuration.default = {
version = 2;
auth.community = "public";
configuration = {
auths.public_v2 = {
community = "public";
version = 2;
};
};
};
exporterTest = ''
Expand Down
8 changes: 4 additions & 4 deletions pkgs/servers/monitoring/prometheus/snmp-exporter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

buildGoModule rec {
pname = "snmp_exporter";
version = "0.22.0";
version = "0.25.0";

src = fetchFromGitHub {
owner = "prometheus";
repo = "snmp_exporter";
rev = "v${version}";
sha256 = "sha256-HncffOX0/z8XIEXTOkt6bcnAfY7xwgNBGhUwC3FIJjo=";
sha256 = "sha256-6Y2zJwY5gToJlY6iLug2jNXXtNLNz98WoTKGcWgYzaA=";
};

vendorHash = "sha256-n0LPKmGPxLZgvzdpyuE67WOJv7MKN28m7PtQpWYdtMk=";
vendorHash = "sha256-8soLDI/hBzSZB6Lfj1jVkIWfIkMPJmp84bu7TKg7jeo=";

buildInputs = [ net-snmp ];

Expand All @@ -23,6 +23,6 @@ buildGoModule rec {
description = "SNMP Exporter for Prometheus";
homepage = "https://github.com/prometheus/snmp_exporter";
license = licenses.asl20;
maintainers = with maintainers; [ oida willibutz Frostman ];
maintainers = with maintainers; [ oida Frostman ];
};
}