Skip to content

Commit

Permalink
Filebeat: Merge "mqtt" input to master (elastic#16204)
Browse files Browse the repository at this point in the history
* Add MQTT input to Filebeat (elastic#15287)

* Inital commit for MQTT input

* Improved naming and error handling

* Improved naming and connection procedure

* Merge "master" branch into "feature-mqtt-input" (elastic#15745)

* [Filebeat] Fixes for NetFlow v9 devices from various vendors (elastic#15449)

- Allow for zero scope fields in options template

NetFlow v9 spec allows for options templates that contain no scope
fields. The netflow input was treating this case as an error and
discarding the template, but that is only applicable to IPFIX.

- Use additional fields to populate bytes/pkt counters

Some devices out there (Cisco NSEL) use fields 231/232 as bytes
counters, when those are supposed to be layer 4 payload counters.

This updates the ECS fields populator to use those fields when the
expected ones are not found.

- Support a classId of 32 bits

While the spec mandates a classId of 8 bits, some Cisco ASA devices
actually use a 32 bit version of this field.

This patches the field to allow up to 32-bit integers and updates the
index pattern to use `long` for the `netflow.class_id` field.

- Add more fields from v9 Cisco devices

Fixes elastic#14212

* update settings for `decode_csv_fields` (elastic#15249) (elastic#15550)

Co-authored-by: DeDe Morton <[email protected]>

Co-authored-by: Sophia Xu <[email protected]>

* docs: updates to output config (elastic#15272)

* [Filebeat] Handle error message in handleS3Objects function (elastic#15545)

* Handle error message in handleS3Objects function

* remove s3Context.Fail and use setError and done instead

* Add changelog

* Fix use of wrong fields in Cisco ASA dashboard (elastic#15553)

This dashboard wasn't updated after a couple of fields were renamed.

Fixes: elastic#15420

* Add test for publisher spool encode and decode. (elastic#15534)

* Add test for publisher queue encode and decode.

* Run mage fmt.

* Fixes from code review.

* Fix convert processor conversion of string with leading zeros to integer (elastic#15557)

The conversion failed when for strings with leading zeroes and a decimal
digit 8 or 9, as the underlying runtime function would try to parse that
as an octal number.

This is fixed by only allowing decimal and hex, which in turns makes the
processor more aligned to its Elasticsearch counterpart.

Fixes elastic#15513

* New mage target: generate pkg file to test the manager (elastic#15580)

This PR adds a new mage target to Functionbeat named `buildPkgForFunction`. It generates the folder `pkg` with the functions to make testing the manager more comfortable during development.

* Packetbeat TLS: Replace array fields with keyword (elastic#15597)

Use of `type: array` in some fields (which was inconsistent) causes
those fields to be excluded from the template. This prevents pointing
aliases to those fields, which we need in 7.6+.

Setting those fields to `keyword` explicitly so that they are included
in the template.

Fixes elastic#15588

* Add a pull request template providing valuable information when reviewing a PR (elastic#15388)

* Add a PR template that provides valuable information when reviewing a PR

* Add CLA check

* Fix typo

* Address comments during review

* SF: Fix typo

* Add deprecation as PR type

* Make it clear how to strike through in markdown

* Add default configuration files to the checklist

* [Metricbeat] Implement IBM MQ module  (elastic#15301)

* Modify cockroachdb source

* Define testdata

* Do not publish ports

* Update docs

* mage fmt update

* Describe containerized environment

* Update CHANGELOG.next.asciidoc

Co-Authored-By: Chris Mark <[email protected]>

* Update data.json

* Rename image

* Update source after review

* Filter ibmmq_ metrics

* mage check

* Fix: mage check

* Don't expose port

* Rename status to qmgr

* Add subscriptions overview dashboard for IBM MQ module

* Add calls, messages overview dashboard for IBM MQ module

* Add screenshots

* Fix: mage check

* Fix: CHANGELOG

* Add explanation

* Fix: mage check

Co-authored-by: Chris Mark <[email protected]>

* Cleanup changelogs for master (elastic#15617)

* Cleanup changelogs for master
* Remove extra header in CHANGELOG.asciidoc

* [Metricbeat] Add lambda metricset in aws module (elastic#15260)

* Add lambda metricset

* Adds missing imports (elastic#15624)

* [docs] Clarify privileges required for the writer role (elastic#15604)

* Mask password discovered via module autodiscover hint (elastic#15616)

* Mask password is string representation of config

* Rename method

* Adding unit test

* Use const for module config password setting name

* Using common.DebugString

* Simplifying

* Removing now-invalid unit test

* Removing now-unnecessary const

* Refactoring: moving debug-related var and func to common file

* Refactoring: rename from black list to mask list

* Implement fmt.Formatter for common.MapStr

* Reintroduce debug statement

* Make MarshalLogObject always filter MapStr object for logging purposes

* Refactoring: renaming to be bit more generic

* Forgot to add license header to new file

* Fixing verb syntax

* Update KQL to get estimated cost without dimension ServiceName (elastic#15640)

* Adding monitoring.cloud.* settings to reference files (elastic#15648)

* Adding monitoring.cloud.* settings to reference files

* Missed winlogbeat somehow

* Missed x-pack/winlogbeat

* remove lablels (elastic#15644)

* Fix panic: don't send events if client is nil (elastic#15568)

* Fix panic: don't send events if client is nil

* Use mutex

* Add CHANGELOG entry

* Rename changelog entry

* Fix: changelog

* Temporarily use specific logstash release

* [Metricbeat] Add Istio mesh metricset (elastic#15535)

* [Metricbeat] Fix changelog (elastic#15681)

* Fix changelog

* ci: use APM pipeline library (elastic#15636)

it uses APM pipeline library configured in the instance

* AWS Lambda: downgrade Kibana dashboard (elastic#15682)

* AWS Lambda: downgrade Kibana dashboard

* Downgrade other AWS dashboards

* Log command error if setup dashboards fails

* Another downgrade

* Use github.com/godror/godror instead of goracle.v2 (elastic#15683)

From the README of goracle:

> Goracle is deprecated because of naming (trademark) issues.

From now on we are using github.com/godror/godror instead.

* Move pdh query to shared location in order for new modules/metricsets to reuse (elastic#15503)

* Move pdh query to shared location

* Update changelog

* Fix make update

* mage fmt

* fix changelog

* Remove datasource option from SQL module and add tests (elastic#15686)

Remove datasource option from SQL module. This option was
intended to set the DSN of a database connection, and we were
ignoring the hosts setting. In other SQL modules we are using
the values in hosts as DSNs, do here the same for consistency.
Host is redacted when we cannot parse it as it can contain passwords.

StandardizeEvent is exposed in mbtest.Fetcher interface so we can
more easily check contents of events in tests.

Add integration tests of the module with MySQL and PostgreSQL.

Add real data.json with data from MySQL and PostgreSQL.

* [metricbeat] add service metricset to reference documentation  (elastic#15643)

* add service metricset to ref docs

* update xpack docs

* [metricbeat] Add divide by zero check to docker/diskio (elastic#15649)

* add NaN check to docker/diskio

* return 0

* Change joda style pattern to java style (elastic#15695)

since 7.0 elasticsearch is using java.time style patterns.
YYYY becomes yyyy

* [DOCS] Add missing config options to shared file (elastic#15136)

* [DOCS] Add missing config options to shared file

* Add fixes from review

* Run mage fmt update to fix build error

* [Heartbeat] Support for multiple status codes elastic#13595 (elastic#15587)

Allow for multiple status codes in config. Fixes elastic#13595

* Add missing changelog entry for elastic#15587 (elastic#15721)

* Update github.com/godror/godror to v0.10.4 (elastic#15737)

## What does this PR do?

This PR updates the dependency `github.com/godror/godror` to v0.10.4.

## Why is it important?

Packaging of Metricbeat fails due to the issue in the `godror` version we are currently using. See more about the problem: godror/godror#8

* Collect normalized CPU percentages by default (elastic#15729)

* Collect normalized CPU percentages by default

* Adding CHANGELOG entry

* Updating x-pack/metricbeat

* Fix: mage check

* Detect Eclipse Public License

Co-authored-by: Adrian Serrano <[email protected]>
Co-authored-by: DeDe Morton <[email protected]>
Co-authored-by: Sophia Xu <[email protected]>
Co-authored-by: Brandon Morelli <[email protected]>
Co-authored-by: kaiyan-sheng <[email protected]>
Co-authored-by: Blake Rouse <[email protected]>
Co-authored-by: Noémi Ványi <[email protected]>
Co-authored-by: Manuel de la Peña <[email protected]>
Co-authored-by: Chris Mark <[email protected]>
Co-authored-by: Michael Madden <[email protected]>
Co-authored-by: Shaunak Kashyap <[email protected]>
Co-authored-by: Pablo Mercado <[email protected]>
Co-authored-by: Ivan Fernandez Calvo <[email protected]>
Co-authored-by: Mariana Dima <[email protected]>
Co-authored-by: Jaime Soriano Pastor <[email protected]>
Co-authored-by: Alex K. <[email protected]>
Co-authored-by: Przemyslaw Gomulka <[email protected]>
Co-authored-by: Amanda H. L. de Andrade Katz <[email protected]>
Co-authored-by: Andrew Cholakian <[email protected]>

* [Filebeat] Refactor mqtt input (elastic#16014)

* Refactor mqtt input

* Fix: comment

* Add unit tests

* Test: input run

* Fix Test: run and stop

* Test: backoff

* Adjust code after review

* MQTT: update docs (elastic#16152)

* MQTT: add integration test (elastic#16143)

* Create mosquitto image

* MQTT input: add integration test

* Fix

* Verify connectivity

* Fix

* Fix: mage check

* Fix

* Fix

* Fix: remove global var

* Update changelog

* Fix: regenerate notice file

* Remove unused dependency

* Fix: zero qos

* Wait asynchronously for client being disconnected

Co-authored-by: Felix <[email protected]>
Co-authored-by: Adrian Serrano <[email protected]>
Co-authored-by: DeDe Morton <[email protected]>
Co-authored-by: Sophia Xu <[email protected]>
Co-authored-by: Brandon Morelli <[email protected]>
Co-authored-by: kaiyan-sheng <[email protected]>
Co-authored-by: Blake Rouse <[email protected]>
Co-authored-by: Noémi Ványi <[email protected]>
Co-authored-by: Manuel de la Peña <[email protected]>
Co-authored-by: Chris Mark <[email protected]>
Co-authored-by: Michael Madden <[email protected]>
Co-authored-by: Shaunak Kashyap <[email protected]>
Co-authored-by: Pablo Mercado <[email protected]>
Co-authored-by: Ivan Fernandez Calvo <[email protected]>
Co-authored-by: Mariana Dima <[email protected]>
Co-authored-by: Jaime Soriano Pastor <[email protected]>
Co-authored-by: Alex K. <[email protected]>
Co-authored-by: Przemyslaw Gomulka <[email protected]>
Co-authored-by: Amanda H. L. de Andrade Katz <[email protected]>
Co-authored-by: Andrew Cholakian <[email protected]>
  • Loading branch information
21 people committed Feb 20, 2020
1 parent 578afa5 commit 8d622e6
Show file tree
Hide file tree
Showing 93 changed files with 13,740 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add ECS tls and categorization fields to apache module. {issue}16032[16032] {pull}16121[16121]
- move create-[module,fileset,fields] to mage and enable in x-pack/filebeat {pull}15836[15836]
- Add ECS tls and categorization fields to apache module. {issue}16032[16032] {pull}16121[16121]
- Add MQTT input. {issue}15602[15602] {pull}16204[16204]

*Heartbeat*

Expand Down
169 changes: 167 additions & 2 deletions NOTICE.txt

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dev-tools/generate_notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ def create_notice(filename, beat, copyright, vendor_dir, csvfile, overrides=None
"Creative Commons Attribution-ShareAlike 4.0 International"
]

ECLIPSE_PUBLIC_LICENSE_TITLES = [
"Eclipse Public License - v 1.0"
]

LGPL_3_LICENSE_TITLE = [
"GNU LESSER GENERAL PUBLIC LICENSE Version 3"
]
Expand Down Expand Up @@ -419,16 +423,18 @@ def detect_license_summary(content):
return "UPL-1.0"
if any(sentence in content[0:1500] for sentence in ISC_LICENSE_TITLE):
return "ISC"

if any(sentence in content[0:1500] for sentence in ECLIPSE_PUBLIC_LICENSE_TITLES):
return "EPL-1.0"
return "UNKNOWN"


ACCEPTED_LICENSES = [
"Apache-2.0",
"MIT",
"BSD-4-Clause",
"BSD-3-Clause",
"BSD-2-Clause",
"EPL-1.0",
"MIT",
"MPL-2.0",
"UPL-1.0",
"ISC",
Expand Down
8 changes: 8 additions & 0 deletions filebeat/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ services:
- KAFKA_PORT=9092
- KIBANA_HOST=kibana
- KIBANA_PORT=5601
- MOSQUITTO_HOST=mosquitto
- MOSQUITTO_PORT=1883
working_dir: /go/src/github.com/elastic/beats/filebeat
volumes:
- ${PWD}/..:/go/src/github.com/elastic/beats/
Expand All @@ -31,6 +33,7 @@ services:
elasticsearch: { condition: service_healthy }
kafka: { condition: service_healthy }
kibana: { condition: service_healthy }
mosquitto: { condition: service_healthy }
redis: { condition: service_healthy }

elasticsearch:
Expand All @@ -51,5 +54,10 @@ services:
file: ${ES_BEATS}/testing/environments/${TESTING_ENVIRONMENT}.yml
service: kibana

mosquitto:
build: ${ES_BEATS}/testing/environments/docker/mosquitto
expose:
- 1883

redis:
build: ${PWD}/input/redis/_meta
3 changes: 3 additions & 0 deletions filebeat/docs/filebeat-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ You can configure {beatname_uc} to use the following inputs:
* <<{beatname_lc}-input-docker>>
* <<{beatname_lc}-input-tcp>>
* <<{beatname_lc}-input-syslog>>
* <<{beatname_lc}-input-mqtt>>
* <<{beatname_lc}-input-s3>>
* <<{beatname_lc}-input-netflow>>
* <<{beatname_lc}-input-google-pubsub>>
Expand All @@ -75,6 +76,8 @@ include::inputs/input-tcp.asciidoc[]

include::inputs/input-syslog.asciidoc[]

include::inputs/input-mqtt.asciidoc[]

include::../../x-pack/filebeat/docs/inputs/input-aws-s3.asciidoc[]

include::../../x-pack/filebeat/docs/inputs/input-netflow.asciidoc[]
Expand Down
81 changes: 81 additions & 0 deletions filebeat/docs/inputs/input-mqtt.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
:type: mqtt

[id="{beatname_lc}-input-{type}"]
=== MQTT input

++++
<titleabbrev>MQTT</titleabbrev>
++++

Use the `MQTT` input to read data transmitted using lightweight messaging protocol
for small and mobile devices, optimized for high-latency or unreliable networks.

This input connects to the MQTT broker, subscribes to selected topics and parses data
into common message lines. Everything happens before line filtering, multiline, and JSON decoding,
so this input can be used in combination with those settings.

Example configuration:

["source","yaml",subs="attributes"]
----
{beatname_lc}.inputs:
- type: mqtt
hosts: <1>
- tcp://broker:1883
- ssl://secure_broker:8883
topics: <2>
- sample_topic
----

<1> `hosts` are required.

<2> `paths` are required.

All other settings are optional.

==== Configuration options

The `mqtt` input supports the following configuration options plus the
<<{beatname_lc}-input-{type}-common-options>> described later.

===== `hosts`

A list of MQTT brokers to connect to.

===== `topics`

A list of topics to subscribe to and read from.

===== `qos`

An agreement level between the sender of a message and the receiver of a message that defines the guarantee of delivery.

There are 3 QoS levels in MQTT:

* At most once (`0`),
* At least once (`1`),
* Exactly once (`2`).

===== `client_id`

A unique identifier of each MQTT client connecting to a MQTT broker.

===== `username`

A client username used for authentication provided on the application level by the MQTT protocol.

===== `password`

A client password used for authentication provided on the application level by the MQTT protocol.

===== `ssl`

Configuration options for SSL parameters like the certificate, key and the certificate authorities
to use.

See <<configuration-ssl>> for more information.

[id="{beatname_lc}-input-{type}-common-options"]
include::../inputs/input-common-options.asciidoc[]

:type!:
1 change: 1 addition & 0 deletions filebeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions filebeat/input/mqtt/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you 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.

package mqtt

import (
libmqtt "github.com/eclipse/paho.mqtt.golang"

"github.com/elastic/beats/libbeat/outputs"
)

func createClientOptions(config mqttInputConfig, onConnectHandler func(client libmqtt.Client)) (*libmqtt.ClientOptions, error) {
clientOptions := libmqtt.NewClientOptions().
SetClientID(config.ClientID).
SetUsername(config.Username).
SetPassword(config.Password).
SetConnectRetry(true).
SetOnConnectHandler(onConnectHandler)

for _, host := range config.Hosts {
clientOptions.AddBroker(host)
}

if config.TLS != nil {
tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
if err != nil {
return nil, err
}
clientOptions.SetTLSConfig(tlsConfig.BuildModuleConfig(""))
}
return clientOptions, nil
}

func createClientSubscriptions(config mqttInputConfig) map[string]byte {
subscriptions := map[string]byte{}
for _, topic := range config.Topics {
subscriptions[topic] = byte(config.QoS)
}
return subscriptions
}
Loading

0 comments on commit 8d622e6

Please sign in to comment.