lua_hammer_script (1) lua lua lua lua lua
lua_hammer_script (1) lua lua lua lua lua
/usr/bin/env lua
-- Configuration
local config = {
name = "Network Sentinel",
version = "2.1.0",
check_interval = 30,
alert_threshold = {
cpu_usage = 80,
memory_usage = 85,
connection_timeout = 5
},
monitored_hosts = {
"8.8.8.8",
"1.1.1.1",
"google.com",
"github.com"
},
log_file = "sentinel.log"
}
-- State tracking
local system_state = {
alerts = {},
last_check = 0,
uptime_start = os.time(),
check_count = 0,
failed_checks = 0
}
-- Utility functions
local function timestamp()
return os.date("%Y-%m-%d %H:%M:%S")
end
return stats
end
tcp:close()
if result then
return {
host = host,
port = port,
status = "connected",
response_time = response_time,
error = nil
}
else
return {
host = host,
port = port,
status = "failed",
response_time = nil,
error = err or "Connection failed"
}
end
end
-- Alert system
local function trigger_alert(alert_type, message, severity)
local alert = {
type = alert_type,
message = message,
severity = severity or "WARNING",
timestamp = os.time(),
id = #system_state.alerts + 1
}
table.insert(system_state.alerts, alert)
log_message("ALERT", string.format("[%s] %s: %s", alert.severity, alert_type,
message))
-- Performance monitoring
local function monitor_system_performance()
local stats = get_system_stats()
return stats
end
-- Network monitoring
local function monitor_network_connectivity()
local connectivity_results = {}
local failed_connections = 0
return connectivity_results
end
-- Report generation
local function generate_status_report()
local uptime = os.time() - system_state.uptime_start
local success_rate = ((system_state.check_count - system_state.failed_checks) /
system_state.check_count) * 100
local report = {
"=== NETWORK SENTINEL STATUS REPORT ===",
string.format("Generated: %s", timestamp()),
string.format("Uptime: %d seconds", uptime),
string.format("Total checks: %d", system_state.check_count),
string.format("Success rate: %.2f%%", success_rate),
string.format("Active alerts: %d", #system_state.alerts),
"",
"Recent Alerts:"
}
if #recent_alerts == 0 then
table.insert(report, " No recent alerts")
else
for _, alert_line in ipairs(recent_alerts) do
table.insert(report, alert_line)
end
end
system_state.check_count = system_state.check_count + 1
local cycle_start = socket.gettime()
-- Update state
system_state.last_check = os.time()
return {
system_stats = sys_stats,
network_results = net_results,
cycle_time = cycle_time
}
end
local cycle_count = 0
while cycles == -1 or cycle_count < cycles do
local results = monitoring_cycle()
cycle_count = cycle_count + 1