diff --git a/zabbix-agent-scripts/get_nc_quota_metrics.py b/zabbix-agent-scripts/get_nc_quota_metrics.py index ed06bb5..59124ac 100644 --- a/zabbix-agent-scripts/get_nc_quota_metrics.py +++ b/zabbix-agent-scripts/get_nc_quota_metrics.py @@ -47,17 +47,19 @@ names=column_names ) -## In some cases assigned_quota get the value of -2 or 'none'. In these cases, we are replacing with 0 -df["assigned_quota"] = df.assigned_quota.str.replace('none','0').str.replace('-2','0') +## In some cases assigned_quota get the value of -2 or 'none'. In these cases, we are replacing with 0. +## If the field is not of type string don't do anything. +if df.assigned_quota.dtype.name == 'object': + df["assigned_quota"] = df.assigned_quota.str.replace('none','0').str.replace('-2','0') -# See https://github.com/nextcloud/user_usage_report/issues/200 -def trf_to_nr(elem): - if 'GB' in elem: - return int(elem.split()[0])*1024*1024*1024 - else: - return int(elem) + # See https://github.com/nextcloud/user_usage_report/issues/200 + def trf_to_nr(elem): + if 'GB' in elem: + return int(elem.split()[0])*1024*1024*1024 + else: + return int(elem) -df["assigned_quota"] = df.assigned_quota.apply(trf_to_nr) + df["assigned_quota"] = df.assigned_quota.apply(trf_to_nr) ## Transformation to int is necessary as json library cannot serialize numpy ## data types