syslogLog.WithFields(logrus.Fields{ "check": "sensupluginses", "client": host, "version": version.AppVersion(), "error": err, "esIndex": esIndex, }).Error(`Could not create an elasticsearch index`) } } // Create an Elasticsearch document. The document type will define the mapping used for the document. doc := make(map[string]interface{}) var docID string docID = sensuhandler.EventName(sensuEvent.Client.Name, sensuEvent.Check.Name) doc["monitored_instance"] = sensuEvent.AcquireMonitoredInstance() doc["sensu_client"] = sensuEvent.Client.Name doc["incident_timestamp"] = time.Unix(sensuEvent.Check.Issued, 0).Format(time.RFC3339) doc["check_name"] = sensuhandler.CreateCheckName(sensuEvent.Check.Name) doc["check_state"] = sensuhandler.DefineStatus(sensuEvent.Check.Status) doc["sensuEnv"] = sensuhandler.DefineSensuEnv(sensuEnv.Sensu.Environment) doc["tags"] = sensuEvent.Check.Tags doc["instance_address"] = sensuEvent.Client.Address doc["check_state_duration"] = sensuhandler.DefineCheckStateDuration() // Add a document to the Elasticsearch index _, err = client.Index(). Index(esIndex). Type(esType). Id(docID). BodyJson(doc).
} // read in the event data from the sensu server sensuEvent := new(sensuhandler.SensuEvent) sensuEvent = sensuEvent.AcquireSensuEvent() // This is done with an api token not an incoming webhook to a specific channel api := slack.New(slackToken) params := slack.PostMessageParameters{} // Build an attachment message for sending to the specified slack channel attachment := slack.Attachment{ Color: sensuhandler.SetColor(sensuEvent.Check.Status), Fields: []slack.AttachmentField{ slack.AttachmentField{ Title: "Monitored Instance", Value: sensuEvent.AcquireMonitoredInstance(), Short: true, }, slack.AttachmentField{ Title: "Sensu Client", Value: sensuEvent.Client.Name, Short: true, }, slack.AttachmentField{ Title: "Check Name", Value: sensuEvent.Check.Name, Short: true, }, slack.AttachmentField{ Title: "Check State", Value: sensuhandler.DefineStatus(sensuEvent.Check.Status),