diff --git a/zabbix-agent-scripts/get_nc_quota_metrics.py b/zabbix-agent-scripts/get_nc_quota_metrics.py new file mode 100644 index 0000000..4c198d1 --- /dev/null +++ b/zabbix-agent-scripts/get_nc_quota_metrics.py @@ -0,0 +1,41 @@ +import subprocess + +import pandas as pd + +import io + +import json + +## The command usage-report:generate is provided by the app +## user_usage_report, that must be installed and enabled in +## the system. +## JSON output would be easier to parse but it actually isn't +## as the JSON file created is not correctly formatted as a JSON +## file. +result_set = subprocess.check_output( + ["occ", "usage-report:generate"] + ) + +result_set = result_set.decode() + +column_names = [ + "userid","extract_date","assigned_quota", "used_quota", + "files", "shares","uploads", "downloads" + ] + +df = pd.read_csv( + io.StringIO(result_set), + names=column_names + ) + +## Transformation to int is necessary as json library cannot serialize numpy +## data types +results = { + "total_number_of_users": int(df.userid.count()), + "total_assigned_quota_gb": df.assigned_quota.agg("sum")/1024/1024/1024, + "total_used_quota_gb": df.used_quota.agg("sum")/1024/1024/1024 + } + +json.dump(results, + open("/var/lib/zabbix/output/nc_quota_metrics.json","w") + ) diff --git a/zabbix_agentd.conf.d/zabbix-agent-nextcloud.conf b/zabbix_agentd.conf.d/zabbix-agent-nextcloud.conf index 520d4f1..cdc77d1 100644 --- a/zabbix_agentd.conf.d/zabbix-agent-nextcloud.conf +++ b/zabbix_agentd.conf.d/zabbix-agent-nextcloud.conf @@ -1,5 +1,7 @@ UserParameter=nc_metric[*],/opt/pyvenv/ncmonitor/bin/python /var/lib/zabbix/scripts/read_nc_metrics.py $1 +UserParameter=nc_quota_metric[*],cat /var/lib/zabbix/output/nc_quota_metrics.json UserParameter=storage_metric[*],/opt/pyvenv/ncmonitor/bin/python /var/lib/zabbix/scripts/read_storage_metrics.py $1 +UserParameter=db_full_version[*],mysql --version UserParameter=db_metric[*],/opt/pyvenv/ncmonitor/bin/python /var/lib/zabbix/scripts/read_db_metrics.py $1 $2 UserParameter=db_metric_discovery,/opt/pyvenv/ncmonitor/bin/python /var/lib/zabbix/scripts/discover_db_metrics.py UserParameter=apache2_user_agent_metric[*],/opt/pyvenv/ncmonitor/bin/python /var/lib/zabbix/scripts/read_apache2_user_agent_metrics.py $1