-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathfetch_telemetry_status.py
More file actions
89 lines (71 loc) · 2.65 KB
/
Copy pathfetch_telemetry_status.py
File metadata and controls
89 lines (71 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Ansible module to fetch telemetry status."""
import os
import yaml
from ansible.module_utils.basic import AnsibleModule
TELEMETRY_CONFIG_FILE_NAME = "telemetry_config.yml"
def load_yaml(path):
"""
Load YAML from a given file path.
Args:
path (str): The path to the YAML file.
Returns:
dict: The loaded YAML data.
Raises:
FileNotFoundError: If the file does not exist.
"""
if not os.path.isfile(path):
raise FileNotFoundError(f"Config file not found: {path}")
with open(path, "r", encoding = "utf-8") as file:
return yaml.safe_load(file)
def main():
"""
This function is the main entry point of the Ansible module.
It takes telemetry config file path as a parameter.
This function loads the telemetry configuration from a YAML file,
checks the status of various telemetry components,
and returns the status as a list.
Parameters:
input_path: path to input files
Returns:
A list containing the telemetry status.
Raises:
None
"""
module_args = {
"input_path": {
"type": "path", "required": True
}
}
module = AnsibleModule(argument_spec=module_args)
input_dir_path = module.params["input_path"]
telemetry_config_path = os.path.join(input_dir_path, TELEMETRY_CONFIG_FILE_NAME)
telemetry_config_data = load_yaml(telemetry_config_path)
telemetry_status_list = []
telemetry_sources = telemetry_config_data.get("telemetry_sources", {})
if telemetry_sources.get("idrac", {}).get("metrics_enabled", False):
telemetry_status_list.append("idrac_telemetry")
# Check UFM telemetry
ufm_config = telemetry_sources.get("ufm", {})
if ufm_config.get("metrics_enabled", False):
telemetry_status_list.append("ufm_telemetry")
if ufm_config.get("logs_enabled", False):
telemetry_status_list.append("ufm_logs")
module.exit_json(
changed=False,
telemetry_status_list=telemetry_status_list
)
if __name__ == "__main__":
main()