fix(ops): sync verified production baseline for AW-Rus DLP

This commit is contained in:
igor04091968
2026-05-13 22:50:42 +03:00
parent 22aadd5c03
commit 91c3b46f16
20 changed files with 661 additions and 127 deletions
+2 -2
View File
@@ -2,6 +2,8 @@
Description=AW Worktime Report API
After=network.target activitywatch-server.service
Wants=activitywatch-server.service
StartLimitBurst=3
StartLimitIntervalSec=60
[Service]
Type=simple
@@ -9,8 +11,6 @@ EnvironmentFile=/etc/activitywatch/aw-server.env
ExecStart=/usr/bin/python3 /usr/local/bin/aw-worktime-api.py
Restart=on-failure
RestartSec=5
StartLimitBurst=3
StartLimitIntervalSec=60
User=activitywatch
Group=activitywatch
StandardOutput=journal
+2 -2
View File
@@ -2,6 +2,8 @@
Description=AW Worktime UI bridge (sessions -> afk/window)
After=network-online.target activitywatch-server.service
Wants=network-online.target
StartLimitBurst=3
StartLimitIntervalSec=120
[Service]
Type=simple
@@ -10,8 +12,6 @@ Environment=AW_WORKTIME_HOST=SHARKON2025
ExecStart=/usr/bin/python3 /usr/local/bin/aw-worktime-ui-bridge.py
Restart=on-failure
RestartSec=10
StartLimitBurst=3
StartLimitIntervalSec=120
User=activitywatch
Group=activitywatch
StandardOutput=journal
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
BASE_DIR="/opt/activitywatch/dlp-content-analysis"
VENV_PY="$BASE_DIR/.venv/bin/python"
ANALYZER="$BASE_DIR/content_analyzer.py"
if [ ! -x "$VENV_PY" ]; then
echo "ERROR: content-analysis virtualenv is missing: $VENV_PY" >&2
exit 1
fi
exec "$VENV_PY" "$ANALYZER" "$@"
@@ -2,6 +2,8 @@
Description=AW DLP Policy Engine
After=network.target activitywatch-server.service
Wants=activitywatch-server.service
StartLimitBurst=3
StartLimitIntervalSec=60
[Service]
Type=simple
@@ -10,8 +12,6 @@ WorkingDirectory=/opt/activitywatch/dlp-policy-engine
ExecStart=/opt/activitywatch/dlp-policy-engine/.venv/bin/uvicorn policy_service:app --host ${AW_DLP_POLICY_ENGINE_BIND_HOST} --port ${AW_DLP_POLICY_ENGINE_PORT}
Restart=on-failure
RestartSec=5
StartLimitBurst=3
StartLimitIntervalSec=60
User=activitywatch
Group=activitywatch
StandardOutput=journal
+12 -103
View File
@@ -40,115 +40,24 @@ check_api_endpoint() {
}
check_dlp_transport_freshness() {
local api_base="${1:-http://127.0.0.1:5600/api/0}"
local max_age_seconds="${2:-900}"
local strict_fileops="${3:-0}"
local dlp_health="${DLP_HEALTH_BIN:-/usr/local/bin/dlp-health-check}"
local result
if ! command -v python3 >/dev/null 2>&1; then
echo "⚠ python3 is not available, skipping DLP transport freshness checks"
WARNINGS+=("dlp-transport-check-skipped")
if [[ ! -x "$dlp_health" ]]; then
echo "⚠ dlp-health-check is not available, skipping DLP transport freshness checks"
WARNINGS+=("dlp-health-check-missing")
return
fi
result="$(python3 - "$api_base" "$max_age_seconds" "$strict_fileops" <<'PY'
import json
import sys
import time
from urllib.request import urlopen
api_base = sys.argv[1].rstrip("/")
max_age = int(sys.argv[2])
strict_fileops = str(sys.argv[3]).strip().lower() in ("1", "true", "yes", "on")
now = time.time()
def parse_ts(ts):
if not ts:
return None
ts = ts.replace("Z", "+00:00")
try:
from datetime import datetime
return datetime.fromisoformat(ts).timestamp()
except Exception:
return None
def get_json(url):
with urlopen(url, timeout=8) as resp:
return json.loads(resp.read().decode("utf-8"))
out = {
"ok": True,
"warnings": [],
"errors": []
}
try:
buckets = get_json(f"{api_base}/buckets/")
except Exception as ex:
out["ok"] = False
out["errors"].append(f"dlp-buckets-read-failed:{ex}")
print(json.dumps(out))
sys.exit(0)
endpoint = [k for k in buckets.keys() if k.startswith("aw-dlp-endpoint-signals_")]
fileops = [k for k in buckets.keys() if k.startswith("aw-file-operations_")]
if not endpoint:
out["ok"] = False
out["errors"].append("no-endpoint-signal-buckets")
if not fileops:
out["warnings"].append("no-file-operations-buckets")
def check_bucket_freshness(bucket_id, label):
b = buckets.get(bucket_id, {})
meta = b.get("metadata") or {}
end = parse_ts(meta.get("end"))
if end is None:
# Some aw-server deployments may not populate metadata.end; fallback to latest event.
try:
events = get_json(f"{api_base}/buckets/{bucket_id}/events?limit=1")
if events:
end = parse_ts(events[0].get("timestamp"))
except Exception:
end = None
if end is None:
out["warnings"].append(f"{label}:no-end-ts-or-events:{bucket_id}")
result="$("$dlp_health" --json 2>/dev/null || true)"
if [[ -z "$result" ]]; then
echo "⚠ dlp-health-check did not return JSON, skipping DLP transport freshness checks"
WARNINGS+=("dlp-health-check-empty")
return
age = int(now - end)
if age > max_age:
if label == "fileops" and not strict_fileops:
out["warnings"].append(f"{label}:stale:{bucket_id}:age={age}s")
else:
out["ok"] = False
out["errors"].append(f"{label}:stale:{bucket_id}:age={age}s")
for bid in endpoint:
check_bucket_freshness(bid, "endpoint")
for bid in fileops:
check_bucket_freshness(bid, "fileops")
# Validate that endpoint self_test contains transport metrics at least once recently.
for bid in endpoint:
try:
events = get_json(f"{api_base}/buckets/{bid}/events?limit=20")
found = False
for e in events:
d = e.get("data") or {}
if d.get("signalType") == "self_test":
if all(k in d for k in ("queueDepth", "eventsEnqueued", "eventsFlushed", "sendFailures")):
found = True
break
if not found:
out["warnings"].append(f"endpoint:self_test-metrics-missing:{bid}")
except Exception as ex:
out["warnings"].append(f"endpoint:self_test-read-failed:{bid}:{ex}")
print(json.dumps(out))
PY
)" || true
fi
local ok
ok="$(printf '%s' "$result" | python3 -c 'import json,sys; d=json.load(sys.stdin); print("1" if d.get("ok") else "0")' 2>/dev/null || echo "0")"
ok="$(printf '%s' "$result" | python3 -c 'import json,sys; data=json.load(sys.stdin); names={r["name"]:r for r in data.get("results", [])}; checks=["buckets:endpoint-signals","buckets:file-operations","endpoint-self-test-metrics"]; bad=[n for n in checks if names.get(n,{}).get("status")=="fail"]; print("1" if not bad else "0")' 2>/dev/null || echo "0")"
if [[ "$ok" == "1" ]]; then
echo "✓ DLP transport freshness check passed"
else
@@ -157,8 +66,8 @@ PY
fi
local errors warnings
errors="$(printf '%s' "$result" | python3 -c 'import json,sys; d=json.load(sys.stdin); print(", ".join(d.get("errors", [])))' 2>/dev/null || true)"
warnings="$(printf '%s' "$result" | python3 -c 'import json,sys; d=json.load(sys.stdin); print(", ".join(d.get("warnings", [])))' 2>/dev/null || true)"
errors="$(printf '%s' "$result" | python3 -c 'import json,sys; data=json.load(sys.stdin); out=[]; [out.append(f"{r.get(\"name\")}:{r.get(\"summary\")}") for r in data.get("results", []) if r.get("status")=="fail" and r.get("name") in ("buckets:endpoint-signals","buckets:file-operations","endpoint-self-test-metrics")]; print(", ".join(out))' 2>/dev/null || true)"
warnings="$(printf '%s' "$result" | python3 -c 'import json,sys; data=json.load(sys.stdin); out=[]; [out.append(f"{r.get(\"name\")}:{r.get(\"summary\")}") for r in data.get("results", []) if r.get("status")=="warn" and r.get("name") in ("buckets:endpoint-signals","buckets:file-operations","endpoint-self-test-metrics")]; print(", ".join(out))' 2>/dev/null || true)"
if [[ -n "$errors" ]]; then
echo " errors: $errors"
fi