File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
etc/kayobe/ansible/scripts Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,14 @@ def run_command(command, parse_json=False):
78
78
return json .loads (result .stdout )
79
79
return result .stdout .strip ()
80
80
81
+ def camel_to_snake (name ):
82
+ """
83
+ Convert a CamelCase string to snake_case.
84
+
85
+ Reference: https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
86
+ """
87
+ return re .sub (r'(?<!^)(?=[A-Z])' , '_' , name ).lower ()
88
+
81
89
def parse_device_info (device ):
82
90
"""
83
91
Produce Prometheus lines describing the device's identity and SMART status:
@@ -145,8 +153,7 @@ def parse_if_attributes(device):
145
153
if callable (val ):
146
154
continue # skip methods
147
155
148
- # Convert CamelCase or PascalCase -> snake_case, e.g. dataUnitsRead -> data_units_read
149
- snake_name = re .sub (r'(?<!^)(?=[A-Z])' , '_' , attr_name ).lower ()
156
+ snake_name = camel_to_snake (attr_name )
150
157
151
158
if snake_name in SMARTMON_ATTRS and isinstance (val , (int , float )):
152
159
metrics .append (f"{ snake_name } {{{ labels } }} { val } " )
You can’t perform that action at this time.
0 commit comments