From 6a5dff7af0e7dc22b357eaadd13929e19823710d Mon Sep 17 00:00:00 2001 From: liberodark Date: Wed, 4 Dec 2024 14:39:54 +0100 Subject: [PATCH] nixos/glpi-agent: init --- .../manual/release-notes/rl-2505.section.md | 2 + nixos/modules/module-list.nix | 1 + .../services/monitoring/glpi-agent.nix | 91 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 nixos/modules/services/monitoring/glpi-agent.nix diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index 10645d55e838..0c0d83d1c736 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -16,6 +16,8 @@ - [Amazon CloudWatch Agent](https://github.com/aws/amazon-cloudwatch-agent), the official telemetry collector for AWS CloudWatch and AWS X-Ray. Available as [services.amazon-cloudwatch-agent](#opt-services.amazon-cloudwatch-agent.enable). +- [GLPI-Agent](https://github.com/glpi-project/glpi-agent), GLPI Agent. Available as [services.glpiAgent](options.html#opt-services.glpiAgent.enable). + ## Backward Incompatibilities {#sec-release-25.05-incompatibilities} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 91ecee0ef265..890b0dfa043e 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -896,6 +896,7 @@ ./services/monitoring/fusion-inventory.nix ./services/monitoring/gatus.nix ./services/monitoring/glances.nix + ./services/monitoring/glpi-agent.nix ./services/monitoring/goss.nix ./services/monitoring/grafana-agent.nix ./services/monitoring/grafana-image-renderer.nix diff --git a/nixos/modules/services/monitoring/glpi-agent.nix b/nixos/modules/services/monitoring/glpi-agent.nix new file mode 100644 index 000000000000..8ee18b5599bf --- /dev/null +++ b/nixos/modules/services/monitoring/glpi-agent.nix @@ -0,0 +1,91 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.glpiAgent; + + settingsType = + with lib.types; + attrsOf (oneOf [ + bool + int + str + (listOf str) + ]); + + formatValue = + v: + if lib.isBool v then + if v then "1" else "0" + else if lib.isList v then + lib.concatStringsSep "," v + else + toString v; + + configContent = lib.concatStringsSep "\n" ( + lib.mapAttrsToList (k: v: "${k} = ${formatValue v}") cfg.settings + ); + + configFile = pkgs.writeText "agent.cfg" configContent; + +in +{ + options = { + services.glpiAgent = { + enable = lib.mkEnableOption "GLPI Agent"; + + package = lib.mkPackageOption pkgs "glpi-agent" { }; + + settings = lib.mkOption { + type = settingsType; + default = { }; + description = '' + GLPI Agent configuration options. + See https://glpi-agent.readthedocs.io/en/latest/configuration.html for all available options. + + The 'server' option is mandatory and must point to your GLPI server. + ''; + example = lib.literalExpression '' + { + server = [ "https://glpi.example.com/inventory" ]; + delaytime = 3600; + tag = "production"; + logger = [ "stderr" "file" ]; + debug = 1; + "no-category" = [ "printer" "software" ]; + } + ''; + }; + + stateDir = lib.mkOption { + type = lib.types.str; + default = "/var/lib/glpi-agent"; + description = "Directory where GLPI Agent stores its state."; + }; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = cfg.settings ? server; + message = "GLPI Agent requires a server to be configured in services.glpiAgent.settings.server"; + } + ]; + + systemd.services.glpi-agent = { + description = "GLPI Agent"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + ExecStart = "${lib.getExe cfg.package} --conf-file ${configFile} --vardir ${cfg.stateDir} --daemon --no-fork"; + Restart = "on-failure"; + }; + }; + }; +}