feat: block/monitoring mode — ask during deploy, configurable in .env

This commit is contained in:
admin 2026-08-02 09:12:27 +00:00
parent e5e1697402
commit 3d076221e2
2 changed files with 23 additions and 6 deletions

View file

@ -98,6 +98,7 @@ type nodeConfig struct {
UpstreamIP string UpstreamIP string
UpstreamPort string UpstreamPort string
Labels string Labels string
BlockMode bool
} }
func loadNodes() []nodeConfig { func loadNodes() []nodeConfig {
@ -122,6 +123,7 @@ func loadNodes() []nodeConfig {
UpstreamIP: env["WALLARM_UPSTREAM_IP_"+n], UpstreamIP: env["WALLARM_UPSTREAM_IP_"+n],
UpstreamPort: env["WALLARM_UPSTREAM_PORT_"+n], UpstreamPort: env["WALLARM_UPSTREAM_PORT_"+n],
Labels: env["WALLARM_LABELS_"+n], Labels: env["WALLARM_LABELS_"+n],
BlockMode: env["WALLARM_BLOCK_"+n] == "true",
}) })
} }
if len(nodes) == 0 { if len(nodes) == 0 {
@ -135,6 +137,7 @@ func loadNodes() []nodeConfig {
UpstreamIP: env["WALLARM_UPSTREAM_IP"], UpstreamIP: env["WALLARM_UPSTREAM_IP"],
UpstreamPort: env["WALLARM_UPSTREAM_PORT"], UpstreamPort: env["WALLARM_UPSTREAM_PORT"],
Labels: env["WALLARM_LABELS"], Labels: env["WALLARM_LABELS"],
BlockMode: env["WALLARM_BLOCK"] == "true",
}) })
} }
} }
@ -215,6 +218,20 @@ func deployOne(nc nodeConfig) {
if nc.Cloud == "" { nc.Cloud = "EU" } if nc.Cloud == "" { nc.Cloud = "EU" }
if nc.Labels == "" { nc.Labels = "group=" + nc.Name } if nc.Labels == "" { nc.Labels = "group=" + nc.Name }
// Ask for block mode
reader := bufio.NewReader(os.Stdin)
mode := "monitoring"
if nc.BlockMode {
fmt.Print("Block mode? [Y/n]: ")
} else {
fmt.Print("Block mode? [y/N]: ")
}
ans, _ := reader.ReadString('\n')
ans = strings.TrimSpace(strings.ToLower(ans))
if ans == "y" || ans == "yes" || (nc.BlockMode && ans == "") {
mode = "block"
}
apiHost := "api.wallarm.com" apiHost := "api.wallarm.com"
if nc.Cloud == "US" { apiHost = "us1.api.wallarm.com" } if nc.Cloud == "US" { apiHost = "us1.api.wallarm.com" }
@ -236,7 +253,7 @@ func deployOne(nc nodeConfig) {
state.Save(s) state.Save(s)
fmt.Println("Starting deployment...") fmt.Println("Starting deployment...")
if err := native.InstallNode(node, nc.Token, apiHost, nc.Labels); err != nil { if err := native.InstallNode(node, nc.Token, apiHost, nc.Labels, mode); err != nil {
fmt.Fprintf(os.Stderr, "Deployment failed: %v\n", err) fmt.Fprintf(os.Stderr, "Deployment failed: %v\n", err)
return return
} }

View file

@ -23,7 +23,7 @@ func installerURL() string {
return "https://storage.googleapis.com/meganode_storage/6.12/wallarm-6.12.5.x86_64-glibc.sh" return "https://storage.googleapis.com/meganode_storage/6.12/wallarm-6.12.5.x86_64-glibc.sh"
} }
func InstallNode(node state.Node, apiToken, apiHost, labels string) error { func InstallNode(node state.Node, apiToken, apiHost, labels, mode string) error {
if apiToken == "" { if apiToken == "" {
return fmt.Errorf("API token required") return fmt.Errorf("API token required")
} }
@ -62,7 +62,7 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
} }
// 5. Start NGINX (modules now available after extraction) // 5. Start NGINX (modules now available after extraction)
startNginx(DeployTo, node, port) startNginx(DeployTo, node, port, mode)
// 6. Load Wallarm NGINX module + register node // 6. Load Wallarm NGINX module + register node
fmt.Printf("[%s] Configuring NGINX module...\n", node.Name) fmt.Printf("[%s] Configuring NGINX module...\n", node.Name)
@ -192,7 +192,7 @@ func Status(name string) (string, error) {
return string(out), nil return string(out), nil
} }
func startNginx(dir string, node state.Node, port string) { func startNginx(dir string, node state.Node, port, mode string) {
nginxDir := filepath.Join(dir, "nginx") nginxDir := filepath.Join(dir, "nginx")
confDir := filepath.Join(nginxDir, "conf") confDir := filepath.Join(nginxDir, "conf")
os.MkdirAll(confDir, 0755) os.MkdirAll(confDir, 0755)
@ -210,7 +210,7 @@ error_log %s/error.log;
events { worker_connections 10240; } events { worker_connections 10240; }
http { http {
access_log %s/access.log; access_log %s/access.log;
wallarm_mode monitoring; wallarm_mode %s;
server { server {
listen %s; listen %s;
@ -229,7 +229,7 @@ http {
} }
} }
} }
`, dir, nginxDir, nginxDir, nginxDir, port, upstream)), 0644) `, dir, nginxDir, nginxDir, nginxDir, mode, port, upstream)), 0644)
bin := filepath.Join(nginxDir, "sbin", "nginx") bin := filepath.Join(nginxDir, "sbin", "nginx")
cmd := exec.Command(bin, "-c", confPath, "-p", nginxDir) cmd := exec.Command(bin, "-c", confPath, "-p", nginxDir)