diff --git a/data/templates/telegraf/telegraf.j2 b/data/templates/telegraf/telegraf.j2 index 2d14230ae..36571ce98 100644 --- a/data/templates/telegraf/telegraf.j2 +++ b/data/templates/telegraf/telegraf.j2 @@ -1,122 +1,122 @@ # Generated by /usr/libexec/vyos/conf_mode/service_monitoring_telegraf.py [agent] interval = "15s" round_interval = true metric_batch_size = 1000 metric_buffer_limit = 10000 collection_jitter = "5s" flush_interval = "15s" flush_jitter = "0s" precision = "" debug = false quiet = false logfile = "" hostname = "" omit_hostname = false {% if azure_data_explorer is vyos_defined %} ### Azure Data Explorer ### [[outputs.azure_data_explorer]] ## The URI property of the Azure Data Explorer resource on Azure endpoint_url = "{{ azure_data_explorer.url }}" ## The Azure Data Explorer database that the metrics will be ingested into. ## The plugin will NOT generate this database automatically, it's expected that this database already exists before ingestion. database = "{{ azure_data_explorer.database }}" metrics_grouping_type = "{{ azure_data_explorer.group_metrics }}" ## Name of the single table to store all the metrics (Only needed if metrics_grouping_type is "SingleTable"). {% if azure_data_explorer.table is vyos_defined and azure_data_explorer.group_metrics == 'SingleTable' %} table_name = "{{ azure_data_explorer.table }}" {% endif %} ### End Azure Data Explorer ### {% endif %} {% if influxdb is vyos_defined %} ### InfluxDB2 ### [[outputs.influxdb_v2]] urls = ["{{ influxdb.url }}:{{ influxdb.port }}"] insecure_skip_verify = true token = "$INFLUX_TOKEN" organization = "{{ influxdb.authentication.organization }}" bucket = "{{ influxdb.bucket }}" ### End InfluxDB2 ### {% endif %} {% if prometheus_client is vyos_defined %} ### Prometheus ### [[outputs.prometheus_client]] ## Address to listen on listen = "{{ prometheus_client.listen_address | bracketize_ipv6 if prometheus_client.listen_address is vyos_defined else '' }}:{{ prometheus_client.port }}" metric_version = {{ prometheus_client.metric_version }} {% if prometheus_client.authentication.username is vyos_defined and prometheus_client.authentication.password is vyos_defined %} ## Use HTTP Basic Authentication basic_username = "{{ prometheus_client.authentication.username }}" basic_password = "{{ prometheus_client.authentication.password }}" {% endif %} {% if prometheus_client.allow_from is vyos_defined %} ip_range = {{ prometheus_client.allow_from }} {% endif %} ### End Prometheus ### {% endif %} {% if splunk is vyos_defined %} ### Splunk ### [[outputs.http]] ## URL is the address to send metrics to url = "{{ splunk.url }}" ## Timeout for HTTP message # timeout = "5s" ## Use TLS but skip chain & host verification {% if splunk.authentication.insecure is vyos_defined %} insecure_skip_verify = true {% endif %} ## Data format to output data_format = "splunkmetric" ## Provides time, index, source overrides for the HEC splunkmetric_hec_routing = true ## Additional HTTP headers [outputs.http.headers] # Should be set manually to "application/json" for json data_format Content-Type = "application/json" Authorization = "Splunk {{ splunk.authentication.token }}" X-Splunk-Request-Channel = "{{ splunk.authentication.token }}" ### End Splunk ### {% endif %} [[inputs.cpu]] percpu = true totalcpu = true collect_cpu_time = false report_active = false [[inputs.disk]] ignore_fs = ["devtmpfs", "devfs"] [[inputs.diskio]] [[inputs.mem]] [[inputs.net]] [[inputs.system]] [[inputs.netstat]] [[inputs.processes]] [[inputs.kernel]] [[inputs.interrupts]] [[inputs.linux_sysctl_fs]] [[inputs.systemd_units]] [[inputs.conntrack]] files = ["ip_conntrack_count","ip_conntrack_max","nf_conntrack_count","nf_conntrack_max"] dirs = ["/proc/sys/net/ipv4/netfilter","/proc/sys/net/netfilter"] [[inputs.ethtool]] interface_include = {{ interfaces_ethernet }} [[inputs.ntpq]] dns_lookup = true [[inputs.internal]] [[inputs.nstat]] [[inputs.syslog]] server = "unixgram:///run/telegraf/telegraf_syslog.sock" best_effort = true syslog_standard = "RFC3164" -{% if influxdb_configured is vyos_defined %} +{% if influxdb is vyos_defined %} [[inputs.exec]] commands = [ "{{ custom_scripts_dir }}/show_firewall_input_filter.py", "{{ custom_scripts_dir }}/show_interfaces_input_filter.py", "{{ custom_scripts_dir }}/vyos_services_input_filter.py" ] timeout = "10s" data_format = "influx" {% endif %} diff --git a/smoketest/scripts/cli/test_service_monitoring_telegraf.py b/smoketest/scripts/cli/test_service_monitoring_telegraf.py index c1c4044e6..ed486c3b9 100755 --- a/smoketest/scripts/cli/test_service_monitoring_telegraf.py +++ b/smoketest/scripts/cli/test_service_monitoring_telegraf.py @@ -1,68 +1,69 @@ #!/usr/bin/env python3 # # Copyright (C) 2021-2022 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import unittest from base_vyostest_shim import VyOSUnitTestSHIM from vyos.configsession import ConfigSession from vyos.configsession import ConfigSessionError from vyos.util import process_named_running from vyos.util import read_file PROCESS_NAME = 'telegraf' TELEGRAF_CONF = '/run/telegraf/telegraf.conf' base_path = ['service', 'monitoring', 'telegraf'] org = 'log@in.local' token = 'GuRJc12tIzfjnYdKRAIYbxdWd2aTpOT9PVYNddzDnFV4HkAcD7u7-kndTFXjGuXzJN6TTxmrvPODB4mnFcseDV==' port = '8888' url = 'https://foo.local' bucket = 'main' inputs = ['cpu', 'disk', 'mem', 'net', 'system', 'kernel', 'interrupts', 'syslog'] class TestMonitoringTelegraf(VyOSUnitTestSHIM.TestCase): def tearDown(self): # Check for running process self.assertTrue(process_named_running(PROCESS_NAME)) self.cli_delete(base_path) self.cli_commit() # Check for not longer running process self.assertFalse(process_named_running(PROCESS_NAME)) def test_01_basic_config(self): self.cli_set(base_path + ['influxdb', 'authentication', 'organization', org]) self.cli_set(base_path + ['influxdb', 'authentication', 'token', token]) self.cli_set(base_path + ['influxdb', 'port', port]) self.cli_set(base_path + ['influxdb', 'url', url]) # commit changes self.cli_commit() config = read_file(TELEGRAF_CONF) # Check telegraf config self.assertIn(f'organization = "{org}"', config) self.assertIn(f' token = "$INFLUX_TOKEN"', config) self.assertIn(f'urls = ["{url}:{port}"]', config) self.assertIn(f'bucket = "{bucket}"', config) + self.assertIn(f'[[inputs.exec]]', config) for input in inputs: self.assertIn(input, config) if __name__ == '__main__': unittest.main(verbosity=2)