SyScope | Efficient Automation Script for System Monitoring

SyScope | Efficient Automation Script for System Monitoring

Written By @H4XSEC
Written By @H4XSEC

Note 📝

SyScope is an open-source script designed to adapt to your needs, whether it’s for monitoring anomalies in security systems, supporting DevOps workflows, or exploring other creative implementations. You are free to use and develop it for any purpose.

Namun, jangan lupa untuk memberikan Credit @H4XSEC sebagai bentuk penghargaan atas usaha dan dedikasi di balik script ini. Together, we can make this tool even better for everyone!

Ready to explore? Download the complete script here:
https://package.h4xsec.org

Step 1: Get Your Setup Ready 🖥️

First thing first, make sure Python is installed. Kalau belum, kamu bisa download langsung dari Python Official Site.
Install juga dependencies yang diperlukan, and you’re good to go!

pip3 install psutil matplotlib

Step 2: Customize Your Config

2.1 SMTP Settings 📧

We’re using SMTP buat kirim email notifikasi. Edit bagian ini sesuai kebutuhan kamu:

SMTP_SERVER = "smtp.loremipsum.com"
SMTP_PORT = 465
SMTP_USER = "[email protected]"
SMTP_PASS = "your_password"
TO_EMAIL = "[email protected]"
FROM_EMAIL = "[email protected]"

2.2 Thresholds

Atur ambang batas buat monitoring system:

MEMORY_THRESHOLD = 80
CPU_THRESHOLD = 80
DISK_THRESHOLD = 80
LOAD_THRESHOLD = 2.0

Step 3: Main Features 🎯

3.1 Get System Info

With this function, kita bisa dapetin hostname dan IP address dari server:

def get_system_info():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
return hostname, ip_address

3.2 Monitoring in Action

Skrip ini akan cek CPU, memory, disk, dan load average. Kalau ada yang melebihi batas, langsung dicatat di log dan dikirim via email.

  • check_memory_usage(): Memeriksa penggunaan memori.
  • check_cpu_usage(): Memeriksa penggunaan CPU.
  • check_disk_usage(): Memeriksa penggunaan disk.
  • check_load_average(): Memeriksa load average sistem.

3.3 Send Email

Here’s how email reporting works, lengkap dengan attachment grafik kalau perlu:

def send_email(subject, body, image_data=None):
msg = MIMEMultipart()
msg['From'] = FROM_EMAIL
msg['To'] = TO_EMAIL
msg['Subject'] = f"{SUBJECT_PREFIX}: {subject}"

    html_body = f"""
    <html>
    <body>
        <h2>{subject}</h2>
        <p>{body}</p>
        <img src="cid:trend_graph" alt="System Trends" />
    </body>
    </html>
    """
    msg.attach(MIMEText(html_body, 'html'))

    if image_data:
        image_part = MIMEImage(image_data.getvalue(), name="system_trends.png")
        image_part.add_header('Content-ID', '<trend_graph>')
        msg.attach(image_part)

    with smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT) as server:
        server.login(SMTP_USER, SMTP_PASS)
        server.sendmail(FROM_EMAIL, TO_EMAIL, msg.as_string())

3.4 Trend Graph Generator

Fungsi ini bikin grafik tren resource usage pakai matplotlib:

def generate_trend_graph():
plt.figure(figsize=(10, 6))

    # Plot untuk CPU Usage
    plt.subplot(2, 2, 1)
    plt.plot(historical_cpu, label="CPU Usage (%)", color='red')
    plt.axhline(y=CPU_THRESHOLD, color='r', linestyle='--', label="CPU Threshold")
    plt.title("CPU Usage Trend")

    # Plot untuk Memory Usage
    plt.subplot(2, 2, 2)
    plt.plot(historical_memory, label="Memory Usage (%)", color='blue')
    plt.axhline(y=MEMORY_THRESHOLD, color='b', linestyle='--', label="Memory Threshold")
    plt.title("Memory Usage Trend")

    # Plot untuk Disk Usage
    plt.subplot(2, 2, 3)
    plt.plot(historical_disk, label="Disk Usage (%)", color='green')
    plt.axhline(y=DISK_THRESHOLD, color='g', linestyle='--', label="Disk Threshold")
    plt.title("Disk Usage Trend")

    # Plot untuk Load Average
    plt.subplot(2, 2, 4)
    plt.plot(historical_load, label="Load Average", color='purple')
    plt.axhline(y=LOAD_THRESHOLD, color='purple', linestyle='--', label="Load Threshold")
    plt.title("Load Average Trend")

    plt.tight_layout()

    image_stream = BytesIO()
    plt.savefig(image_stream, format='png')
    image_stream.seek(0)
    plt.close()

    return image_stream

Step 4: Run It Like a Pro 🚀

Untuk menjalankan skrip ini di background, you can simply use the following command:

nohup python3 namafile.py &

Step 5: Check the Process 🔍

Ensure everything runs smoothly and seamlessly:

ps aux | grep namafile.py

Step 6: Automated Email Alerts

Skrip ini akan otomatis kirim email yang berisi:

  • Status real-time CPU, memory, disk, dan load average.
  • Grafik tren untuk visualisasi.

Conclusion 🎉

Now that you’ve seen how it works, kamu bisa effortlessly monitor your system’s performance simple, efficient, and accurate! Let’s take your monitoring experience to the next level! 🚀