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):
7878 return json .loads (result .stdout )
7979 return result .stdout .strip ()
8080
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+
8189def parse_device_info (device ):
8290 """
8391 Produce Prometheus lines describing the device's identity and SMART status:
@@ -145,8 +153,7 @@ def parse_if_attributes(device):
145153 if callable (val ):
146154 continue # skip methods
147155
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 )
150157
151158 if snake_name in SMARTMON_ATTRS and isinstance (val , (int , float )):
152159 metrics .append (f"{ snake_name } {{{ labels } }} { val } " )
You can’t perform that action at this time.
0 commit comments