Skip to content

About

AI-powered self-healing server monitoring & auto-remediation system built with Bash + Groq API on AWS EC2

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

29 Commits

Folders and files

Repository files navigation

πŸ›‘οΈ SentinelSH-AI

Self-Healing Server Monitoring & Auto-Remediation, Powered by Bash + AI

Bash AWS Docker Groq License: MIT

Most monitoring tools tell you something broke. SentinelSH-AI tells you why it broke, fixes it automatically when it's safe to do so, and writes you a postmortem about it β€” all in pure Bash, with an AI co-pilot, running for free on AWS or your own laptop.


πŸ“– Table of Contents


🎯 Why This Project Exists

Every bash scripting tutorial ends the same way: a todo app, a backup script, a log parser. This project asks a different question β€”

What if a bash script could think like a junior SRE: notice something's wrong, reason about why, decide whether it's safe to fix, fix it, and then write up what happened?

SentinelSH-AI is that answer. It's a lightweight, dependency-free, fully autonomous monitoring daemon that combines classic shell scripting fundamentals with a real LLM (via the free Groq API) to bring genuine reasoning into the ops loop β€” not just if cpu > 80 then alert.


✨ What Makes It Different

Feature Typical Monitoring Script SentinelSH-AI
Detects issues βœ… βœ…
Auto-remediates ⚠️ Sometimes, blindly βœ… With AI safety review first
Explains why it happened ❌ βœ… AI root-cause diagnosis
Generates incident postmortems ❌ βœ… Auto-written Markdown reports
Learns "normal" for your server ❌ βœ… Baseline learning + anomaly detection
Natural language log queries ❌ βœ… ask.sh "why was the server slow yesterday?"
Weekly AI-written health summary ❌ βœ…
Extensible without touching core code ❌ βœ… Drop-in plugin architecture
Real-time alerts Maybe βœ… Discord webhook
Live dashboard ❌ βœ… Auto-refreshing HTML dashboard

🧠 The standout idea: AI as a safety guardrail, not a blind trigger

Before executing any destructive remediation (clearing logs, restarting services), SentinelSH-AI asks the AI: "is this actually safe given the current context?" If the AI has concerns, it halts and flags for manual review instead of charging ahead. This mirrors how a cautious human engineer would actually operate β€” automation with judgment, not automation with a hair-trigger.


πŸ—οΈ Architecture

                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚   systemd.timer      β”‚  (runs every 2 min)
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     β”‚     sentinel.sh        β”‚  (main orchestrator)
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β–Ό                   β–Ό                   β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  checks/*.sh     β”‚ β”‚  lib/baseline.sh   β”‚ β”‚  lib/dashboard.sh  β”‚
   β”‚  (plugin system)  β”‚ β”‚  (anomaly detect)  β”‚ β”‚  (status.html)     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚ on FAILURE
            β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  ai/diagnose.sh       │──────▢│   Groq API (LLaMA 3.3) β”‚
   β”‚  (root cause analysis) β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  ai/safety_check.sh   │──────▢│   Groq API (verdict)   β”‚
   β”‚  (SAFE / UNSAFE gate)  β”‚      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚ if SAFE
            β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ remediate/*.sh        β”‚    β”‚ lib/report.sh         β”‚    β”‚ lib/notify.sh          β”‚
   β”‚ (auto-fix plugin)     β”‚    β”‚ (Markdown postmortem) β”‚    β”‚ (Discord webhook)     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‚ Project Structure

sentinelsh-ai/
β”œβ”€β”€ sentinel.sh              # Main orchestrator β€” auto-discovers and runs everything
β”œβ”€β”€ install.sh                # One-command installer for fresh machines
β”œβ”€β”€ config.conf.example        # Copy to config.conf and fill in your keys
β”œβ”€β”€ Dockerfile                  # Run the whole thing in a container
β”œβ”€β”€ docker-compose.yml          # One-command Docker deployment
β”‚
β”œβ”€β”€ checks/                    # πŸ”Œ Plugin system β€” drop a new .sh here, it's auto-discovered
β”‚   β”œβ”€β”€ cpu_check.sh
β”‚   β”œβ”€β”€ disk_check.sh
β”‚   β”œβ”€β”€ memory_check.sh
β”‚   β”œβ”€β”€ load_avg_check.sh
β”‚   └── service_check.sh
β”‚
β”œβ”€β”€ remediate/                  # πŸ”§ Auto-fix scripts, matched to checks by resource name
β”‚   β”œβ”€β”€ clear_logs.sh
β”‚   └── restart_service.sh
β”‚
β”œβ”€β”€ ai/                          # 🧠 Groq-powered intelligence layer
β”‚   β”œβ”€β”€ ai_client.sh             # Core Groq API wrapper
β”‚   β”œβ”€β”€ diagnose.sh               # Root cause analysis on incidents
β”‚   β”œβ”€β”€ safety_check.sh            # SAFE/UNSAFE guardrail before remediation
β”‚   β”œβ”€β”€ ask.sh                      # Natural language log queries
β”‚   └── weekly_report.sh             # AI-written weekly health summary
β”‚
β”œβ”€β”€ lib/                         # Shared utilities
β”‚   β”œβ”€β”€ logger.sh
β”‚   β”œβ”€β”€ report.sh                 # Markdown incident report generator
β”‚   β”œβ”€β”€ baseline.sh                # Metric history + anomaly detection
β”‚   β”œβ”€β”€ notify.sh                  # Discord webhook integration
β”‚   └── dashboard.sh               # Live HTML dashboard generator
β”‚
β”œβ”€β”€ deploy/                      # systemd + logrotate configs for production
β”‚   β”œβ”€β”€ sentinelsh.service
β”‚   β”œβ”€β”€ sentinelsh.timer
β”‚   └── sentinelsh.logrotate
β”‚
β”œβ”€β”€ reports/                     # Auto-generated incident & weekly reports (gitignored)
└── logs/                        # Runtime logs (gitignored)

πŸ“Έ Screenshots & Proof of Work

All features below were tested end-to-end on a live AWS EC2 instance. See Quick Start to reproduce these yourself.

βœ… Clean Healthy Run All plugins auto-discovered and passing, dashboard auto-regenerated.

πŸ“Š Live Auto-Refreshing Dashboard Health banner, color-coded metrics, progress bars β€” updates every 30s.

🚨 Full Incident Pipeline Detection β†’ AI diagnosis β†’ incident report β†’ Discord alert, fully automated.

πŸ’¬ Real-Time Discord Alert AI's actual root-cause explanation delivered straight to chat.

πŸ“ Auto-Generated Incident Report A real Markdown postmortem β€” timestamp, root cause, action taken, system snapshot.

πŸ—£οΈ Natural Language Log Queries ask.sh "what happened to my server this week?" β€” conversational ops assistant.

πŸ“… AI-Written Weekly Report Reads like a real SRE wrote it β€” summary, incidents, recommendations.

πŸ›‘ AI Safety Guardrail in Action AI reviewing a proposed remediation before allowing it to execute.

πŸ”Œ Plugin Architecture Proof Five independent check plugins, auto-discovered with zero hardcoding.

⏱️ Fully Autonomous via systemd Timer fires every 2 minutes without any manual trigger.

🩹 The Self-Healing Moment β€” Service Crash β†’ Auto-Restart β†’ Verified cron service killed manually β†’ detected by service_check β†’ AI diagnosed it β†’ restart_service.sh auto-fired β†’ confirmed back online, all without human intervention.

πŸ’‘ Note for repo setup: create a /screenshots folder in your repo root and drop your PNG files there using the filenames referenced above, or update the paths to match your own filenames.


πŸš€ Quick Start

You have three ways to run SentinelSH-AI. Pick whichever fits you.

Option A β€” Docker (Recommended, runs anywhere)

The fastest way to see it working, no AWS account or systemd needed. Works on Windows/Mac/Linux as long as Docker is installed.

# 1. Clone the repo
git clone https://github.com/Adarsh73111/sentinelsh-ai.git
cd sentinelsh-ai

# 2. Set your environment variables
export GROQ_API_KEY="your_groq_api_key_here"
export WEBHOOK_URL="your_discord_webhook_url_here"   # optional

# 3. Build and run
docker compose up --build

Then open your browser to:

http://localhost:8080/status.html

To stop:

docker compose down

Get a free Groq API key at console.groq.com/keys β€” no credit card required.


Option B β€” Local Machine / WSL / Linux

Run it directly on any Linux machine (or WSL on Windows) without Docker.

# 1. Clone the repo
git clone https://github.com/Adarsh73111/sentinelsh-ai.git
cd sentinelsh-ai

# 2. Run the installer (installs jq, curl, sets up folders & permissions)
chmod +x install.sh
./install.sh

# 3. Configure your keys
cp config.conf.example config.conf
nano config.conf   # add your GROQ_API_KEY and WEBHOOK_URL

# 4. Run it manually
bash sentinel.sh

# 5. (Optional) View the dashboard
python3 -m http.server 8080
# visit http://localhost:8080/status.html

install.sh will also offer to set up a systemd timer for automatic recurring runs β€” skip this step if you're just testing on a personal laptop.


Option C β€” AWS EC2 Free Tier (Full Production Setup)

For the complete experience with autonomous systemd scheduling, a public dashboard URL, and Discord alerting from a real server.

Click to expand full AWS setup guide

1. Launch an EC2 instance

  • AMI: Ubuntu Server 24.04 LTS, Free Tier eligible

  • Instance type: t2.micro

  • Storage: 30 GB gp2

  • Security Group inbound rules:

    Type Port Source
    SSH 22 My IP
    Custom TCP 8080 Anywhere

2. (Recommended) Allocate an Elastic IP

So your dashboard URL never changes after stop/start: EC2 β†’ Elastic IPs β†’ Allocate β†’ Associate with your instance.

3. SSH in and set up the project

ssh -i "your-key.pem" ubuntu@<your-ec2-ip>

git clone https://github.com/Adarsh73111/sentinelsh-ai.git ~/sentinelsh
cd ~/sentinelsh
chmod +x install.sh
./install.sh

4. Configure

cp config.conf.example config.conf
nano config.conf

Add your GROQ_API_KEY and WEBHOOK_URL.

5. Verify the systemd timer is running

sudo systemctl status sentinelsh.timer

6. Serve the dashboard

cd ~/sentinelsh
nohup python3 -m http.server 8080 > /dev/null 2>&1 &

Visit http://<your-ec2-ip>:8080/status.html


βš™οΈ Configuration

All settings live in config.conf (copy from config.conf.example):

Variable Description Default
GROQ_API_KEY Your free Groq API key (required)
AI_MODEL Groq model to use llama-3.3-70b-versatile
DISK_THRESHOLD Disk usage % that triggers an alert 80
CPU_THRESHOLD CPU usage % that triggers an alert 75
MEMORY_THRESHOLD Memory usage % that triggers an alert 80
MONITORED_SERVICES Space-separated systemd service names to watch ssh cron
WEBHOOK_URL Discord (or Slack-compatible) webhook for alerts (optional)
AI_SAFETY_CHECK Require AI approval before destructive remediation yes

πŸ›‘οΈ How the AI Safety Guardrail Works

Before any destructive remediation action executes (e.g. clearing logs, deleting temp files), SentinelSH-AI sends the proposed action and its context to the AI and requires an explicit verdict:

Proposed action: Clear compressed logs, journal logs older than 2 days, apt cache, and /tmp
Context: Disk usage exceeded threshold

β†’ AI Verdict: SAFE
   "These are routine, reversible cleanup actions unlikely to cause disruption."

If the AI responds UNSAFE β€” for example, flagging that a file might be in active use β€” the remediation halts and the incident is logged for manual review instead of executing blindly. This is the difference between automation and automation with judgment.


πŸ”Œ Extending SentinelSH-AI (Plugin System)

Adding a new health check requires zero changes to sentinel.sh. Drop a script into checks/ that follows this contract:

#!/bin/bash
source ~/sentinelsh/config.conf
source ~/sentinelsh/lib/logger.sh

check_something() {
    # your check logic here
    if [ "$condition_failed" ]; then
        echo "FAIL:resource_name:value"
        return 1
    else
        echo "OK"
        return 0
    fi
}

check_something

To add an auto-fix for it, create remediate/<resource_name>_fix.sh (or a service-style fix that accepts the resource as $1) β€” sentinel.sh will auto-discover and wire it in.


🧰 Tech Stack

  • Bash β€” 100% of the orchestration logic, no Python/Node dependency for core functionality
  • Groq API (LLaMA 3.3 70B) β€” free-tier LLM inference for diagnosis, safety checks, and reports
  • AWS EC2 β€” Free Tier deployment target
  • systemd β€” timers and services for autonomous scheduling
  • Discord Webhooks β€” real-time alerting
  • Docker β€” portable, zero-dependency deployment option
  • jq β€” JSON parsing for API responses
  • HTML/CSS β€” self-contained live dashboard, no frontend framework

πŸ—ΊοΈ Roadmap / Stretch Goals

  • AWS CLI integration β€” auto-snapshot EBS volume on critical disk alerts
  • Multi-server support with aggregated dashboard
  • Slack slash-command interface for ask.sh
  • Historical trend analysis with monthly AI reports
  • Configurable severity thresholds via a whiptail/dialog TUI menu

🀝 Contributing

This started as a personal learning project to push bash scripting beyond tutorial-level exercises. Issues, forks, and pull requests are welcome β€” especially new checks/ or remediate/ plugins.


πŸ“„ License

This project is licensed under the MIT License.


Built with 🐚 Bash, 🧠 Groq AI, and ☁️ AWS Free Tier β€” proof that infrastructure automation doesn't need a heavyweight framework to be genuinely intelligent.

About

AI-powered self-healing server monitoring & auto-remediation system built with Bash + Groq API on AWS EC2

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages