diff --git a/docs/components.md b/docs/components.md index cfd44f26d2..e03cf92120 100644 --- a/docs/components.md +++ b/docs/components.md @@ -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] | @@ -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] | diff --git a/go.mod b/go.mod index 0d29279f8c..9bc271f36f 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 4e44007278..c61aa03e45 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/internal/components/components.go b/internal/components/components.go index b43d9368ad..481ec48419 100644 --- a/internal/components/components.go +++ b/internal/components/components.go @@ -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" @@ -175,6 +176,7 @@ func Get() (otelcol.Factories, error) { solacereceiver.NewFactory(), splunkhecreceiver.NewFactory(), sqlqueryreceiver.NewFactory(), + sshcheckreceiver.NewFactory(), statsdreceiver.NewFactory(), syslogreceiver.NewFactory(), tcplogreceiver.NewFactory(), diff --git a/internal/components/components_test.go b/internal/components/components_test.go index a1358544ab..f823bd5efb 100644 --- a/internal/components/components_test.go +++ b/internal/components/components_test.go @@ -78,6 +78,7 @@ func TestDefaultComponents(t *testing.T) { "solace", "splunk_hec", "sqlquery", + "sshcheck", "statsd", "syslog", "tcplog", diff --git a/tests/receivers/sshcheck/sshcheck_test.go b/tests/receivers/sshcheck/sshcheck_test.go new file mode 100644 index 0000000000..6c04cb52fe --- /dev/null +++ b/tests/receivers/sshcheck/sshcheck_test.go @@ -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) +} diff --git a/tests/receivers/sshcheck/testdata/resource_metrics/sshcheck_bad_password.yaml b/tests/receivers/sshcheck/testdata/resource_metrics/sshcheck_bad_password.yaml new file mode 100644 index 0000000000..3dec4bbf8c --- /dev/null +++ b/tests/receivers/sshcheck/testdata/resource_metrics/sshcheck_bad_password.yaml @@ -0,0 +1,23 @@ +resource_metrics: + - attributes: {} + scope_metrics: + - instrumentation_scope: + attributes: {} + name: otelcol/sshcheckreceiver + version: + 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 \ No newline at end of file diff --git a/tests/receivers/sshcheck/testdata/resource_metrics/sshcheck_happy_path.yaml b/tests/receivers/sshcheck/testdata/resource_metrics/sshcheck_happy_path.yaml new file mode 100644 index 0000000000..e426bca4e5 --- /dev/null +++ b/tests/receivers/sshcheck/testdata/resource_metrics/sshcheck_happy_path.yaml @@ -0,0 +1,17 @@ +resource_metrics: + - attributes: {} + scope_metrics: + - instrumentation_scope: + attributes: {} + name: otelcol/sshcheckreceiver + version: + 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 \ No newline at end of file diff --git a/tests/receivers/sshcheck/testdata/server/Dockerfile b/tests/receivers/sshcheck/testdata/server/Dockerfile new file mode 100644 index 0000000000..bc6e7cba8e --- /dev/null +++ b/tests/receivers/sshcheck/testdata/server/Dockerfile @@ -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"] \ No newline at end of file diff --git a/tests/receivers/sshcheck/testdata/sshcheck_config_bad_password.yaml b/tests/receivers/sshcheck/testdata/sshcheck_config_bad_password.yaml new file mode 100644 index 0000000000..49e30dd8d8 --- /dev/null +++ b/tests/receivers/sshcheck/testdata/sshcheck_config_bad_password.yaml @@ -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] diff --git a/tests/receivers/sshcheck/testdata/sshcheck_config_happy_path.yaml b/tests/receivers/sshcheck/testdata/sshcheck_config_happy_path.yaml new file mode 100644 index 0000000000..862103dee2 --- /dev/null +++ b/tests/receivers/sshcheck/testdata/sshcheck_config_happy_path.yaml @@ -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] diff --git a/tests/testutils/telemetry/metrics.go b/tests/testutils/telemetry/metrics.go index 667b87e416..1bcc8a3b7e 100644 --- a/tests/testutils/telemetry/metrics.go +++ b/tests/testutils/telemetry/metrics.go @@ -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" @@ -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 }