producer: rimuove tutti i record tranne il primo ( il piu' recente ) lrange(1, -1) main: options: xymon: manda stato a xymon
51 lines
950 B
Go
51 lines
950 B
Go
// xymon.go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func sendStatus() {
|
|
|
|
var msg string
|
|
|
|
host := strings.Replace(opts.Hostname, ".", ",", -1)
|
|
|
|
if count.GetErr() > 0 {
|
|
msg = fmt.Sprintf("status %s.llmongo %s %s %d", host, "yellow", "errors", count.GetErr())
|
|
} else {
|
|
msg = fmt.Sprintf("status %s.llmongo %s %s %d", host, "green", "logins", count.GetLog())
|
|
}
|
|
|
|
if opts.Debug {
|
|
fmt.Println("Sending: ", msg)
|
|
}
|
|
|
|
xymonSend([]byte(msg))
|
|
}
|
|
|
|
func xymonSend(msg []byte) error {
|
|
cl, err := net.Dial("tcp", opts.Xymon)
|
|
defer cl.Close()
|
|
if err != nil {
|
|
fmt.Printf("xymon connect error: ", err)
|
|
log.Printf("xymon connect error: ", err)
|
|
return err
|
|
}
|
|
|
|
// fmt.Printf("xymon: %s - localhost: %s\n", cl.RemoteAddr(), cl.LocalAddr())
|
|
|
|
_, err = cl.Write(msg)
|
|
if err != nil {
|
|
fmt.Printf("xymon write error: ", err)
|
|
log.Printf("xymon write error: ", err)
|
|
return err
|
|
}
|
|
|
|
// fmt.Printf("written: %d\n", tot)
|
|
|
|
return nil
|
|
}
|