← 返回
未分类

Cmdnotify

Lightweight command monitoring tool that periodically executes local commands/scripts in batches, detects output changes, and triggers alerts. Built with Go...
轻量级命令监控工具,定期批量执行本地命令/脚本,检测输出变化并触发告警。使用 Go 开发。
mengyun8 mengyun8 来源
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 289
下载
💾 0
安装
1
版本
#latest

概述

CmdNotify - Command Monitor Skill

触发词

当用户提到以下关键词时激活此技能:

  • "监控命令"
  • "命令告警"
  • "定时执行脚本"
  • "输出变化检测"
  • "cmdnotify"
  • "command monitor"
  • "batch script execution"

使用场景

  • 批量监控多个系统命令的输出变化
  • 定时执行脚本并检测异常
  • 磁盘使用率、内存、进程数等系统指标监控
  • API 健康检查与状态变化告警
  • 配置文件漂移检测
  • 日志模式监控

Overview

CmdNotify is a lightweight, resource-optimized command monitoring system written in Go. It allows you to:

  • Batch monitor multiple commands/scripts simultaneously
  • Set custom execution intervals for each command
  • Automatically detect output changes (stdout/stderr + exit code)
  • Trigger alerts when changes are detected
  • Run with minimal CPU/memory footprint using goroutine pools and timeouts

Quick Start

1. Configuration

Create a config.json file:

{
  "commands": [
    {
      "name": "disk_usage",
      "command": "df -h /",
      "interval": "30s",
      "timeout": "10s",
      "notify_on": ["change"],
      "max_history": 2
    },
    {
      "name": "memory_check",
      "command": "vm_stat | grep 'Pages free'",
      "interval": "20s",
      "timeout": "5s",
      "notify_on": ["change"],
      "notify_cmd": "echo '[ALERT] $CMD_NAME: $CMD_MESSAGE'",
      "max_history": 2
    }
  ]
}

2. Build & Run

# Build
go build -o cmdnotify .

# Run with default config
./cmdnotify

# Run with custom config
./cmdnotify -config /path/to/config.json

Configuration Options

FieldTypeDefaultDescription
-----------------------------------
namestringrequiredUnique identifier for the command
commandstringrequiredShell command to execute
intervalduration1sExecution interval (e.g., 30s, 5m, 1h)
timeoutduration30sMaximum execution time per run
notify_on[]string[]Events to notify on: ["change"], ["error"], ["all"]
notify_cmdstring""Custom notification command (optional)
max_historyint2Number of results to keep for change detection
working_dirstring""Working directory for command execution

Notification

Default Behavior

When no notify_cmd is specified, alerts are printed to stderr:

[disk_usage] Command 'disk_usage' output changed
Exit code: 0
Output:
Filesystem      Size   Used  Avail Capacity
/dev/disk1s1   228Gi  180Gi   48Gi    79%

Custom Notification

Set notify_cmd to integrate with external systems:

{
  "notify_cmd": "curl -X POST -d '{\"text\":\"$CMD_MESSAGE\"}' https://hooks.slack.com/services/..."
}

Environment variables available in notify_cmd:

  • CMD_NAME - Command name
  • CMD_MESSAGE - Alert message

Resource Optimization

CmdNotify is designed for minimal resource consumption:

FeatureImplementation
------------------------
Goroutine PoolSemaphore-based concurrency limiting (default: CPU count, min 4)
Timeout ControlPer-command context.WithTimeout prevents zombie processes
Memory Reusebytes.Buffer for output; history limited to max_history
Efficient HashingSHA-256 of output + exit code for fast change detection
Graceful Shutdowncontext.Cancel + sync.WaitGroup ensures clean exit

Project Structure

CmdNotify/
├── config.go      # Configuration loading & validation
├── config.json    # Example configuration
├── executor.go    # Command execution & change detection
├── scheduler.go   # Scheduling engine with goroutine pool
├── main.go        # Entry point
└── go.mod         # Go module definition

Use Cases

  • Monitor disk usage changes
  • Track process counts
  • Watch log file patterns
  • Check service health endpoints
  • Detect configuration drift
  • Monitor system resource usage

Advanced Example

{
  "commands": [
    {
      "name": "api_health",
      "command": "curl -s -o /dev/null -w '%{http_code}' http://localhost:8080/health",
      "interval": "10s",
      "timeout": "5s",
      "notify_on": ["change", "error"],
      "notify_cmd": "echo '[$(date)] $CMD_NAME status changed: $CMD_MESSAGE' >> /var/log/alerts.log",
      "max_history": 3
    },
    {
      "name": "db_connection_count",
      "command": "psql -c 'SELECT count(*) FROM pg_stat_activity;' -t",
      "interval": "1m",
      "timeout": "10s",
      "notify_on": ["all"],
      "working_dir": "/opt/monitoring"
    }
  ]
}

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-11 04:57 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

it-ops-security

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装后可防止您和您的用户受到提示注入、数据泄露及恶意行为的侵害。
★ 116 📥 31,041
it-ops-security

Free Ride - Unlimited free AI

shaivpidadi
管理OpenClaw的OpenRouter免费AI模型,自动按质量排名模型,配置速率限制备用方案,并更新opencla...
★ 472 📥 78,745
it-ops-security

OpenClaw Backup

alex3alex
备份与恢复 OpenClaw 数据。适用于创建备份、设置自动备份计划、从备份恢复或管理备份轮转。处理 ~/.openclaw 目录归档并包含适当的排除规则。
★ 90 📥 31,175