at 17.09-beta 2.1 kB view raw
1# Zabbix agent daemon. 2{ config, lib, pkgs, ... }: 3 4with lib; 5 6let 7 8 cfg = config.services.zabbixAgent; 9 10 stateDir = "/var/run/zabbix"; 11 12 logDir = "/var/log/zabbix"; 13 14 pidFile = "${stateDir}/zabbix_agentd.pid"; 15 16 configFile = pkgs.writeText "zabbix_agentd.conf" 17 '' 18 Server = ${cfg.server} 19 20 LogFile = ${logDir}/zabbix_agentd 21 22 PidFile = ${pidFile} 23 24 StartAgents = 1 25 26 ${config.services.zabbixAgent.extraConfig} 27 ''; 28 29in 30 31{ 32 33 ###### interface 34 35 options = { 36 37 services.zabbixAgent = { 38 39 enable = mkOption { 40 default = false; 41 description = '' 42 Whether to run the Zabbix monitoring agent on this machine. 43 It will send monitoring data to a Zabbix server. 44 ''; 45 }; 46 47 server = mkOption { 48 default = "127.0.0.1"; 49 description = '' 50 The IP address or hostname of the Zabbix server to connect to. 51 ''; 52 }; 53 54 extraConfig = mkOption { 55 default = ""; 56 type = types.lines; 57 description = '' 58 Configuration that is injected verbatim into the configuration file. 59 ''; 60 }; 61 62 }; 63 64 }; 65 66 67 ###### implementation 68 69 config = mkIf cfg.enable { 70 71 users.extraUsers = mkIf (!config.services.zabbixServer.enable) (singleton 72 { name = "zabbix"; 73 uid = config.ids.uids.zabbix; 74 description = "Zabbix daemon user"; 75 }); 76 77 systemd.services."zabbix-agent" = 78 { description = "Zabbix Agent"; 79 80 wantedBy = [ "multi-user.target" ]; 81 82 path = [ pkgs.nettools ]; 83 84 preStart = 85 '' 86 mkdir -m 0755 -p ${stateDir} ${logDir} 87 chown zabbix ${stateDir} ${logDir} 88 ''; 89 90 serviceConfig.ExecStart = "@${pkgs.zabbix.agent}/sbin/zabbix_agentd zabbix_agentd --config ${configFile}"; 91 serviceConfig.Type = "forking"; 92 serviceConfig.RemainAfterExit = true; 93 serviceConfig.Restart = "always"; 94 serviceConfig.RestartSec = 2; 95 }; 96 97 environment.systemPackages = [ pkgs.zabbix.agent ]; 98 99 }; 100 101}