Merge pull request #264910 from anthonyroussel/ocsinventory-agent+nixos
nixos/ocsinventory-agent: init
This commit is contained in:
@@ -799,6 +799,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
|
||||
|
||||
@@ -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.
|
||||
@@ -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";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -616,6 +616,7 @@ in {
|
||||
openstack-image-userdata = (handleTestOn ["x86_64-linux"] ./openstack-image.nix {}).userdata or {};
|
||||
opentabletdriver = handleTest ./opentabletdriver.nix {};
|
||||
opentelemetry-collector = handleTest ./opentelemetry-collector.nix {};
|
||||
ocsinventory-agent = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./ocsinventory-agent.nix {};
|
||||
owncast = handleTest ./owncast.nix {};
|
||||
outline = handleTest ./outline.nix {};
|
||||
image-contents = handleTest ./image-contents.nix {};
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import ./make-test-python.nix ({ pkgs, ...} : {
|
||||
name = "ocsinventory-agent";
|
||||
|
||||
nodes.machine = { pkgs, ... }: {
|
||||
services.ocsinventory-agent = {
|
||||
enable = true;
|
||||
settings = {
|
||||
debug = true;
|
||||
local = "/var/lib/ocsinventory-agent/reports";
|
||||
tag = "MY_INVENTORY_TAG";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
path = "/var/lib/ocsinventory-agent/reports"
|
||||
|
||||
# Run the agent to generate the inventory file in offline mode
|
||||
start_all()
|
||||
machine.succeed("mkdir -p {}".format(path))
|
||||
machine.wait_for_unit("ocsinventory-agent.service")
|
||||
machine.wait_until_succeeds("journalctl -u ocsinventory-agent.service | grep 'Inventory saved in'")
|
||||
|
||||
# Fetch the path to the generated inventory file
|
||||
report_file = machine.succeed("find {}/*.ocs -type f | head -n1".format(path))
|
||||
|
||||
with subtest("Check the tag value"):
|
||||
tag = machine.succeed(
|
||||
"${pkgs.libxml2}/bin/xmllint --xpath 'string(/REQUEST/CONTENT/ACCOUNTINFO/KEYVALUE)' {}".format(report_file)
|
||||
).rstrip()
|
||||
assert tag == "MY_INVENTORY_TAG", f"tag is not valid, was '{tag}'"
|
||||
'';
|
||||
})
|
||||
@@ -15,6 +15,7 @@
|
||||
, pciutils
|
||||
, usbutils
|
||||
, util-linux
|
||||
, nixosTests
|
||||
, testers
|
||||
, ocsinventory-agent
|
||||
, nix-update-script
|
||||
@@ -75,11 +76,14 @@ perlPackages.buildPerlPackage rec {
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
tests.version = testers.testVersion {
|
||||
package = ocsinventory-agent;
|
||||
command = "ocsinventory-agent --version";
|
||||
# upstream has not updated version in lib/Ocsinventory/Agent/Config.pm
|
||||
version = "2.10.0";
|
||||
tests = {
|
||||
inherit (nixosTests) ocsinventory-agent;
|
||||
version = testers.testVersion {
|
||||
package = ocsinventory-agent;
|
||||
command = "ocsinventory-agent --version";
|
||||
# upstream has not updated version in lib/Ocsinventory/Agent/Config.pm
|
||||
version = "2.10.0";
|
||||
};
|
||||
};
|
||||
updateScript = nix-update-script { };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user