summaryrefslogtreecommitdiff
path: root/modules/telegraf/core.py
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@ut.ee>2025-05-11 15:43:31 +0300
committerRasmus Luha <rasmus.luha@ut.ee>2025-05-11 15:43:31 +0300
commit137b8a988f77e957feed698494f7143ac06a7b51 (patch)
treed330750cc63ebbe38a0187002c7cd637eb3f687e /modules/telegraf/core.py
parent9a332ab302a2f05ce4924a66647dec03fb3b1366 (diff)
add diffJsonRootPath template to telegraf
Diffstat (limited to 'modules/telegraf/core.py')
-rw-r--r--modules/telegraf/core.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/modules/telegraf/core.py b/modules/telegraf/core.py
index 64fe893..0c9f9c7 100644
--- a/modules/telegraf/core.py
+++ b/modules/telegraf/core.py
@@ -10,6 +10,7 @@ import config
import toml
import shutil
+import sys
@@ -26,7 +27,6 @@ def introduction():
def modify_template(new_pipeline_path, api_url, schedulingPeriod, data_values, measurement_name, api_username, api_password, template_name):
-
## Pipeline interval
telegraf_utils.modify_agent(new_pipeline_path,"interval", schedulingPeriod)
@@ -39,32 +39,29 @@ def modify_template(new_pipeline_path, api_url, schedulingPeriod, data_values, m
if template_name == "basic_ETL.toml":
-
for key, value in data_values.items():
fields.append(key)
-
parts = value.rsplit('.', 2)
json_query = '.'.join(parts[:-1])[1:] # Get the json path till last item (second last dot(.))
-
telegraf_utils.modify_input(new_pipeline_path,"json_query", json_query)
telegraf_utils.modify_input(new_pipeline_path,"fieldinclude", fields)
-
elif template_name == "advanced_ETL.toml":
-
for key, value in data_values.items():
-
parts = value.split(']', 1)
json_query = parts[0].split("[")[0][1:]
fields.append(parts[1][1:])
-
-
telegraf_utils.modify_input(new_pipeline_path,"json_query", json_query)
telegraf_utils.modify_input(new_pipeline_path,"json_string_fields", fields)
-
-
-
+ elif template_name == "different_jsonPaths_ETL.toml":
+ for key, value in data_values.items():
+ fields.append(value[1:].replace(".","_"))
+ telegraf_utils.modify_input(new_pipeline_path, "fieldpass", fields)
+ #sys.exit(1)
+ else:
+ print("Malli valimisel tekkis probleem...")
+ sys.exit(1)
## Measurement
telegraf_utils.modify_input(new_pipeline_path,"name_override", measurement_name)
@@ -82,8 +79,6 @@ def modify_template(new_pipeline_path, api_url, schedulingPeriod, data_values, m
telegraf_utils.modify_input(new_pipeline_path,"password", api_password)
-
-
def build_pipeline():
if config.INTERACTIVE_MODE:
data_values, api_url, api_username, api_password= common.get_data_values()
@@ -103,14 +98,22 @@ def build_pipeline():
api_password = config.API_PASSWORD
measurement_name = config.MEASUREMENT_NAME
+
+ ### Select template
+ ## Check if multiple root json paths template should be used
+ prev=""
+ multpleJsonPaths=False
+ for el in data_values.values():
+ cur = el.split(".", 2)[1]
+ if cur != prev and prev != "":
+ multpleJsonPaths = True
+ prev = cur
-
- ### Select template
- ##TODO
- #template_name="basic_ETL.toml"
if (api_username and api_username.lower() != "placeholder") and (api_password and api_password.lower() != "placeholder"):
template_name="advanced_ETL.toml"
+ elif multpleJsonPaths:
+ template_name="different_jsonPaths_ETL.toml"
else:
template_name="basic_ETL.toml"