You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
![]()
6 years ago
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
"github.com/spf13/cobra"
|
||
|
"github.com/spf13/viper"
|
||
![]()
6 years ago
|
|
||
|
"github.com/noerw/osem_notify/core"
|
||
|
"github.com/noerw/osem_notify/utils"
|
||
![]()
6 years ago
|
)
|
||
|
|
||
|
func init() {
|
||
|
debugCmd.AddCommand(debugNotificationsCmd)
|
||
|
rootCmd.AddCommand(debugCmd)
|
||
|
}
|
||
|
|
||
|
var debugCmd = &cobra.Command{
|
||
|
Use: "debug",
|
||
|
Short: "Run some debugging checks on osem_notify itself",
|
||
|
Long: "osem_notify debug <feature> tests the functionality of the given feature",
|
||
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||
|
log.SetLevel(log.DebugLevel)
|
||
|
},
|
||
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
||
![]()
6 years ago
|
utils.PrintConfig()
|
||
![]()
6 years ago
|
},
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
cmd.Help()
|
||
|
},
|
||
|
}
|
||
|
|
||
|
var debugNotificationsCmd = &cobra.Command{
|
||
|
Use: "notifications",
|
||
|
Short: "Verify that notifications are working",
|
||
|
Long: "osem_notify debug <feature> tests the functionality of the given feature",
|
||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||
|
defaultNotifyConf := &core.NotifyConfig{}
|
||
|
err := viper.UnmarshalKey("defaultHealthchecks", defaultNotifyConf)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
for transport, notifier := range core.Notifiers {
|
||
|
notLog := log.WithField("transport", transport)
|
||
|
opts := defaultNotifyConf.Notifications.Options
|
||
|
notLog.Infof("testing notifer %s with options %v", transport, opts)
|
||
|
n, err := notifier.New(opts)
|
||
|
if err != nil {
|
||
|
notLog.Warnf("could not initialize %s notifier. configuration might be missing?", transport)
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
host, _ := os.Hostname()
|
||
|
err = n.Submit(core.Notification{
|
||
6 years ago
|
Subject: "Test notification from openSenseMap notifier",
|
||
![]()
6 years ago
|
Body: fmt.Sprintf("Your notification set up on %s is working fine!", host),
|
||
|
})
|
||
|
if err != nil {
|
||
6 years ago
|
notLog.Warnf("could not submit test notification for %s notifier: %s", transport, err)
|
||
![]()
6 years ago
|
continue
|
||
|
}
|
||
|
notLog.Info("Test notification (successfully?) submitted, check the specified inbox")
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
},
|
||
|
}
|