mirror of
https://github.com/kemko/keenetic-grafana-monitoring.git
synced 2026-01-01 15:45:43 +03:00
Migrate to json path
This commit is contained in:
committed by
Vitaliy Skrypnyk
parent
abc26e4875
commit
cba96f79c3
@@ -2,33 +2,32 @@ import re
|
||||
|
||||
|
||||
def isstring(value): return isinstance(value, str)
|
||||
|
||||
|
||||
def isfloat(value: str): return (re.match(r'^-?\d+(?:\.\d+)?$', value) is not None)
|
||||
|
||||
|
||||
def isinteger(value: str): return (re.match('^\d+$', value) is not None)
|
||||
|
||||
|
||||
def isvalidmetric(value) : return isinstance(value, int) or isinstance(value, float) or isinstance(value, bool)
|
||||
|
||||
def normalize_data(data):
|
||||
if isinstance(data, dict):
|
||||
for key in data:
|
||||
def normalize_value(value):
|
||||
|
||||
value = data.get(key)
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if isstring(value):
|
||||
value = remove_data_unit(value)
|
||||
if isinteger(value):
|
||||
data[key] = int(value)
|
||||
continue
|
||||
if isfloat(value):
|
||||
data[key] = float(value)
|
||||
continue
|
||||
if isstring(value):
|
||||
value = parse_string(value)
|
||||
|
||||
if isvalidmetric(value):
|
||||
return value
|
||||
else:
|
||||
print("WARN Value: " + str(value) + " is not valid metric type")
|
||||
return None
|
||||
|
||||
|
||||
return data
|
||||
def parse_string(value):
|
||||
value = remove_data_unit(value)
|
||||
if isinteger(value):
|
||||
value = int(value)
|
||||
elif isfloat(value):
|
||||
value = float(value)
|
||||
return value
|
||||
|
||||
|
||||
def remove_data_unit(value: str):
|
||||
|
||||
Reference in New Issue
Block a user