working mode
This commit is contained in:
81
main.go
81
main.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -19,7 +20,48 @@ import (
|
||||
"nannyagentv2/internal/websocket"
|
||||
)
|
||||
|
||||
const Version = "v2.0.0"
|
||||
const Version = "0.0.1"
|
||||
|
||||
// showVersion displays the version information
|
||||
func showVersion() {
|
||||
fmt.Printf("nannyagent version %s\n", Version)
|
||||
fmt.Println("Linux diagnostic agent with eBPF capabilities")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// showHelp displays the help information
|
||||
func showHelp() {
|
||||
fmt.Println("NannyAgent - Linux Diagnostic Agent with eBPF Monitoring")
|
||||
fmt.Printf("Version: %s\n\n", Version)
|
||||
fmt.Println("USAGE:")
|
||||
fmt.Printf(" sudo %s [OPTIONS]\n\n", os.Args[0])
|
||||
fmt.Println("OPTIONS:")
|
||||
fmt.Println(" --version, -v Show version information")
|
||||
fmt.Println(" --help, -h Show this help message")
|
||||
fmt.Println()
|
||||
fmt.Println("DESCRIPTION:")
|
||||
fmt.Println(" NannyAgent is an AI-powered Linux diagnostic tool that uses eBPF")
|
||||
fmt.Println(" for deep system monitoring and analysis. It requires root privileges")
|
||||
fmt.Println(" to run for eBPF functionality.")
|
||||
fmt.Println()
|
||||
fmt.Println("REQUIREMENTS:")
|
||||
fmt.Println(" - Linux kernel 5.x or higher")
|
||||
fmt.Println(" - Root privileges (sudo)")
|
||||
fmt.Println(" - bpftrace and bpfcc-tools installed")
|
||||
fmt.Println(" - Network connectivity to Supabase")
|
||||
fmt.Println()
|
||||
fmt.Println("CONFIGURATION:")
|
||||
fmt.Println(" Configuration file: /etc/nannyagent/config.env")
|
||||
fmt.Println(" Data directory: /var/lib/nannyagent")
|
||||
fmt.Println()
|
||||
fmt.Println("EXAMPLES:")
|
||||
fmt.Printf(" # Run the agent\n")
|
||||
fmt.Printf(" sudo %s\n\n", os.Args[0])
|
||||
fmt.Printf(" # Show version (no sudo required)\n")
|
||||
fmt.Printf(" %s --version\n\n", os.Args[0])
|
||||
fmt.Println("For more information, visit: https://github.com/yourusername/nannyagent")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// checkRootPrivileges ensures the program is running as root
|
||||
func checkRootPrivileges() {
|
||||
@@ -31,7 +73,7 @@ func checkRootPrivileges() {
|
||||
}
|
||||
}
|
||||
|
||||
// checkKernelVersionCompatibility ensures kernel version is 4.4 or higher
|
||||
// checkKernelVersionCompatibility ensures kernel version is 5.x or higher
|
||||
func checkKernelVersionCompatibility() {
|
||||
output, err := exec.Command("uname", "-r").Output()
|
||||
if err != nil {
|
||||
@@ -54,18 +96,12 @@ func checkKernelVersionCompatibility() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
minor, err := strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
logging.Error("Cannot parse minor kernel version: %s", parts[1])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Check if kernel is 4.4 or higher
|
||||
if major < 4 || (major == 4 && minor < 4) {
|
||||
logging.Error("Kernel version %s is too old for eBPF", kernelVersion)
|
||||
logging.Error("Required: Linux kernel 4.4 or higher")
|
||||
logging.Error("Current: %s", kernelVersion)
|
||||
logging.Error("Reason: eBPF requires kernel features introduced in 4.4+:\n - BPF system call support\n - eBPF program types (kprobe, tracepoint)\n - BPF maps and helper functions")
|
||||
// Check if kernel is 5.x or higher
|
||||
if major < 5 {
|
||||
logging.Error("Kernel version %s is not supported", kernelVersion)
|
||||
logging.Error("Required: Linux kernel 5.x or higher")
|
||||
logging.Error("Current: %s (major version: %d)", kernelVersion, major)
|
||||
logging.Error("Reason: NannyAgent requires modern kernel features:\n - Advanced eBPF capabilities\n - BTF (BPF Type Format) support\n - Enhanced security and stability")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -126,6 +162,23 @@ func runInteractiveDiagnostics(agent *LinuxDiagnosticAgent) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Define flags with both long and short versions
|
||||
versionFlag := flag.Bool("version", false, "Show version information")
|
||||
versionFlagShort := flag.Bool("v", false, "Show version information (short)")
|
||||
helpFlag := flag.Bool("help", false, "Show help information")
|
||||
helpFlagShort := flag.Bool("h", false, "Show help information (short)")
|
||||
flag.Parse()
|
||||
|
||||
// Handle --version or -v flag (no root required)
|
||||
if *versionFlag || *versionFlagShort {
|
||||
showVersion()
|
||||
}
|
||||
|
||||
// Handle --help or -h flag (no root required)
|
||||
if *helpFlag || *helpFlagShort {
|
||||
showHelp()
|
||||
}
|
||||
|
||||
logging.Info("NannyAgent v%s starting...", Version)
|
||||
|
||||
// Perform system compatibility checks first
|
||||
|
||||
Reference in New Issue
Block a user