| 
									
										
										
										
											2008-11-18 18:00:21 +00:00
										 |  |  | # Zabbix agent daemon. | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2008-11-18 18:00:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | let | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-08 22:21:56 +00:00
										 |  |  |   cfg = config.services.zabbixAgent; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  |   stateDir = "/var/run/zabbix"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   logDir = "/var/log/zabbix"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   pidFile = "${stateDir}/zabbix_agentd.pid"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |   configFile = pkgs.writeText "zabbix_agentd.conf" | 
					
						
							|  |  |  |     ''
 | 
					
						
							|  |  |  |       Server = ${cfg.server} | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       LogFile = ${logDir}/zabbix_agentd | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       PidFile = ${pidFile} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 17:13:43 +00:00
										 |  |  |       StartAgents = 1 | 
					
						
							| 
									
										
										
										
											2010-02-16 12:51:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       ${config.services.zabbixAgent.extraConfig} | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |     '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | in | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### interface | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |     services.zabbixAgent = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether to run the Zabbix monitoring agent on this machine. | 
					
						
							|  |  |  |           It will send monitoring data to a Zabbix server. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       server = mkOption { | 
					
						
							|  |  |  |         default = "127.0.0.1"; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           The IP address or hostname of the Zabbix server to connect to. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-16 12:51:28 +00:00
										 |  |  |       extraConfig = mkOption { | 
					
						
							|  |  |  |         default = ""; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Configuration that is injected verbatim into the configuration file. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 18:00:21 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 16:16:16 +02:00
										 |  |  |     users.extraUsers = mkIf (!config.services.zabbixServer.enable) (singleton | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       { name = "zabbix"; | 
					
						
							|  |  |  |         uid = config.ids.uids.zabbix; | 
					
						
							|  |  |  |         description = "Zabbix daemon user"; | 
					
						
							| 
									
										
										
										
											2014-04-30 16:16:16 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 12:33:18 +01:00
										 |  |  |     systemd.services."zabbix-agent" = | 
					
						
							| 
									
										
										
										
											2012-10-26 15:15:26 +02:00
										 |  |  |       { description = "Zabbix Agent"; | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-26 15:15:26 +02:00
										 |  |  |         wantedBy = [ "multi-user.target" ]; | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-26 15:15:26 +02:00
										 |  |  |         path = [ pkgs.nettools ]; | 
					
						
							| 
									
										
										
										
											2012-03-19 19:43:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |         preStart = | 
					
						
							|  |  |  |           ''
 | 
					
						
							|  |  |  |             mkdir -m 0755 -p ${stateDir} ${logDir} | 
					
						
							|  |  |  |             chown zabbix ${stateDir} ${logDir} | 
					
						
							| 
									
										
										
										
											2010-02-16 10:15:20 +00:00
										 |  |  |           '';
 | 
					
						
							| 
									
										
										
										
											2010-02-15 17:13:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-26 15:15:26 +02:00
										 |  |  |         serviceConfig.ExecStart = "@${pkgs.zabbix.agent}/sbin/zabbix_agentd zabbix_agentd --config ${configFile}"; | 
					
						
							|  |  |  |         serviceConfig.Type = "forking"; | 
					
						
							| 
									
										
										
										
											2012-12-11 20:54:19 +01:00
										 |  |  |         serviceConfig.RemainAfterExit = true; | 
					
						
							| 
									
										
										
										
											2012-10-26 15:15:26 +02:00
										 |  |  |         serviceConfig.Restart = "always"; | 
					
						
							|  |  |  |         serviceConfig.RestartSec = 2; | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2008-11-18 18:00:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 17:13:43 +00:00
										 |  |  |     environment.systemPackages = [ pkgs.zabbix.agent ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 18:00:21 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2009-10-12 16:36:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-06 09:13:16 +00:00
										 |  |  | } |