File: //usr/local/packages/@appstore/ActiveInsight/collectors/feature.py
#!/usr/bin/python
import os
import json
import subprocess
MIB_RESOURCE_MONITOR_CONF = "/var/packages/ActiveInsight/target/configs/resource_monitor.json"
MIB_RESOURCE_MONITOR_FEATURES_CONF = "/var/packages/ActiveInsight/var/mibresourcemonitor_features.json"
MEMORY_LIMITED_MODELS = [
"DS220j",
"DS120j",
"DS419slim",
"DS218j",
"RS217",
"DS416j",
"DS416slim",
"DS216",
"DS216j",
"DS215j",
"DS115",
"RS214",
"DS414j",
"DS414slim",
"DS214",
"DS114",
"DS213j",
"DS115j",
"DS119j",
"DS214se",
"DS216se",
]
def is_memory_limited_model() -> bool:
result = subprocess.run(
[
"/usr/syno/bin/synowebapi",
"--exec",
"api=SYNO.Core.System",
"method=info",
"version=3",
],
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
)
if result.returncode != 0:
return False
response = json.loads(result.stdout.decode("utf-8"))
if response.get("success", False) is False:
return False
return response.get("data", {}).get("model", "") in MEMORY_LIMITED_MODELS
def collect_features():
results = []
if not os.path.exists(MIB_RESOURCE_MONITOR_FEATURES_CONF):
# workaround for Active Insight 3.0.1 and 3.0.2
with open(MIB_RESOURCE_MONITOR_CONF, "r") as f:
config = json.load(f)
if config.get("enable_file_activity_module", False) is False:
results.append(
{
"application": "ActiveInsight",
"name": "feature",
"type": "info",
"label": {
"name": "FILE_ACTIVITY",
},
"attribute": {
"disable": "true",
"disable_reason": "WITHOUT_ENOUGH_MEMORY" if is_memory_limited_model() else "UNKNOWN_REASON",
},
}
)
return results
with open(MIB_RESOURCE_MONITOR_FEATURES_CONF, "r", encoding="utf-8") as f:
features = json.load(f)
for feature_key, feature_attr in features.items():
disable = feature_attr.get("disable", False)
results.append(
{
"application": "ActiveInsight",
"name": "feature",
"type": "info",
"label": {
"name": feature_key,
},
"attribute": {
"disable": "true" if disable else "false",
"disable_reason": feature_attr.get("disable_reason", ""),
},
}
)
return results