tangled
alpha
login
or
join now
julien.rbrt.fr
/
servmon
0
fork
atom
kiss server monitoring tool with email alerts
go
monitoring
0
fork
atom
overview
issues
pulls
pipelines
feat: send email on start
julien.rbrt.fr
2 months ago
0d9739b3
4d7e680c
0/1
ci.yml
failed
5s
+40
2 changed files
expand all
collapse all
unified
split
.gitignore
main.go
+1
.gitignore
···
5
*.so
6
*.dylib
7
servmon-bin
0
8
9
# Test binary, built with `go test -c`
10
*.test
···
5
*.so
6
*.dylib
7
servmon-bin
8
+
servmon
9
10
# Test binary, built with `go test -c`
11
*.test
+39
main.go
···
12
"runtime/debug"
13
"strings"
14
"syscall"
0
15
16
"github.com/spf13/cobra"
17
)
···
101
cmd.Println("Servmon started successfully. Monitoring active.")
102
cmd.Println("Press Ctrl+C to stop.")
103
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
104
// Wait for shutdown signal
105
sig := <-sigChan
106
cmd.Printf("\nReceived signal %v, shutting down gracefully...\n", sig)
···
159
160
return strings.TrimSpace(version.Main.Version), nil
161
}
0
0
0
0
0
0
0
0
0
···
12
"runtime/debug"
13
"strings"
14
"syscall"
15
+
"time"
16
17
"github.com/spf13/cobra"
18
)
···
102
cmd.Println("Servmon started successfully. Monitoring active.")
103
cmd.Println("Press Ctrl+C to stop.")
104
105
+
// Send email notification that monitoring is now active
106
+
go func() {
107
+
hostname, err := os.Hostname()
108
+
if err != nil {
109
+
hostname = "unknown"
110
+
}
111
+
112
+
subject := fmt.Sprintf("Monitoring Active on %s", hostname)
113
+
body := fmt.Sprintf("ServMon has started successfully and is now actively monitoring:\n\n"+
114
+
"- CPU threshold: %.1f%%\n"+
115
+
"- Memory threshold: %.1f%%\n"+
116
+
"- Disk paths: %s\n",
117
+
cfg.AlertThresholds.CPU.Threshold,
118
+
cfg.AlertThresholds.Memory.Threshold,
119
+
getDiskPaths(cfg))
120
+
121
+
if cfg.AlertThresholds.HTTP.URL != "" {
122
+
body += fmt.Sprintf("- HTTP endpoint: %s\n", cfg.AlertThresholds.HTTP.URL)
123
+
}
124
+
125
+
body += fmt.Sprintf("\nMonitoring started at: %s", time.Now().Format(time.RFC1123))
126
+
127
+
if err := sendEmail(subject, body, cfg); err != nil {
128
+
cmd.Printf("Warning: Failed to send monitoring active notification: %v\n", err)
129
+
} else {
130
+
cmd.Println("Monitoring active notification sent successfully.")
131
+
}
132
+
}()
133
+
134
// Wait for shutdown signal
135
sig := <-sigChan
136
cmd.Printf("\nReceived signal %v, shutting down gracefully...\n", sig)
···
189
190
return strings.TrimSpace(version.Main.Version), nil
191
}
192
+
193
+
// getDiskPaths returns a comma-separated list of monitored disk paths
194
+
func getDiskPaths(cfg *Config) string {
195
+
var paths []string
196
+
for _, disk := range cfg.AlertThresholds.Disks {
197
+
paths = append(paths, disk.Path)
198
+
}
199
+
return strings.Join(paths, ", ")
200
+
}