Things that gave the simulator away (#40): - hosts were fleet-0000 to fleet-0119. Now they're named for their site and what they do: phx1-gw01, phx1-lb01, phx1-app05, phx1-db03, phx1-cache02, iad1-lb02, lon1-kvm01 (collectors.go); - fleet-0041 was a Redis cache, a KVM host, the IBM i collector and the HMC reader at once, so IBM i alerts read as if PROD2 ran on it. The agents that read storage, IBM i and virtualization are small hosts of their own now: phx1-stor01 (the Pure arrays), phx1-ibmi01 (the partitions and the HMC), phx1-virt01 (vCenter, Proxmox, Nutanix). fleet config writes their agents; - libvirt runs only on app servers, not on a load balancer or a cache; - RHEL hosts' units are sshd and chronyd, as RHEL names them; - Akamai's CP codes no longer have round counts. Varied disks and jittered readings came with #39 (load.go).
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/cairnobs/cairnobs/internal/mailmon/mailfake"
|
|
)
|
|
|
|
// The demo's mail server (fleet run -mail DIR): a stand-in on loopback for
|
|
// the Mail page's round trip, served by phx1-mq04. Healthy on purpose,
|
|
// with deliveries taking a few seconds and a small outgoing queue, so the
|
|
// page shows what normal looks like.
|
|
const mailPort = 58440 // SMTP; IMAP and JMAP on the next two
|
|
|
|
func serveMail(ctx context.Context, dir string) {
|
|
if err := os.MkdirAll(dir, 0o700); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
const pw = "fleet-demo-mail-password"
|
|
f, err := mailfake.Start("[email protected]", pw,
|
|
fmt.Sprintf("127.0.0.1:%d", mailPort), fmt.Sprintf("127.0.0.1:%d", mailPort+1), fmt.Sprintf("127.0.0.1:%d", mailPort+2))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
go func() { <-ctx.Done(); f.Close() }()
|
|
// Deliveries take 1.5-6 s, and the queue holds a few messages a
|
|
// receiving server asked to try again later.
|
|
go func() {
|
|
t := time.NewTicker(30 * time.Second)
|
|
defer t.Stop()
|
|
for k := 0; ; k++ {
|
|
f.SetDelay(1500*time.Millisecond + time.Duration(k*7919%4500)*time.Millisecond)
|
|
now := time.Now()
|
|
var q []time.Time
|
|
for i := range 3 + k%6 {
|
|
q = append(q, now.Add(-time.Duration(2+i*4)*time.Minute))
|
|
}
|
|
f.SetQueue(q)
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-t.C:
|
|
}
|
|
}
|
|
}()
|
|
pf := filepath.Join(dir, "password")
|
|
if err := os.WriteFile(pf, []byte(pw+"\n"), 0o600); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
yaml := fmt.Sprintf(`mail:
|
|
account: %s
|
|
password_file: %s
|
|
server: mail.example
|
|
smtp: %s
|
|
imap: %s
|
|
url: %s
|
|
client_id: cairn-obs
|
|
redirect_url: https://obs.example/never-visited
|
|
host: %s
|
|
every: 1m
|
|
wait: 45s
|
|
stand_in: true
|
|
`, f.User, pf, f.SMTPAddr, f.IMAPAddr, f.URL, hostName(48))
|
|
p := filepath.Join(dir, "mail.yaml")
|
|
if err := os.WriteFile(p, []byte(yaml), 0o600); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Printf("fleet: mail server on 127.0.0.1:%d-%d; %s has the mail: section for obs-beacond.yaml", mailPort, mailPort+2, p)
|
|
}
|