1 import ./make-test-python.nix (
4 meta = with pkgs.lib.maintainers; {
5 maintainers = [ symphorien ];
8 nodes.machine = { lib, ... }: let
9 writer = pkgs.writeShellScript "write" ''
11 echo "$@" >> /tmp/notifications
16 services.sshd.enable = true;
20 # make state transitions faster
21 extraConfig.interval_length = "5";
23 (map (x: "${pkgs.nagios}/etc/objects/${x}.cfg") [ "templates" "timeperiods" "commands" ]) ++ [
25 pkgs.writeText "objects.cfg" ''
26 # notifications are written to /tmp/notifications
28 command_name notify-host-by-file
29 command_line ${writer} "$HOSTNAME is $HOSTSTATE$"
32 command_name notify-service-by-file
33 command_line ${writer} "$SERVICEDESC$ is $SERVICESTATE$"
40 host_notifications_enabled 1
41 service_notifications_enabled 1
42 service_notification_period 24x7
43 host_notification_period 24x7
44 service_notification_options w,u,c,r,f,s
45 host_notification_options d,u,r,f,s
46 service_notification_commands notify-service-by-file
47 host_notification_commands notify-host-by-file
51 contactgroup_name admins
56 hostgroup_name allhosts
68 # make state transitions faster.
76 service_description ssh
77 check_command check_ssh
78 # make state transitions faster.
89 testScript = { ... }: ''
90 with subtest("ensure sshd starts"):
91 machine.wait_for_unit("sshd.service")
94 with subtest("ensure nagios starts"):
95 machine.wait_for_file("/var/log/nagios/current")
98 def assert_notify(text):
99 machine.wait_for_file("/tmp/notifications")
100 real = machine.succeed("cat /tmp/notifications").strip()
101 print(f"got {real!r}, expected {text!r}")
105 with subtest("ensure we get a notification when sshd is down"):
106 machine.succeed("systemctl stop sshd")
107 assert_notify("ssh is CRITICAL")
110 with subtest("ensure tests can succeed"):
111 machine.succeed("systemctl start sshd")
112 machine.succeed("rm /tmp/notifications")
113 assert_notify("ssh is OK")