codecov-io: # [Codecov](https://codecov.io/gh/MatterMiners/tardis/pull/77?src=pr&el=h1) Report
> Merging [#77](https://codecov.io/gh/MatterMiners/tardis/pull/77?src=pr&el=desc) into [master](https://codecov.io/gh/MatterMiners/tardis/commit/06d67fbbd6e3a4cf6cee51f871f86f3fdc25405a?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/MatterMiners/tardis/pull/77/graphs/tree.svg?width=650&token=BKeuDMxoaj&height=150&src=pr)](https://codecov.io/gh/MatterMiners/tardis/pull/77?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
+ Coverage   94.61%   94.62%   +<.01%     
==========================================
  Files          39       39              
  Lines        1355     1357       +2     
==========================================
+ Hits         1282     1284       +2     
  Misses         73       73
```


| [Impacted Files](https://codecov.io/gh/MatterMiners/tardis/pull/77?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tardis/plugins/telegrafmonitoring.py](https://codecov.io/gh/MatterMiners/tardis/pull/77/diff?src=pr&el=tree#diff-dGFyZGlzL3BsdWdpbnMvdGVsZWdyYWZtb25pdG9yaW5nLnB5) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/MatterMiners/tardis/pull/77?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/MatterMiners/tardis/pull/77?src=pr&el=footer). Last update [06d67fb...b5b6b45](https://codecov.io/gh/MatterMiners/tardis/pull/77?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/docs/source/plugins/plugins.rst b/docs/source/plugins/plugins.rst
index ab4d881..bf26cec 100644
--- a/docs/source/plugins/plugins.rst
+++ b/docs/source/plugins/plugins.rst
@@ -2,7 +2,7 @@
 Plugins
 =======
 
-All plugins are configured within the `plugins` section of the TARDIS configuration. Using multiple plugins is```
+All plugins are configured within the `plugins` section of the TARDIS configuration. Using multiple plugins is
 supported by using a separate MappingNode per plugin.
 
 .. code-block:: yaml
@@ -42,6 +42,10 @@ Telegraf Monitoring
 The :py:class:`~tardis.plugins.telegrafmonitoring.TelegrafMonitoring` implements an interface to monitor state changes
 of the Drones in a telegraf service running a UDP input module.
 
+.. Note::
+    By default the machine name of the host running tardis is added as default tag. It can be overwritten by adding
+    `tardis_machine_name: 'something_else'` as `default_tag` in the configuration.
+
 Available configuration options
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/tardis/plugins/telegrafmonitoring.py b/tardis/plugins/telegrafmonitoring.py
index bae7b19..a94f975 100644
--- a/tardis/plugins/telegrafmonitoring.py
+++ b/tardis/plugins/telegrafmonitoring.py
@@ -6,6 +6,7 @@ from ..utilities.attributedict import AttributeDict
 import aiotelegraf
 from datetime import datetime
 import logging
+import platform
 
 
 class TelegrafMonitoring(Plugin):
@@ -20,7 +21,8 @@ class TelegrafMonitoring(Plugin):
 
         host = config.host
         port = config.port
-        default_tags = getattr(config, 'default_tags', None)
+        default_tags = dict(tardis_machine_name=platform.node())
+        default_tags.update(getattr(config, 'default_tags', {}))
         self.metric = getattr(config, 'metric', 'tardis_data')
 
         self.client = aiotelegraf.Client(host=host, port=port, tags=default_tags)

Add information about hostname to logging config
The logging configuration should include information about the *hostname*. Currently it works implicitly via the global configuration for telegraf but this can be disabled by the user.

To ensure the availability of information about the host and reduce external dependency we should explicitly include host information into the tardis config:

* [x] include `hostname` information in tardis config
* [x] add documentation about `hostname` field in config
diff --git a/tests/plugins_t/test_telegrafmonitoring.py b/tests/plugins_t/test_telegrafmonitoring.py
index 955dd24..c2da69f 100644
--- a/tests/plugins_t/test_telegrafmonitoring.py
+++ b/tests/plugins_t/test_telegrafmonitoring.py
@@ -10,6 +10,8 @@ from unittest.mock import patch
 from ..utilities.utilities import async_return
 from ..utilities.utilities import run_async
 
+import platform
+
 
 class TestTelegrafMonitoring(TestCase):
     @classmethod
@@ -26,11 +28,11 @@ class TestTelegrafMonitoring(TestCase):
 
     @patch('tardis.plugins.telegrafmonitoring.logging', Mock())
     def setUp(self):
-        config = self.mock_config.return_value
-        config.Plugins.TelegrafMonitoring.host = "telegraf.test"
-        config.Plugins.TelegrafMonitoring.port = 1234
-        config.Plugins.TelegrafMonitoring.default_tags = {'test_tag': 'test'}
-        config.Plugins.TelegrafMonitoring.metric = "tardis_data"
+        self.config = self.mock_config.return_value
+        self.config.Plugins.TelegrafMonitoring.host = "telegraf.test"
+        self.config.Plugins.TelegrafMonitoring.port = 1234
+        self.config.Plugins.TelegrafMonitoring.default_tags = {'test_tag': 'test'}
+        self.config.Plugins.TelegrafMonitoring.metric = "tardis_data"
 
         telegraf_client = self.mock_aiotelegraf.Client.return_value
         telegraf_client.connect.return_value = async_return()
@@ -50,7 +52,24 @@ class TestTelegrafMonitoring(TestCase):
                            updated=datetime.timestamp(test_param.updated))
         test_tags = dict(site_name=test_param.site_name, machine_type=test_param.machine_type)
         run_async(self.plugin.notify, test_state, test_param)
-        self.mock_aiotelegraf.Client.assert_called_with(host='telegraf.test', port=1234, tags={'test_tag': 'test'})
+        self.mock_aiotelegraf.Client.assert_called_with(host='telegraf.test', port=1234,
+                                                        tags={'tardis_machine_name': platform.node(),
+                                                              'test_tag': 'test'})
+        self.mock_aiotelegraf.Client.return_value.connect.assert_called_with()
+        self.mock_aiotelegraf.Client.return_value.metric.assert_called_with('tardis_data', test_result, tags=test_tags)
+        self.mock_aiotelegraf.Client.return_value.close.assert_called_with()
+
+        self.mock_aiotelegraf.reset()
+
+        # Test to overwrite tardis_node_name in plugin configuration
+        self.config.Plugins.TelegrafMonitoring.default_tags = {'test_tag': 'test',
+                                                               'tardis_machine_name': 'my_test_node'}
+        self.plugin = TelegrafMonitoring()
+        run_async(self.plugin.notify, test_state, test_param)
+
+        self.mock_aiotelegraf.Client.assert_called_with(host='telegraf.test', port=1234,
+                                                        tags={'tardis_machine_name': 'my_test_node',
+                                                              'test_tag': 'test'})
         self.mock_aiotelegraf.Client.return_value.connect.assert_called_with()
         self.mock_aiotelegraf.Client.return_value.metric.assert_called_with('tardis_data', test_result, tags=test_tags)
         self.mock_aiotelegraf.Client.return_value.close.assert_called_with()

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-asyncio
3.7
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aiohttp==3.8.6
aiosignal==1.3.1
aiotelegraf==0.4.0
async-timeout==4.0.3
AsyncOpenStackClient==0.9.0
asyncssh==2.20.0
asynctest==0.13.0
attrs==24.2.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
cffi==1.15.1
charset-normalizer==3.4.1
CloudStackAIO==0.0.8
cobald==0.13.0
-e git+https://github.com/MatterMiners/tardis.git@06d67fbbd6e3a4cf6cee51f871f86f3fdc25405a#egg=cobald_tardis
cryptography==44.0.2
entrypoints==0.4
exceptiongroup==1.2.2
frozenlist==1.3.3
idna==3.10
importlib-metadata==6.7.0
iniconfig==2.0.0
json-encoder==0.4.4
multidict==6.0.5
outcome==1.3.0.post0
packaging==24.0
pluggy==1.2.0
pycparser==2.21
pytelegraf==0.3.3
pytest==7.4.4
pytest-asyncio==0.21.2
python-dateutil==2.8.0
python-status==1.0.1
PyYAML==6.0.1
requests==2.31.0
simple-rest-client==0.5.4
simplejson==3.16.0
singledispatch==4.0.0
six==1.17.0
sniffio==1.3.1
sortedcontainers==2.4.0
tomli==2.0.1
toposort==1.10
trio==0.22.2
typing_extensions==4.7.1
urllib3==2.0.7
yarl==1.9.4
zipp==3.15.0

name: tardis
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aiohttp==3.8.6
      - aiosignal==1.3.1
      - aiotelegraf==0.4.0
      - async-timeout==4.0.3
      - asyncopenstackclient==0.9.0
      - asyncssh==2.20.0
      - asynctest==0.13.0
      - attrs==24.2.0
      - cffi==1.15.1
      - charset-normalizer==3.4.1
      - cloudstackaio==0.0.8
      - cobald==0.13.0
      - cryptography==44.0.2
      - entrypoints==0.4
      - exceptiongroup==1.2.2
      - frozenlist==1.3.3
      - idna==3.10
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - json-encoder==0.4.4
      - multidict==6.0.5
      - outcome==1.3.0.post0
      - packaging==24.0
      - pluggy==1.2.0
      - pycparser==2.21
      - pytelegraf==0.3.3
      - pytest==7.4.4
      - pytest-asyncio==0.21.2
      - python-dateutil==2.8.0
      - python-status==1.0.1
      - pyyaml==6.0.1
      - requests==2.31.0
      - simple-rest-client==0.5.4
      - simplejson==3.16.0
      - singledispatch==4.0.0
      - six==1.17.0
      - sniffio==1.3.1
      - sortedcontainers==2.4.0
      - tomli==2.0.1
      - toposort==1.10
      - trio==0.22.2
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - yarl==1.9.4
      - zipp==3.15.0
prefix: /opt/conda/envs/tardis

tests/plugins_t/test_telegrafmonitoring.py::TestTelegrafMonitoring::test_notify
docs/source/plugins/plugins.rst tardis/plugins/telegrafmonitoring.py
docs/source/plugins/plugins.rst tardis/plugins/telegrafmonitoring.py