at 25.11-pre 5.8 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7with lib; 8let 9 cfg = config.services.icingaweb2.modules.monitoring; 10 11 configIni = '' 12 [security] 13 protected_customvars = "${concatStringsSep "," cfg.generalConfig.protectedVars}" 14 ''; 15 16 backendsIni = 17 let 18 formatBool = b: if b then "1" else "0"; 19 in 20 concatStringsSep "\n" ( 21 mapAttrsToList (name: config: '' 22 [${name}] 23 type = "ido" 24 resource = "${config.resource}" 25 disabled = "${formatBool config.disabled}" 26 '') cfg.backends 27 ); 28 29 transportsIni = concatStringsSep "\n" ( 30 mapAttrsToList (name: config: '' 31 [${name}] 32 type = "${config.type}" 33 ${optionalString (config.instance != null) ''instance = "${config.instance}"''} 34 ${optionalString (config.type == "local" || config.type == "remote") ''path = "${config.path}"''} 35 ${optionalString (config.type != "local") '' 36 host = "${config.host}" 37 ${optionalString (config.port != null) ''port = "${toString config.port}"''} 38 user${optionalString (config.type == "api") "name"} = "${config.username}" 39 ''} 40 ${optionalString (config.type == "api") ''password = "${config.password}"''} 41 ${optionalString (config.type == "remote") ''resource = "${config.resource}"''} 42 '') cfg.transports 43 ); 44 45in 46{ 47 options.services.icingaweb2.modules.monitoring = with types; { 48 enable = mkOption { 49 type = bool; 50 default = true; 51 description = "Whether to enable the icingaweb2 monitoring module."; 52 }; 53 54 generalConfig = { 55 mutable = mkOption { 56 type = bool; 57 default = false; 58 description = "Make config.ini of the monitoring module mutable (e.g. via the web interface)."; 59 }; 60 61 protectedVars = mkOption { 62 type = listOf str; 63 default = [ 64 "*pw*" 65 "*pass*" 66 "community" 67 ]; 68 description = "List of string patterns for custom variables which should be excluded from users view."; 69 }; 70 }; 71 72 mutableBackends = mkOption { 73 type = bool; 74 default = false; 75 description = "Make backends.ini of the monitoring module mutable (e.g. via the web interface)."; 76 }; 77 78 backends = mkOption { 79 default = { 80 icinga = { 81 resource = "icinga_ido"; 82 }; 83 }; 84 description = "Monitoring backends to define"; 85 type = attrsOf ( 86 submodule ( 87 { name, ... }: 88 { 89 options = { 90 name = mkOption { 91 visible = false; 92 default = name; 93 type = str; 94 description = "Name of this backend"; 95 }; 96 97 resource = mkOption { 98 type = str; 99 description = "Name of the IDO resource"; 100 }; 101 102 disabled = mkOption { 103 type = bool; 104 default = false; 105 description = "Disable this backend"; 106 }; 107 }; 108 } 109 ) 110 ); 111 }; 112 113 mutableTransports = mkOption { 114 type = bool; 115 default = true; 116 description = "Make commandtransports.ini of the monitoring module mutable (e.g. via the web interface)."; 117 }; 118 119 transports = mkOption { 120 default = { }; 121 description = "Command transports to define"; 122 type = attrsOf ( 123 submodule ( 124 { name, ... }: 125 { 126 options = { 127 name = mkOption { 128 visible = false; 129 default = name; 130 type = str; 131 description = "Name of this transport"; 132 }; 133 134 type = mkOption { 135 type = enum [ 136 "api" 137 "local" 138 "remote" 139 ]; 140 default = "api"; 141 description = "Type of this transport"; 142 }; 143 144 instance = mkOption { 145 type = nullOr str; 146 default = null; 147 description = "Assign a icinga instance to this transport"; 148 }; 149 150 path = mkOption { 151 type = str; 152 description = "Path to the socket for local or remote transports"; 153 }; 154 155 host = mkOption { 156 type = str; 157 description = "Host for the api or remote transport"; 158 }; 159 160 port = mkOption { 161 type = nullOr str; 162 default = null; 163 description = "Port to connect to for the api or remote transport"; 164 }; 165 166 username = mkOption { 167 type = str; 168 description = "Username for the api or remote transport"; 169 }; 170 171 password = mkOption { 172 type = str; 173 description = "Password for the api transport"; 174 }; 175 176 resource = mkOption { 177 type = str; 178 description = "SSH identity resource for the remote transport"; 179 }; 180 }; 181 } 182 ) 183 ); 184 }; 185 }; 186 187 config = mkIf (config.services.icingaweb2.enable && cfg.enable) { 188 environment.etc = 189 { 190 "icingaweb2/enabledModules/monitoring" = { 191 source = "${pkgs.icingaweb2}/modules/monitoring"; 192 }; 193 } 194 // optionalAttrs (!cfg.generalConfig.mutable) { 195 "icingaweb2/modules/monitoring/config.ini".text = configIni; 196 } 197 // optionalAttrs (!cfg.mutableBackends) { 198 "icingaweb2/modules/monitoring/backends.ini".text = backendsIni; 199 } 200 // optionalAttrs (!cfg.mutableTransports) { 201 "icingaweb2/modules/monitoring/commandtransports.ini".text = transportsIni; 202 }; 203 }; 204}