opnsense / plugins

OPNsense plugin collection
https://opnsense.org/
BSD 2-Clause "Simplified" License
842 stars 638 forks source link

[os-telegraf] add MQTT [[outputs.mqtt]] #2572

Closed CoreSec-xyz closed 2 years ago

CoreSec-xyz commented 3 years ago

Is it possible to add mqtt as output?

mqtt is a good way to process the information without a database.

[[outputs.mqtt]]
  ## URLs of mqtt brokers
  servers = ["localhost:1883"]

  ## topic for producer messages
  topic_prefix = "telegraf"

  ## QoS policy for messages
  ##   0 = at most once
  ##   1 = at least once
  ##   2 = exactly once
  qos = 2

  ## username and password to connect MQTT server.
  # username = "telegraf"
  # password = "metricsmetricsmetricsmetrics"

  ## client ID, if not set a random ID is generated
  # client_id = ""

  ## Timeout for write operations. default: 5s
  # timeout = "5s"

  ## Optional TLS Config
  # tls_ca = "/etc/telegraf/ca.pem"
  # tls_cert = "/etc/telegraf/cert.pem"
  # tls_key = "/etc/telegraf/key.pem"
  ## Use TLS but skip chain & host verification
  # insecure_skip_verify = false

  ## When true, metrics will be sent in one MQTT message per flush.  Otherwise,
  ## metrics are written one metric per MQTT message.
  # batch = false

  ## When true, messages will have RETAIN flag set.
  # retain = false

  ## Defines the maximum length of time that the broker and client may not communicate. 
  ## Defaults to 0 which turns the feature off. For version v2.0.12 mosquitto there is a 
  ## [bug](https://github.com/eclipse/mosquitto/issues/2117) which requires keep_alive to be set.
  ## As a reference eclipse/paho.mqtt.golang v1.3.0 defaults to 30.
  # keep_alive = 0

  ## Data format to output.
  # data_format = "influx"
OPNsense-bot commented 3 years ago

Thank you for creating an issue. Since the ticket doesn't seem to be using one of our templates, we're marking this issue as low priority until further notice.

For more information about the policies for this repository, please read https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md for further details.

The easiest option to gain traction is to close this ticket and open a new one using one of our templates.

psychogun commented 2 years ago

I can start:

plugins/net-mgmt/telegraf/src/opnsense/mvc/app/controllers/OPNsense/Telegraf/forms/output.xml:

    <field>
        <id>output.mqtt_enable</id>
        <label>Enable MQTT</label>
        <type>checkbox</type>
        <help>This will enable writes to a MQTT Broker acting as a mqtt Producer.</help>
    </field>
    <field>
        <id>output.mqtt_topic_prefix</id>
        <label>MQTT topic</label>
        <type>text</type>
        <help>Topic for producer messages.</help>
    </field>
    <field>
        <id>output.mqtt_servers</id>
        <label>MQTT brokers</label>
        <type>text</type>
        <help>URLs of mqtt brokers. Format is without square brackets, just like localhost:8083.</help>
    </field>
    <field>
        <id>output.mqtt_qos</id>
        <label>MQTT QoS</label>
        <type>text</type>
        <help>QoS policy for messages. 0 = at most once, 1 = at least once, 2 = exactly once. Defaults to 2. </help>
    </field>
    <field>
        <id>output.mqtt_username</id>
        <label>MQTT Username</label>
        <type>text</type>
        <help>Set the username for authentication.</help>
    </field>
    <field>
        <id>output.mqtt_password</id>
        <label>MQTT Password</label>
        <type>text</type>
        <help>Set the password for authentication.</help>
    </field>
    <field>
        <id>output.mqtt_client_id</id>
        <label>MQTT Client ID</label>
        <type>text</type>
        <help>Client ID, if not set a random ID is generated.</help>
    </field>
    <field>
        <id>output.mqtt_timeout</id>
        <label>MQTT Timeout</label>
        <type>text</type>
        <help>Timeout for write operations. Default is 5s. </help>
    </field>
    <field>
        <id>output.mqtt_tls_ca</id>
        <label>MQTT TLS CA</label>
        <type>text</type>
        <help>Optional TLS Config, "/etc/telegraf/ca.pem".</help>
    </field>
    <field>
        <id>output.mqtt_tls_cert</id>
        <label>MQTT TLS Cert</label>
        <type>text</type>
        <help>Optional TLS Config, "/etc/telegraf/cert.pem".</help>
    </field>
    <field>
        <id>output.mqtt_tls_key</id>
        <label>MQTT TLS Key</label>
        <type>text</type>
        <help>Optional TLS Config, "/etc/telegraf/key.pem".</help>
    </field>
    <field>
        <id>output.mqtt_insecure_skip_verify</id>
        <label>MQTT Client ID</label>
        <type>checkbox</type>
        <help>Use TLS, but skip chain & host verification.</help>
    </field>
    <field>
        <id>output.mqtt_batch</id>
        <label>MQTT batch</label>
        <type>checkbox</type>
        <help>When checked, metrics will be sent in one MQTT message per flush.  Otherwise, metrics are written one metric per MQTT message.</help>
    </field>
    <field>
        <id>output.mqtt_retain</id>
        <label>MQTT Retain</label>
        <type>checkbox</type>
        <help>When checked, messages will have RETAIN flag set.</help>
    </field>
    <field>
        <id>output.mqtt_keep_alive</id>
        <label>MQTT Keep Alive</label>
        <type>text</type>
        <help>Defines the maximum length of time that the broker and client may not communicate. Defaults to 0 which turns the feature off. For version v2.0.12 mosquitto there is a [bug](https://github.com/eclipse/mosquitto/issues/2117) which requires keep_alive to be set. As a reference eclipse/paho.mqtt.golang v1.3.0 defaults to 30.</help>
    </field>
    <field>
        <id>output.mqtt_format</id>
        <label>MQTT Format</label>
        <type>text</type>
        <help>Data format to output. Defaults to "influx".</help>
    </field>

Given the configuration above is correct, next is to implement all the bells and whistles in:

OPNsense-bot commented 2 years ago

This issue has been automatically timed-out (after 180 days of inactivity).

For more information about the policies for this repository, please read https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md for further details.

If someone wants to step up and work on this issue, just let us know, so we can reopen the issue and assign an owner to it.