forked from NorfairKing/dnscheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
82 lines (79 loc) · 2.09 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{ lib, pkgs, config, ... }:
with lib;
let
dnscheck = (import ../.).dnscheck;
dnsCheckConfig = ./dns-check-config.yaml;
cfg = config.services.dns-checker;
dnscheckName = "dns-checker";
dnscheckTimer = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "minutely";
Persistent = true;
};
};
configFile = pkgs.writeText "dnscheck-config-file" ''
checks: ${builtins.toJSON cfg.checks}
${cfg.extraVerbatimConfig}
'';
dnscheckService = {
description = "DNS Checker";
path = with pkgs; [
dnscheck
];
script = ''
set +e # We need error codes to work this way.
tmpfile=~/.dns-checker
${dnscheck}/bin/dnscheck ${configFile} 2>&1 > "$tmpfile"
if [[ "$?" != "0" ]]
then
cat "$tmpfile" | ${cfg.notifyCommand}
fi
rm -f "$tmpfile"
'';
};
in
{
options.services.dns-checker = {
enable = mkEnableOption "DNS Checker";
checks = mkOption {
default = [];
type = types.listOf (
types.submodule {
options = {
type = mkOption {
type = types.str;
example = "a";
description = "The type of record to check";
};
domain = mkOption {
type = types.str;
example = "cs-syd.eu";
description = "The domain to query";
};
values = mkOption {
type = types.listOf types.str;
example = [ "52.211.121.166" ];
default = [];
description = "The value to expect in the dns response";
};
};
}
);
};
extraVerbatimConfig = mkOption {
type = types.str;
default = "";
description = "Extra configuration, verbatim";
};
notifyCommand = mkOption {
type = types.str;
default = "false";
description = "The command to pass the output to in case of a failure";
};
};
config.systemd = mkIf cfg.enable {
timers = { "${dnscheckName}" = dnscheckTimer; };
services = { "${dnscheckName}" = dnscheckService; };
};
}