Skip to content

Commit 87c00c3

Browse files
authored
Merge pull request flyingcircusio#908 from flyingcircusio/PL-132185-sensu-fix-check-ping
sensu: fix check_ping
2 parents 96b2e42 + eccab13 commit 87c00c3

File tree

2 files changed

+59
-24
lines changed

2 files changed

+59
-24
lines changed

pkgs/overlay.nix

+38-4
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,44 @@ in {
203203

204204
mysql = super.mariadb;
205205

206-
monitoring-plugins = super.monitoring-plugins.overrideAttrs(_: rec {
207-
postInstall = ''
208-
cp plugins-root/check_dhcp $out/bin
209-
cp plugins-root/check_icmp $out/bin
206+
monitoring-plugins = let
207+
binPath = lib.makeBinPath (with self; [
208+
(placeholder "out")
209+
"/run/wrappers"
210+
coreutils
211+
gnugrep
212+
gnused
213+
lm_sensors
214+
net-snmp
215+
procps
216+
unixtools.ping
217+
]);
218+
ping = "${self.unixtools.ping}/bin/ping";
219+
in
220+
super.monitoring-plugins.overrideAttrs(_: rec {
221+
# Taken from upstream postPatch, but with an absolute path for ping instead
222+
# of relying on PATH. Looks like PATH doesn't apply to check_ping (it's a C
223+
# program and not a script like other checks), so check_ping needs to
224+
# be compiled with the full path.
225+
postPatch = ''
226+
substituteInPlace po/Makefile.in.in \
227+
--replace /bin/sh ${self.runtimeShell}
228+
229+
sed -i configure.ac \
230+
-e 's|^DEFAULT_PATH=.*|DEFAULT_PATH=\"${binPath}\"|'
231+
232+
configureFlagsArray+=(
233+
--with-ping-command='${ping} -4 -n -U -w %d -c %d %s'
234+
--with-ping6-command='${ping} -6 -n -U -w %d -c %d %s'
235+
)
236+
'';
237+
238+
# These checks are not included by default.
239+
# Our platform doesn't use them, maybe some customer?
240+
# XXX: Remove in 24.05 if nobody needs it.
241+
postInstall = (super.monitoring-plugins.postInstall or "") + ''
242+
cp plugins-root/check_dhcp $out/bin
243+
cp plugins-root/check_icmp $out/bin
210244
'';
211245
});
212246

tests/sensuclient.nix

+21-20
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,28 @@ in
7474
};
7575
};
7676

77-
testScript =
78-
let
79-
in ''
80-
import json
81-
machine.wait_for_unit("rabbitmq.service")
82-
machine.wait_for_unit("prepare-rabbitmq-for-sensu.service")
83-
machine.wait_for_unit("sensu-client.service")
84-
machine.wait_for_open_port(3031)
77+
testScript = ''
78+
import json
79+
machine.wait_for_unit("rabbitmq.service")
80+
machine.wait_for_unit("prepare-rabbitmq-for-sensu.service")
81+
machine.wait_for_unit("sensu-client.service")
82+
machine.wait_for_open_port(3031)
8583
86-
with subtest("sensu client should respond to HTTP"):
87-
out = machine.succeed("curl localhost:3031/brew")
88-
assert {"response":"I'm a teapot!"} == json.loads(out)
84+
with subtest("sensu client should respond to HTTP"):
85+
out = machine.succeed("curl localhost:3031/brew")
86+
assert {"response":"I'm a teapot!"} == json.loads(out)
8987
90-
with subtest("sensu client config should have basic checks configured"):
91-
out = machine.succeed("sensu-client-show-config")
92-
config = json.loads(out)
93-
assert "disk" in config["checks"]
94-
assert "firewall-active" in config["checks"]
95-
assert "uptime" in config["checks"]
88+
with subtest("sensu client config should have basic checks configured"):
89+
out = machine.succeed("sensu-client-show-config")
90+
config = json.loads(out)
91+
assert "disk" in config["checks"]
92+
assert "firewall-active" in config["checks"]
93+
assert "uptime" in config["checks"]
9694
97-
with subtest("sensu client should subscribe as consumer to rabbitmq"):
98-
machine.wait_until_succeeds("sudo -u rabbitmq rabbitmqctl list_consumers -p /sensu | grep rabbit@machine")
99-
'';
95+
with subtest("sensu client should subscribe as consumer to rabbitmq"):
96+
machine.wait_until_succeeds("sudo -u rabbitmq rabbitmqctl list_consumers -p /sensu | grep rabbit@machine")
97+
98+
with subtest("check_ping should be able to ping the VM"):
99+
machine.succeed("${pkgs.monitoring-plugins}/bin/check_ping localhost -w 200,10% -c 500,30%")
100+
'';
100101
})

0 commit comments

Comments
 (0)