2
0
mirror of https://github.com/FluuxIO/go-xmpp synced 2024-11-11 07:11:03 +00:00
go-xmpp/cmd/fluuxmpp/check.go

42 lines
976 B
Go
Raw Normal View History

2019-07-16 20:03:26 +00:00
package main
import (
"github.com/bdlm/log"
"github.com/spf13/cobra"
"gosrc.io/xmpp"
)
var domain = ""
2019-08-06 09:00:52 +00:00
var cmdCheck = &cobra.Command{
Use: "check <host[:port]>",
Short: "is a command-line to check if you XMPP TLS certificate is valid and warn you before it expires",
2019-08-06 14:03:48 +00:00
Example: "fluuxmpp check chat.sum7.eu:5222 --domain meckerspace.de",
2019-07-16 20:03:26 +00:00
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runCheck(args[0], domain)
},
}
func init() {
2019-08-06 09:00:52 +00:00
cmdRoot.AddCommand(cmdCheck)
cmdCheck.Flags().StringVarP(&domain, "domain", "d", "", "domain if host handle multiple domains")
2019-07-16 20:03:26 +00:00
}
func runCheck(address, domain string) {
logger := log.WithFields(map[string]interface{}{
"address": address,
"domain": domain,
})
client, err := xmpp.NewChecker(address, domain)
if err != nil {
log.Fatal("Error: ", err)
}
if err = client.Check(); err != nil {
logger.Fatal("Failed connection check: ", err)
}
logger.Println("All checks passed")
}