Merge pull request #281278 from Moraxyc/nezha-agent

This commit is contained in:
Sandro 2024-04-06 12:35:07 +02:00 committed by GitHub
commit 4e6092c8cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 155 additions and 0 deletions

View File

@ -13379,6 +13379,12 @@
githubId = 830082;
name = "Nathan Moos";
};
moraxyc = {
name = "Moraxyc Xu";
email = "nix@qaq.li";
github = "Moraxyc";
githubId = 69713071;
};
moredread = {
email = "code@apb.name";
github = "Moredread";

View File

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

View File

@ -0,0 +1,103 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.nezha-agent;
in
{
meta = {
maintainers = with lib.maintainers; [ moraxyc ];
};
options = {
services.nezha-agent = {
enable = lib.mkEnableOption (lib.mdDoc "Agent of Nezha Monitoring");
package = lib.mkPackageOption pkgs "nezha-agent" { };
debug = lib.mkEnableOption (lib.mdDoc "verbose log");
tls = lib.mkOption {
type = lib.types.bool;
default = false;
description = lib.mdDoc ''
Enable SSL/TLS encryption.
'';
};
disableCommandExecute = lib.mkOption {
type = lib.types.bool;
default = true;
description = lib.mdDoc ''
Disable executing the command from dashboard.
'';
};
skipConnection = lib.mkOption {
type = lib.types.bool;
default = false;
description = lib.mdDoc ''
Do not monitor the number of connections.
'';
};
skipProcess = lib.mkOption {
type = lib.types.bool;
default = false;
description = lib.mdDoc ''
Do not monitor the number of processes.
'';
};
reportDelay = lib.mkOption {
type = lib.types.enum [ 1 2 3 4 ];
default = 1;
description = lib.mdDoc ''
The interval between system status reportings.
The value must be an integer from 1 to 4
'';
};
passwordFile = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = lib.mdDoc ''
Path to the file contained the password from dashboard.
'';
};
server = lib.mkOption {
type = lib.types.str;
description = lib.mdDoc ''
Address to the dashboard
'';
};
};
};
config = lib.mkIf cfg.enable {
systemd.packages = [ cfg.package ];
systemd.services.nezha-agent = {
serviceConfig = {
ProtectSystem = "full";
PrivateDevices = "yes";
PrivateTmp = "yes";
NoNewPrivileges = true;
};
path = [ cfg.package ];
startLimitIntervalSec = 10;
startLimitBurst = 3;
script = lib.concatStringsSep " " (
[
"${cfg.package}/bin/agent"
"--disable-auto-update"
"--disable-force-update"
"--password $(cat ${cfg.passwordFile})"
]
++ lib.optional cfg.debug "--debug"
++ lib.optional cfg.disableCommandExecute "--disable-command-execute"
++ lib.optional (cfg.reportDelay != null) "--report-delay ${toString cfg.reportDelay}"
++ lib.optional (cfg.server != null) "--server ${cfg.server}"
++ lib.optional cfg.skipConnection "--skip-conn"
++ lib.optional cfg.skipProcess "--skip-procs"
++ lib.optional cfg.tls "--tls"
);
wantedBy = [ "multi-user.target" ];
};
};
}

View File

@ -0,0 +1,45 @@
{
lib,
buildGoModule,
fetchFromGitHub,
nezha-agent,
testers,
}:
buildGoModule rec {
pname = "nezha-agent";
version = "0.16.4";
src = fetchFromGitHub {
owner = "nezhahq";
repo = "agent";
rev = "v${version}";
hash = "sha256-xXv2FVPsl8BR51VMrFreaS3UQLEJwfObY4OeMMb8pms=";
};
vendorHash = "sha256-ZlheRFgl3vsUXVx8PKZQ59kme2NC31OQAL6EaNhbf70=";
ldflags = [
"-s"
"-w"
"-X main.version=${version}"
];
# The test failed due to a geoip request in the sandbox. Remove it to avoid network requirement
preCheck = ''
rm ./pkg/monitor/myip_test.go
'';
passthru.tests = {
version = testers.testVersion {
package = nezha-agent;
command = "${nezha-agent}/bin/agent -v";
};
};
meta = with lib; {
description = "Agent of Nezha Monitoring";
homepage = "https://github.com/nezhahq/agent";
license = licenses.asl20;
maintainers = with maintainers; [moraxyc];
};
}