53 lines
1.5 KiB
Bash
Executable File
53 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
LEARNING_LOG="/var/log/wevads_learning.log"
|
|
KNOWLEDGE_BASE="/opt/wevads/rag/knowledge_base.json"
|
|
|
|
log_learning() {
|
|
local incident=$1
|
|
local action=$2
|
|
local result=$3
|
|
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] INCIDENT: $incident" >> "$LEARNING_LOG"
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ACTION: $action" >> "$LEARNING_LOG"
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] RESULT: $result" >> "$LEARNING_LOG"
|
|
echo "---" >> "$LEARNING_LOG"
|
|
|
|
# Mettre à jour la base de connaissances RAG
|
|
if [ -f "/opt/wevads/scripts/rag-processor.py" ]; then
|
|
python3 -c "
|
|
import json, sys
|
|
incident = '''$incident'''
|
|
action = '''$action'''
|
|
result = '''$result'''
|
|
|
|
try:
|
|
with open('$KNOWLEDGE_BASE', 'r') as f:
|
|
data = json.load(f)
|
|
except:
|
|
data = {'incidents': []}
|
|
|
|
data['incidents'].append({
|
|
'timestamp': '$(date -Iseconds)',
|
|
'incident': incident[:500],
|
|
'action': action,
|
|
'result': result
|
|
})
|
|
|
|
with open('$KNOWLEDGE_BASE', 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
print('Knowledge base updated')
|
|
"
|
|
fi
|
|
}
|
|
|
|
# Exemple d'apprentissage depuis les incidents récents
|
|
if [ -f "/var/log/wevads_autofix.log" ]; then
|
|
LAST_INCIDENT=$(tail -5 /var/log/wevads_autofix.log | grep -i "problem\|error\|issue" | head -1)
|
|
LAST_ACTION=$(tail -5 /var/log/wevads_autofix.log | grep -i "fix\|repair\|action" | head -1)
|
|
|
|
if [ -n "$LAST_INCIDENT" ] && [ -n "$LAST_ACTION" ]; then
|
|
log_learning "$LAST_INCIDENT" "$LAST_ACTION" "resolved"
|
|
echo "✅ Incident appris et ajouté à la base de connaissances"
|
|
fi
|
|
fi
|