Skip to content

Commit d56337e

Browse files
committed
Moved isconnectable example to acceptance test since it needs to be complicated to work.
We need to see what port is listening and that takes some work. This was causing trouble in our CI environment where we change the ssh port to a random other port. Ticket: ENT-12729 Changelog: none
1 parent 8788bcf commit d56337e

File tree

2 files changed

+43
-45
lines changed

2 files changed

+43
-45
lines changed

examples/isconnectable.cf

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
body common control
2+
{
3+
inputs => { "../../default.cf.sub" };
4+
bundlesequence => { default("$(this.promise_filename)") };
5+
version => "1.0";
6+
}
7+
8+
bundle agent init
9+
{
10+
vars:
11+
# to avoid dependencies (like installing netstat/net-utils), look at proc filesystem for listening port, probably at least one (like ssh or chrony)
12+
# header of /proc/net/tcp is: sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
13+
# local_address is ip:port
14+
# example line for ssh (port 22, hex 16): 0: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 25575 2 ffff9eac03038000 100 0 0 10 0
15+
# finally, to keep things "simple" only try ports listening on 0.0.0.0 aka 00000000: in the local_address column
16+
"port_to_check" string => execresult("cat /proc/net/tcp | grep ': 00000000:' | head -2 | tail -1 | awk '{print $2}' | cut -d: -f2 | xargs -I{} printf '%d\n' 0x{}", "useshell");
17+
18+
classes:
19+
"port_to_check_available" expression => and(
20+
isvariable("port_to_check"),
21+
not(strcmp("${port_to_check}",""))
22+
),
23+
scope => "namespace";
24+
25+
reports:
26+
"init bundle, port_to_check is ${port_to_check}";
27+
}
28+
29+
bundle agent check
30+
{
31+
meta:
32+
"test_skip_unsupported" string => "!linux|!port_to_check_available";
33+
34+
classes:
35+
"isconnectable" expression => isconnectable("localhost", ${init.port_to_check}, "30");
36+
37+
reports:
38+
"Tried isconnectable on port_to_check ${init.port_to_check}";
39+
isconnectable::
40+
"${this.promise_filename} Pass";
41+
!isconnectable::
42+
"${this.promise_filename} FAIL";
43+
}

0 commit comments

Comments
 (0)