diff --git a/zabbix-agent-scripts/get_nc_quota_metrics.py b/zabbix-agent-scripts/get_nc_quota_metrics.py index 78f7fe5..ed06bb5 100644 --- a/zabbix-agent-scripts/get_nc_quota_metrics.py +++ b/zabbix-agent-scripts/get_nc_quota_metrics.py @@ -32,7 +32,7 @@ ## as the JSON file created is not correctly formatted as a JSON ## file. result_set = subprocess.check_output( - ["/usr/bin/php", "/var/www/nextcloud/occ", "usage-report:generate"] + ["sudo", "-u", "www-data", "/usr/bin/php", "/var/www/nextcloud/occ", "usage-report:generate"] ) result_set = result_set.decode() @@ -48,7 +48,16 @@ ) ## In some cases assigned_quota get the value of -2 or 'none'. In these cases, we are replacing with 0 -df["assigned_quota"] = pd.to_numeric(df.assigned_quota.str.replace('none','0').str.replace('-2','0')) +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) + +df["assigned_quota"] = df.assigned_quota.apply(trf_to_nr) ## Transformation to int is necessary as json library cannot serialize numpy ## data types