diff options
author | Christian Breunig <christian@breunig.cc> | 2023-04-13 08:53:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 08:53:34 +0200 |
commit | 94a6fb73d248e9e9e2c3d4a4ac023228473c9f48 (patch) | |
tree | 7752e4e7d9235d7a762af848b0fccf46adb7f508 | |
parent | 30263ab26b8a9bbebe9356dd4e465b331230e31e (diff) | |
parent | 692f103fe535cd8f3ed20206a3c17cddd151e046 (diff) | |
download | vyos-1x-94a6fb73d248e9e9e2c3d4a4ac023228473c9f48.tar.gz vyos-1x-94a6fb73d248e9e9e2c3d4a4ac023228473c9f48.zip |
Merge pull request #1954 from sever-sever/T5152-eq
T5152: Get default hostname for telegraf from FQDN or hostname
-rw-r--r-- | data/templates/monitoring/telegraf.tmpl | 2 | ||||
-rwxr-xr-x | src/conf_mode/service_monitoring_telegraf.py | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/data/templates/monitoring/telegraf.tmpl b/data/templates/monitoring/telegraf.tmpl index c5cbddc8c..5b9838f7b 100644 --- a/data/templates/monitoring/telegraf.tmpl +++ b/data/templates/monitoring/telegraf.tmpl @@ -12,7 +12,7 @@ debug = false quiet = false logfile = "" - hostname = "" + hostname = "{{ hostname }}" omit_hostname = false {% if influxdb_configured is defined %} [[outputs.influxdb_v2]] diff --git a/src/conf_mode/service_monitoring_telegraf.py b/src/conf_mode/service_monitoring_telegraf.py index a71565df4..e816bbe8a 100755 --- a/src/conf_mode/service_monitoring_telegraf.py +++ b/src/conf_mode/service_monitoring_telegraf.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2021-2022 VyOS maintainers and contributors +# Copyright (C) 2021-2023 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 @@ -15,6 +15,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import os +import socket import json from sys import exit @@ -77,6 +78,14 @@ def get_nft_filter_chains(): return chain_list +def get_hostname() -> str: + try: + hostname = socket.getfqdn() + except socket.gaierror: + hostname = socket.gethostname() + return hostname + + def get_config(config=None): if config: @@ -96,6 +105,7 @@ def get_config(config=None): monitoring = dict_merge(default_values, monitoring) monitoring['custom_scripts_dir'] = custom_scripts_dir + monitoring['hostname'] = get_hostname() monitoring['interfaces_ethernet'] = get_interfaces('ethernet', vlan=False) monitoring['nft_chains'] = get_nft_filter_chains() |