Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sshcheckreceiver to the distribution #4099

Merged
merged 6 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The distribution offers support for the following components.
| [azureeventhub](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/azureeventhubreceiver) | [alpha] |
| [carbon](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/carbonreceiver) | [alpha] |
| [cloudfoundry](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/cloudfoundryreceiver) | [beta] |
| [collectd](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/collectdreceiver) | [beta] |
| [collectd](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/collectdreceiver) | [beta] |
| [databricks](../internal/receiver/databricksreceiver) | [alpha] |
| [discovery](../internal/receiver/discoveryreceiver) | [in development] |
| [filelog](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver) | [beta] |
Expand Down Expand Up @@ -48,6 +48,7 @@ The distribution offers support for the following components.
| [solace](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/solacereceiver) | [beta] |
| [splunk_hec](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/splunkhecreceiver) | [beta] |
| [sqlquery](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlqueryreceiver) | [alpha] |
| [sshcheck](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sshcheckreceiver) | alpha |
| [statsd](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/statsdreceiver) | [beta] |
| [syslog](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/syslogreceiver) | [alpha] |
| [tcplog](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/tcplogreceiver) | [alpha] |
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/solacereceiver v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlqueryreceiver v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver v0.91.0
Expand Down Expand Up @@ -164,6 +165,7 @@ require (
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
Expand All @@ -180,6 +182,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.91.0 // indirect
github.com/ovh/go-ovh v1.4.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.6 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,8 @@ github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b/go.mod h1:pcaDhQK0/NJZ
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down Expand Up @@ -1245,6 +1247,8 @@ github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecrece
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver v0.91.0/go.mod h1:yZNCWZDmNEKbTUgPn0CfHbyjvvJ4cTGjIorjmnHh4Uo=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlqueryreceiver v0.91.0 h1:Fg1/7HmB0o45beLCnqixkUe/jBFZ1TL2OO/9vD54Nrs=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlqueryreceiver v0.91.0/go.mod h1:QaWk0MD1xZSoTiwBmkjgqgIYWWwhz+ae6xbOT9W1S/M=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver v0.91.0 h1:QOfnJaelNZL8gB56v9A9W7RFUaK8an7iDjtwQA0kd48=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver v0.91.0/go.mod h1:OsAAL/ncR+i016hgmtEebau94fLfqS7Ni+qRU/2ESec=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.91.0 h1:FmfGNnxGWBzMNd/fu5s5pL/3czfNJeR3/ssN9Mk7qOI=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.91.0/go.mod h1:wkEO4jo0q1YA2pPgcZVRhppWKCOjWkhoOH8fuAls6dc=
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver v0.91.0 h1:aD61qnTJLvNsrABL6IxgkB/7Ai79MTwJWIubw6vgKIk=
Expand Down Expand Up @@ -1309,6 +1313,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pkg/sftp v1.13.6 h1:JFZT4XbOU7l77xGSpOdW+pwIMqP044IyjXX6FGyEKFo=
github.com/pkg/sftp v1.13.6/go.mod h1:tz1ryNURKu77RL+GuCzmoJYxQczL3wLNNpPWagdg4Qk=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
2 changes: 2 additions & 0 deletions internal/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/solacereceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlqueryreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver"
Expand Down Expand Up @@ -175,6 +176,7 @@ func Get() (otelcol.Factories, error) {
solacereceiver.NewFactory(),
splunkhecreceiver.NewFactory(),
sqlqueryreceiver.NewFactory(),
sshcheckreceiver.NewFactory(),
statsdreceiver.NewFactory(),
syslogreceiver.NewFactory(),
tcplogreceiver.NewFactory(),
Expand Down
1 change: 1 addition & 0 deletions internal/components/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestDefaultComponents(t *testing.T) {
"solace",
"splunk_hec",
"sqlquery",
"sshcheck",
"statsd",
"syslog",
"tcplog",
Expand Down
36 changes: 36 additions & 0 deletions tests/receivers/sshcheck/sshcheck_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Splunk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build integration

package tests

import (
"path"
"testing"

"github.com/signalfx/splunk-otel-collector/tests/testutils"
)

var sshd = testutils.NewContainer().WithContext(path.Join(".", "testdata", "server")).WithExposedPorts("2222:22").WithName("sshd-server").WillWaitForPorts("22")

func TestSSHCheckReceiverBadPassword(t *testing.T) {
testutils.AssertAllMetricsReceived(t, "sshcheck_bad_password.yaml", "sshcheck_config_bad_password.yaml",
[]testutils.Container{sshd}, nil)
}

func TestSSHCheckReceiverHappyPath(t *testing.T) {
testutils.AssertAllMetricsReceived(t, "sshcheck_happy_path.yaml", "sshcheck_config_happy_path.yaml",
[]testutils.Container{sshd}, nil)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource_metrics:
- attributes: {}
scope_metrics:
- instrumentation_scope:
attributes: {}
name: otelcol/sshcheckreceiver
version: <ANY>
metrics:
- description: Measures the duration of SSH connection.
name: sshcheck.duration
type: IntGauge
unit: ms
- attributes:
error.message: "ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain"
description: Records errors occurring during SSH check.
name: sshcheck.error
type: IntNonmonotonicCumulativeSum
unit: "{error}"
- description: 1 if the SSH client successfully connected, otherwise 0.
name: sshcheck.status
type: IntNonmonotonicCumulativeSum
unit: 1
value: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource_metrics:
- attributes: {}
scope_metrics:
- instrumentation_scope:
attributes: {}
name: otelcol/sshcheckreceiver
version: <ANY>
metrics:
- description: Measures the duration of SSH connection.
name: sshcheck.duration
type: IntGauge
unit: ms
- description: 1 if the SSH client successfully connected, otherwise 0.
name: sshcheck.status
type: IntNonmonotonicCumulativeSum
unit: 1
value: 1
10 changes: 10 additions & 0 deletions tests/receivers/sshcheck/testdata/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y openssh-server
# Configure SSH
RUN mkdir /var/run/sshd
RUN echo 'root:foo' | chpasswd
#password for user login
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22
# Start SSH server
CMD ["/usr/sbin/sshd", "-D"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
receivers:
sshcheck:
endpoint: localhost:2222
username: root
password: bar # Provide wrong password on purpose to get errors.
ignore_host_key: true
exporters:
otlp:
endpoint: "${OTLP_ENDPOINT}"
tls:
insecure: true

service:
telemetry:
logs:
level: debug
pipelines:
metrics:
receivers: [sshcheck]
exporters: [otlp]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
receivers:
sshcheck:
endpoint: localhost:2222
username: root
password: foo
ignore_host_key: true
exporters:
otlp:
endpoint: "${OTLP_ENDPOINT}"
tls:
insecure: true

service:
telemetry:
logs:
level: debug
pipelines:
metrics:
receivers: [sshcheck]
exporters: [otlp]
3 changes: 2 additions & 1 deletion tests/testutils/telemetry/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"

"github.com/knadh/koanf/maps"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

"github.com/signalfx/splunk-otel-collector/tests/internal/version"
Expand Down Expand Up @@ -256,7 +257,7 @@ func (metric Metric) equals(toCompare Metric, strict bool) bool {
return false
}

if metric.Value != toCompare.Value && (strict || metric.Value != nil) {
if !assert.ObjectsAreEqualValues(metric.Value, toCompare.Value) && (strict || metric.Value != nil) {
return false
}

Expand Down
Loading