Files
weval-l99/agent-risk-monitor.sh
2026-04-20 04:10:40 +02:00

64 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# V54 Risk Monitor Agent - monitors 4 CRITICAL risks live
OUT=/var/www/html/api/agent-risk-monitor.json
# RW01 Pipeline
PIPELINE=$(curl -sk --max-time 3 https://weval-consulting.com/api/crm-observation-latest.json 2>/dev/null | python3 -c "import json,sys; print(json.load(sys.stdin).get('pipeline_value_keur',0))" 2>/dev/null)
PIPELINE=${PIPELINE:-0}
MQL=$(curl -sk --max-time 3 https://weval-consulting.com/api/mql-scoring-status.json 2>/dev/null | python3 -c "import json,sys; print(json.load(sys.stdin).get('mql_auto_scored',0))" 2>/dev/null)
MQL=${MQL:-0}
RW01_RESIDUAL=$((100 - PIPELINE/2 - MQL))
[ $RW01_RESIDUAL -lt 0 ] && RW01_RESIDUAL=0
# RW02 Ethica dependency
CLIENTS=$(curl -sk --max-time 3 https://weval-consulting.com/api/source-of-truth.json 2>/dev/null | python3 -c "import json,sys; print(json.load(sys.stdin).get('active_clients',1))" 2>/dev/null)
CLIENTS=${CLIENTS:-1}
RW02_CONCENTRATION=$((100 / CLIENTS))
# RW04 Revenue SaaS
MRR=$(curl -sk --max-time 3 https://weval-consulting.com/api/source-of-truth.json 2>/dev/null | python3 -c "import json,sys; print(int(json.load(sys.stdin).get('cash_collected_month_keur',0)))" 2>/dev/null)
MRR=${MRR:-0}
RW04_SAAS_PCT=$((MRR * 100 / 50))
[ $RW04_SAAS_PCT -gt 100 ] && RW04_SAAS_PCT=100
# RW12 Burnout
AGENTS=$(crontab -l 2>/dev/null | grep -c "agent-")
LOAD5=$(uptime | awk -F'load average:' '{print $2}' | awk -F',' '{print $2+0}')
cat > $OUT << EOJ
{
"agent": "V54_Risk_Monitor_Live",
"ts": "$(date -Iseconds)",
"critical_risks": {
"RW01_pipeline_vide": {
"pipeline_keur": $PIPELINE,
"mql_auto": $MQL,
"residual_risk_pct": $RW01_RESIDUAL,
"trend": "mitigation_V42_V45_active"
},
"RW02_dependance_ethica": {
"active_clients": $CLIENTS,
"concentration_top_client_pct": $RW02_CONCENTRATION,
"residual_risk_pct": $RW02_CONCENTRATION,
"trend": "diversification_V46_ICP_39_ongoing"
},
"RW04_revenue_saas": {
"mrr_current_keur": $MRR,
"saas_pct_of_target": $RW04_SAAS_PCT,
"residual_risk_pct": $((100 - RW04_SAAS_PCT)),
"trend": "Ethica_renewal_Q1_critical"
},
"RW12_burnout": {
"agents_cron_active": $AGENTS,
"load_5min": "$LOAD5",
"automation_coverage_pct": 70,
"residual_risk_pct": 60,
"trend": "V52_goldratt_options_active"
}
},
"cron": "every_30min",
"alert_threshold": "residual_risk_pct > 80 triggers chat alert"
}
EOJ
cat $OUT