Skip to content

Commit e4488d8

Browse files
feat: add csphere_http port detection (#119)
1 parent f625c22 commit e4488d8

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

service_port.go

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ var inputServicePorts = map[string]ServicePortGetter{
5454
DefaultPort: 25826,
5555
DefaultProtocol: networking.ProtocolUDP,
5656
},
57+
"csphere_http": {
58+
PortFunc: fromPort,
59+
DefaultPort: 443,
60+
DefaultProtocol: networking.ProtocolTCP,
61+
},
5762
"elasticsearch": {
5863
PortFunc: fromPort,
5964
DefaultPort: 9200,

service_port_test.go

+44-37
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func TestConfig_ServicePorts(t *testing.T) {
3636
name cloudflare
3737
[INPUT]
3838
name collectd
39+
[INPUT]
40+
name csphere_http
3941
[INPUT]
4042
name elasticsearch
4143
[INPUT]
@@ -67,17 +69,18 @@ func TestConfig_ServicePorts(t *testing.T) {
6769
{Port: 2020, Protocol: networking.ProtocolTCP, Kind: SectionKindService},
6870
expected(9880, networking.ProtocolTCP, SectionKindInput, "cloudflare", 0),
6971
expected(25826, networking.ProtocolUDP, SectionKindInput, "collectd", 1),
70-
expected(9200, networking.ProtocolTCP, SectionKindInput, "elasticsearch", 2),
71-
expected(24224, networking.ProtocolTCP, SectionKindInput, "forward", 3),
72-
expected(9880, networking.ProtocolTCP, SectionKindInput, "http", 4),
73-
expected(1883, networking.ProtocolTCP, SectionKindInput, "mqtt", 5),
74-
expected(4318, networking.ProtocolTCP, SectionKindInput, "opentelemetry", 6),
75-
expected(8080, networking.ProtocolTCP, SectionKindInput, "prometheus_remote_write", 7),
76-
expected(8088, networking.ProtocolTCP, SectionKindInput, "splunk", 8),
77-
expected(8125, networking.ProtocolUDP, SectionKindInput, "statsd", 9),
78-
// expected(5140, networking.ProtocolTCP, SectionKindInput, "syslog", 10), // default syslog without explicit mode tcp or udp is skipped
79-
expected(5170, networking.ProtocolTCP, SectionKindInput, "tcp", 11),
80-
expected(5170, networking.ProtocolUDP, SectionKindInput, "udp", 12),
72+
expected(443, networking.ProtocolTCP, SectionKindInput, "csphere_http", 2),
73+
expected(9200, networking.ProtocolTCP, SectionKindInput, "elasticsearch", 3),
74+
expected(24224, networking.ProtocolTCP, SectionKindInput, "forward", 4),
75+
expected(9880, networking.ProtocolTCP, SectionKindInput, "http", 5),
76+
expected(1883, networking.ProtocolTCP, SectionKindInput, "mqtt", 6),
77+
expected(4318, networking.ProtocolTCP, SectionKindInput, "opentelemetry", 7),
78+
expected(8080, networking.ProtocolTCP, SectionKindInput, "prometheus_remote_write", 8),
79+
expected(8088, networking.ProtocolTCP, SectionKindInput, "splunk", 9),
80+
expected(8125, networking.ProtocolUDP, SectionKindInput, "statsd", 10),
81+
// expected(5140, networking.ProtocolTCP, SectionKindInput, "syslog", 11), // default syslog without explicit mode tcp or udp is skipped
82+
expected(5170, networking.ProtocolTCP, SectionKindInput, "tcp", 12),
83+
expected(5170, networking.ProtocolUDP, SectionKindInput, "udp", 13),
8184
expected(2021, networking.ProtocolTCP, SectionKindOutput, "prometheus_exporter", 0),
8285
}, config.ServicePorts())
8386
})
@@ -94,65 +97,69 @@ func TestConfig_ServicePorts(t *testing.T) {
9497
name collectd
9598
port 3
9699
[INPUT]
97-
name elasticsearch
100+
name csphere_http
98101
port 4
99102
[INPUT]
100-
name forward
103+
name elasticsearch
101104
port 5
102105
[INPUT]
103-
name http
106+
name forward
104107
port 6
105108
[INPUT]
106-
name mqtt
109+
name http
107110
port 7
108111
[INPUT]
109-
name opentelemetry
112+
name mqtt
110113
port 8
111114
[INPUT]
112-
name prometheus_remote_write
115+
name opentelemetry
113116
port 9
114117
[INPUT]
115-
name splunk
118+
name prometheus_remote_write
116119
port 10
117120
[INPUT]
118-
name statsd
121+
name splunk
119122
port 11
123+
[INPUT]
124+
name statsd
125+
port 12
120126
[INPUT]
121127
name syslog
122128
mode tcp
123-
port 12
129+
port 13
124130
[INPUT]
125131
name syslog
126132
mode udp
127-
port 13
133+
port 14
128134
[INPUT]
129135
name tcp
130-
port 14
136+
port 15
131137
[INPUT]
132138
name udp
133-
port 15
139+
port 16
134140
[OUTPUT]
135141
name prometheus_exporter
136-
port 16
142+
port 17
137143
`, FormatClassic)
138144
assert.NoError(t, err)
139145
assert.Equal(t, ServicePorts{
140146
{Port: 1, Protocol: networking.ProtocolTCP, Kind: SectionKindService},
141147
expected(2, networking.ProtocolTCP, SectionKindInput, "cloudflare", 0, property.Property{Key: "addr", Value: ":2"}),
142148
expected(3, networking.ProtocolUDP, SectionKindInput, "collectd", 1, property.Property{Key: "port", Value: int64(3)}),
143-
expected(4, networking.ProtocolTCP, SectionKindInput, "elasticsearch", 2, property.Property{Key: "port", Value: int64(4)}),
144-
expected(5, networking.ProtocolTCP, SectionKindInput, "forward", 3, property.Property{Key: "port", Value: int64(5)}),
145-
expected(6, networking.ProtocolTCP, SectionKindInput, "http", 4, property.Property{Key: "port", Value: int64(6)}),
146-
expected(7, networking.ProtocolTCP, SectionKindInput, "mqtt", 5, property.Property{Key: "port", Value: int64(7)}),
147-
expected(8, networking.ProtocolTCP, SectionKindInput, "opentelemetry", 6, property.Property{Key: "port", Value: int64(8)}),
148-
expected(9, networking.ProtocolTCP, SectionKindInput, "prometheus_remote_write", 7, property.Property{Key: "port", Value: int64(9)}),
149-
expected(10, networking.ProtocolTCP, SectionKindInput, "splunk", 8, property.Property{Key: "port", Value: int64(10)}),
150-
expected(11, networking.ProtocolUDP, SectionKindInput, "statsd", 9, property.Property{Key: "port", Value: int64(11)}),
151-
expected(12, networking.ProtocolTCP, SectionKindInput, "syslog", 10, property.Property{Key: "mode", Value: "tcp"}, property.Property{Key: "port", Value: int64(12)}),
152-
expected(13, networking.ProtocolUDP, SectionKindInput, "syslog", 11, property.Property{Key: "mode", Value: "udp"}, property.Property{Key: "port", Value: int64(13)}),
153-
expected(14, networking.ProtocolTCP, SectionKindInput, "tcp", 12, property.Property{Key: "port", Value: int64(14)}),
154-
expected(15, networking.ProtocolUDP, SectionKindInput, "udp", 13, property.Property{Key: "port", Value: int64(15)}),
155-
expected(16, networking.ProtocolTCP, SectionKindOutput, "prometheus_exporter", 0, property.Property{Key: "port", Value: int64(16)}),
149+
expected(4, networking.ProtocolTCP, SectionKindInput, "csphere_http", 2, property.Property{Key: "port", Value: int64(4)}),
150+
expected(5, networking.ProtocolTCP, SectionKindInput, "elasticsearch", 3, property.Property{Key: "port", Value: int64(5)}),
151+
expected(6, networking.ProtocolTCP, SectionKindInput, "forward", 4, property.Property{Key: "port", Value: int64(6)}),
152+
expected(7, networking.ProtocolTCP, SectionKindInput, "http", 5, property.Property{Key: "port", Value: int64(7)}),
153+
expected(8, networking.ProtocolTCP, SectionKindInput, "mqtt", 6, property.Property{Key: "port", Value: int64(8)}),
154+
expected(9, networking.ProtocolTCP, SectionKindInput, "opentelemetry", 7, property.Property{Key: "port", Value: int64(9)}),
155+
expected(10, networking.ProtocolTCP, SectionKindInput, "prometheus_remote_write", 8, property.Property{Key: "port", Value: int64(10)}),
156+
expected(11, networking.ProtocolTCP, SectionKindInput, "splunk", 9, property.Property{Key: "port", Value: int64(11)}),
157+
expected(12, networking.ProtocolUDP, SectionKindInput, "statsd", 10, property.Property{Key: "port", Value: int64(12)}),
158+
expected(13, networking.ProtocolTCP, SectionKindInput, "syslog", 11, property.Property{Key: "mode", Value: "tcp"}, property.Property{Key: "port", Value: int64(13)}),
159+
expected(14, networking.ProtocolUDP, SectionKindInput, "syslog", 12, property.Property{Key: "mode", Value: "udp"}, property.Property{Key: "port", Value: int64(14)}),
160+
expected(15, networking.ProtocolTCP, SectionKindInput, "tcp", 13, property.Property{Key: "port", Value: int64(15)}),
161+
expected(16, networking.ProtocolUDP, SectionKindInput, "udp", 14, property.Property{Key: "port", Value: int64(16)}),
162+
expected(17, networking.ProtocolTCP, SectionKindOutput, "prometheus_exporter", 0, property.Property{Key: "port", Value: int64(17)}),
156163
}, config.ServicePorts())
157164
})
158165

0 commit comments

Comments
 (0)