File tree Expand file tree Collapse file tree 2 files changed +44
-7
lines changed
tests/acceptance/01_vars/02_functions Expand file tree Collapse file tree 2 files changed +44
-7
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ body common control
25
25
{
26
26
bundlesequence => { "example" };
27
27
}
28
- bundle agent example
28
+ bundle agent example
29
29
{
30
30
classes:
31
31
"isconnectable" expression => isconnectable("localhost", 22, "30");
@@ -37,9 +37,3 @@ bundle agent example
37
37
"Port is not connectable";
38
38
}
39
39
#+end_src
40
- ###############################################################################
41
- #+begin_src example_output
42
- #@ ```
43
- #@ R: Port is connectable
44
- #@ ```
45
- #+end_src
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments