コード例 #1
0
ファイル: root.go プロジェクト: yieldbot/sensupluginses
func init() {
	cobra.OnInitialize(initConfig)

	// Setup logging for the package. Doing it here is much eaiser than in each
	// binary. If you want to overwrite it in a specific binary then feel free.
	hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
	if err != nil {
		panic(err)
	}
	syslogLog.Hooks.Add(hook)
	syslogLog.Formatter = new(logrus.JSONFormatter)

	// Set the hostname for use in logging within the package. Doing it here is
	// cleaner than in each binary but if you want to use some other method just
	// override the variable in the specific binary.
	host, err = os.Hostname()
	if err != nil {
		syslogLog.WithFields(logrus.Fields{
			"check":   "sensupluginses",
			"client":  "unknown",
			"version": version.AppVersion(),
			"error":   err,
		}).Error(`Could not determine the hostname of this machine as reported by the kernel.`)
		sensuutil.Exit("GENERALGOLANGERROR")
	}

	RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.sensupluginses.yaml)")
	RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
コード例 #2
0
		// read in the event data from the sensu server
		sensuEvent := new(sensuhandler.SensuEvent)
		sensuEvent = sensuEvent.AcquireSensuEvent()

		// set the environment this is running in (prd, dev,stg)
		sensuEnv = sensuEnv.SetSensuEnv()

		// Create a client
		client, err := elastic.NewClient(
			elastic.SetURL("http://" + esHost + ":" + esPort),
		)
		if err != nil {
			syslogLog.WithFields(logrus.Fields{
				"check":   "sensupluginses",
				"client":  host,
				"version": version.AppVersion(),
				"error":   err,
				"esHost":  esHost,
				"esPort":  esPort,
			}).Error(`Could not create an elasticsearch client`)

		}

		// Check to see if the index exists and if not create it
		if client.IndexExists(esIndex) == nil { // need to test to make sure this does what I want
			_, err = client.CreateIndex(esIndex).Do()
			if err != nil {
				syslogLog.WithFields(logrus.Fields{
					"check":   "sensupluginses",
					"client":  host,
					"version": version.AppVersion(),
コード例 #3
0
ファイル: root.go プロジェクト: yieldbot/sensupluginses
	"github.com/yieldbot/sensupluginses/version"
)

// Configuration via Viper
var cfgFile string

// Hostname for logging
var host string

// Create a logging instance.
var syslogLog = logrus.New()

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
	Use:   "sensupluginses",
	Short: fmt.Sprintf("An elasticsearch handler for Sensu - (%s)", version.AppVersion()),
	Long: `This plugin currently contains a single handler that will drop
Sensu check results into Elasticsearch.`,
}

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
	if err := RootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(-1)
	}
}

func init() {
	cobra.OnInitialize(initConfig)