nixos/ocsinventory-agent: init

This commit is contained in:
Anthony Roussel 2023-11-02 01:28:05 +01:00
parent 02ee793341
commit efdbdab8b5
No known key found for this signature in database
GPG Key ID: 9DC4987B1A55E75E
3 changed files with 168 additions and 0 deletions

View File

@ -797,6 +797,7 @@
./services/monitoring/munin.nix
./services/monitoring/nagios.nix
./services/monitoring/netdata.nix
./services/monitoring/ocsinventory-agent.nix
./services/monitoring/opentelemetry-collector.nix
./services/monitoring/osquery.nix
./services/monitoring/parsedmarc.nix

View File

@ -0,0 +1,33 @@
# OCS Inventory Agent {#module-services-ocsinventory-agent}
[OCS Inventory NG](https://ocsinventory-ng.org/) or Open Computers and Software inventory
is an application designed to help IT administrator to keep track of the hardware and software
configurations of computers that are installed on their network.
OCS Inventory collects information about the hardware and software of networked machines
through the **OCS Inventory Agent** program.
This NixOS module enables you to install and configure this agent so that it sends information from your computer to the OCS Inventory server.
For more technical information about OCS Inventory Agent, refer to [the Wiki documentation](https://wiki.ocsinventory-ng.org/03.Basic-documentation/Setting-up-the-UNIX-agent-manually-on-client-computers/).
## Basic Usage {#module-services-ocsinventory-agent-basic-usage}
A minimal configuration looks like this:
```nix
{
services.ocsinventory-agent = {
enable = true;
settings = {
server = "https://ocsinventory.localhost:8080/ocsinventory";
tag = "01234567890123";
};
};
}
```
This configuration will periodically run the ocsinventory-agent SystemD service.
The OCS Inventory Agent will inventory the computer and then sends the results to the specified OCS Inventory Server.

View File

@ -0,0 +1,134 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.ocsinventory-agent;
settingsFormat = pkgs.formats.keyValue {
mkKeyValue = lib.generators.mkKeyValueDefault { } "=";
};
in
{
meta = {
doc = ./ocsinventory-agent.md;
maintainers = with lib.maintainers; [ anthonyroussel ];
};
options = {
services.ocsinventory-agent = {
enable = lib.mkEnableOption (lib.mdDoc "OCS Inventory Agent");
package = lib.mkPackageOptionMD pkgs "ocsinventory-agent" { };
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type.nestedTypes.elemType;
options = {
server = lib.mkOption {
type = lib.types.nullOr lib.types.str;
example = "https://ocsinventory.localhost:8080/ocsinventory";
default = null;
description = lib.mdDoc ''
The URI of the OCS Inventory server where to send the inventory file.
This option is ignored if {option}`services.ocsinventory-agent.settings.local` is set.
'';
};
local = lib.mkOption {
type = lib.types.nullOr lib.types.path;
example = "/var/lib/ocsinventory-agent/reports";
default = null;
description = lib.mdDoc ''
If specified, the OCS Inventory Agent will run in offline mode
and the resulting inventory file will be stored in the specified path.
'';
};
ca = lib.mkOption {
type = lib.types.path;
default = "/etc/ssl/certs/ca-certificates.crt";
description = lib.mdDoc ''
Path to CA certificates file in PEM format, for server
SSL certificate validation.
'';
};
tag = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "01234567890123";
description = lib.mdDoc "Tag for the generated inventory.";
};
debug = lib.mkEnableOption (lib.mdDoc "debug mode");
};
};
default = { };
example = {
ca = "/etc/ssl/certs/ca-certificates.crt";
debug = true;
server = "https://ocsinventory.localhost:8080/ocsinventory";
tag = "01234567890123";
};
description = lib.mdDoc ''
Configuration for /etc/ocsinventory-agent/ocsinventory-agent.cfg.
Refer to
{manpage}`ocsinventory-agent(1)` for available options.
'';
};
interval = lib.mkOption {
type = lib.types.str;
default = "daily";
example = "06:00";
description = lib.mdDoc ''
How often we run the ocsinventory-agent service. Runs by default every daily.
The format is described in
{manpage}`systemd.time(7)`.
'';
};
};
};
config =
let
configFile = settingsFormat.generate "ocsinventory-agent.cfg" cfg.settings;
in lib.mkIf cfg.enable {
# Path of the configuration file is hard-coded and cannot be changed
# https://github.com/OCSInventory-NG/UnixAgent/blob/v2.10.0/lib/Ocsinventory/Agent/Config.pm#L78
#
environment.etc."ocsinventory-agent/ocsinventory-agent.cfg".source = configFile;
systemd.services.ocsinventory-agent = {
description = "OCS Inventory Agent service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
reloadTriggers = [ configFile ];
serviceConfig = {
ExecStart = lib.getExe cfg.package;
ConfigurationDirectory = "ocsinventory-agent";
StateDirectory = "ocsinventory-agent";
};
};
systemd.timers.ocsinventory-agent = {
description = "Launch OCS Inventory Agent regularly";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = cfg.interval;
AccuracySec = "1h";
RandomizedDelaySec = 240;
Persistent = true;
Unit = "ocsinventory-agent.service";
};
};
};
}