diff --git a/lib/netconf-junos/default.nix b/lib/netconf-junos/default.nix index 1ba1769..41b9b6c 100644 --- a/lib/netconf-junos/default.nix +++ b/lib/netconf-junos/default.nix @@ -41,6 +41,7 @@ in ./system.nix ./vlans.nix ./routing-options.nix + ./snmp.nix ]; options = { @@ -102,6 +103,7 @@ in ${poe} ${access} ${routing-options} + ${snmp} ''; rpc = pkgs.writeText "${name}.rpc" '' diff --git a/lib/netconf-junos/snmp.nix b/lib/netconf-junos/snmp.nix new file mode 100644 index 0000000..1e58c13 --- /dev/null +++ b/lib/netconf-junos/snmp.nix @@ -0,0 +1,80 @@ +# SPDX-FileCopyrightText: 2025 Lubin Bailly +# +# SPDX-License-Identifier: EUPL-1.2 + +{ lib, config, ... }: +let + inherit (lib) + concatMapAttrsStringSep + mkOption + optionalString + ; + inherit (lib.types) + attrsOf + bool + enum + str + submodule + ; +in +{ + options = { + snmp = { + filter-interfaces.all-internal-interfaces = mkOption { + type = bool; + default = false; + description = '' + Whether to filter internal interfaces. + ''; + }; + community = mkOption { + type = attrsOf ( + submodule ( + { name, config, ... }: + { + options = { + authorization = mkOption { + type = enum [ + "read-only" + "read-write" + ]; + description = '' + Authorization type. + ''; + }; + xml = mkOption { + type = str; + visible = false; + readOnly = true; + }; + }; + config.xml = '' + + ${name} + ${config.authorization} + + ''; + } + ) + ); + default = { }; + description = '' + Communities for SNMPv2 access. + ''; + }; + }; + netconf.xmls.snmp = mkOption { + type = str; + visible = false; + readOnly = true; + }; + }; + config.netconf.xmls.snmp = '' + + + ${optionalString config.snmp.filter-interfaces.all-internal-interfaces ""} + + ${concatMapAttrsStringSep "" (_: comm: comm.xml) config.snmp.community} + + ''; +}