fix: correct execution headings, variableize LOG_DIR, fix dead alert path
PR Pipeline — Authorize → Validate → Review → Merge / auth (pull_request) Successful in 4s
PR Pipeline — Authorize → Validate → Review → Merge / validate (pull_request) Successful in 11s
PR Pipeline — Authorize → Validate → Review → Merge / lint (pull_request) Successful in 6s
PR Pipeline — Authorize → Validate → Review → Merge / ai-review (pull_request) Successful in 4s
PR Pipeline — Authorize → Validate → Review → Merge / gate (pull_request) Successful in 2s
PR Pipeline — Authorize → Validate → Review → Merge / auth (pull_request) Successful in 4s
PR Pipeline — Authorize → Validate → Review → Merge / validate (pull_request) Successful in 11s
PR Pipeline — Authorize → Validate → Review → Merge / lint (pull_request) Successful in 6s
PR Pipeline — Authorize → Validate → Review → Merge / ai-review (pull_request) Successful in 4s
PR Pipeline — Authorize → Validate → Review → Merge / gate (pull_request) Successful in 2s
1. Replace '(## Execution' + ')' with '## Execution' in 6 contract files 2. Make LOG_DIR honor CONTRACT_RUN_LOG_DIR env var (default: /var/log/contract-runs) 3. Fix Zulip alert: correct URL (https://chat.sysloggh.net/api/v1), user (abiba-bot@chat.sysloggh.net), take ZULIP_API_KEY from environment, and write alert failures to run log
This commit is contained in:
+34
-22
@@ -2,7 +2,11 @@
|
||||
# contract-run.sh — Deterministic contract execution from machine scheduler
|
||||
#
|
||||
# Takes a contract name, resolves its script, runs it with timeout,
|
||||
# logs output to /var/log/contract-runs/, and alerts on failure.
|
||||
# logs output to $CONTRACT_RUN_LOG_DIR (default: /var/log/contract-runs/),
|
||||
# and alerts on failure.
|
||||
#
|
||||
# Environment:
|
||||
# CONTRACT_RUN_LOG_DIR Override the log directory (default: /var/log/contract-runs)
|
||||
#
|
||||
# Usage: bash scripts/contract-run.sh <contract-name>
|
||||
#
|
||||
@@ -24,7 +28,7 @@ set -uo pipefail
|
||||
|
||||
CONTRACT_NAME="$1"
|
||||
SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
LOG_DIR="/var/log/contract-runs"
|
||||
LOG_DIR="${CONTRACT_RUN_LOG_DIR:-/var/log/contract-runs}"
|
||||
TIMESTAMP=$(date -u '+%Y%m%d-%H%M%S')
|
||||
LOG_FILE="${LOG_DIR}/${CONTRACT_NAME}-${TIMESTAMP}.log"
|
||||
|
||||
@@ -90,30 +94,38 @@ else
|
||||
# Send alert (Zulip DM to user 9 + stream agent-hub topic alerts-infra)
|
||||
# Using the same alert path as other monitors
|
||||
ALERT_MSG="🔴 Contract $CONTRACT_NAME failed (exit $EXIT_CODE). Log: $LOG_FILE"
|
||||
ALERT_SENT=false
|
||||
|
||||
# Try to send via the existing alert mechanism
|
||||
if command -v curl &> /dev/null; then
|
||||
# Zulip DM to user 9
|
||||
ZULIP_API_URL="http://192.168.68.117/api/v1"
|
||||
ZULIP_API_KEY=$(cat /root/.config/zulip-api-key 2>/dev/null || echo "")
|
||||
|
||||
if [ -n "$ZULIP_API_KEY" ]; then
|
||||
curl -s -X POST "${ZULIP_API_URL}/messages" \
|
||||
-u "user:${ZULIP_API_KEY}" \
|
||||
-d "type=private" \
|
||||
-d "to=9" \
|
||||
-d "content=${ALERT_MSG}" > /dev/null 2>&1
|
||||
fi
|
||||
# Take credentials from environment (ZULIP_API_KEY required)
|
||||
ZULIP_API_URL="${ZULIP_API_URL:-https://chat.sysloggh.net/api/v1}"
|
||||
ZULIP_API_KEY="${ZULIP_API_KEY:-}"
|
||||
ZULIP_USER="${ZULIP_USER:-abiba-bot@chat.sysloggh.net}"
|
||||
|
||||
if [ -n "$ZULIP_API_KEY" ] && command -v curl &> /dev/null; then
|
||||
# DM to user 9
|
||||
DM_EXIT=0
|
||||
curl -s -X POST "${ZULIP_API_URL}/messages" \
|
||||
-u "${ZULIP_USER}:${ZULIP_API_KEY}" \
|
||||
-d "type=private" \
|
||||
-d "to=9" \
|
||||
-d "content=${ALERT_MSG}" > /dev/null 2>&1 || DM_EXIT=$?
|
||||
|
||||
# Stream agent-hub topic alerts-infra
|
||||
if [ -n "$ZULIP_API_KEY" ]; then
|
||||
curl -s -X POST "${ZULIP_API_URL}/messages" \
|
||||
-u "user:${ZULIP_API_KEY}" \
|
||||
-d "type=stream" \
|
||||
-d "to=agent-hub" \
|
||||
-d "topic=alerts-infra" \
|
||||
-d "content=${ALERT_MSG}" > /dev/null 2>&1
|
||||
STREAM_EXIT=0
|
||||
curl -s -X POST "${ZULIP_API_URL}/messages" \
|
||||
-u "${ZULIP_USER}:${ZULIP_API_KEY}" \
|
||||
-d "type=stream" \
|
||||
-d "to=agent-hub" \
|
||||
-d "topic=alerts-infra" \
|
||||
-d "content=${ALERT_MSG}" > /dev/null 2>&1 || STREAM_EXIT=$?
|
||||
|
||||
if [ $DM_EXIT -eq 0 ] || [ $STREAM_EXIT -eq 0 ]; then
|
||||
ALERT_SENT=true
|
||||
else
|
||||
echo "$(date -u '+%Y-%m-%dT%H:%M:%SZ') ALERT FAILURE: DM exit=$DM_EXIT, stream exit=$STREAM_EXIT" >> "$LOG_FILE"
|
||||
fi
|
||||
else
|
||||
echo "$(date -u '+%Y-%m-%dT%H:%M:%SZ') ALERT SKIPPED: no ZULIP_API_KEY or curl" >> "$LOG_FILE"
|
||||
fi
|
||||
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user