本文整理汇总了Golang中github.com/AcalephStorage/consul-alerts/Godeps/_workspace/src/github.com/Sirupsen/logrus.Println函数的典型用法代码示例。如果您正苦于以下问题:Golang Println函数的具体用法?Golang Println怎么用?Golang Println使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Println函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processChecks
func processChecks() {
for {
<-checksChannel
// if there's no leader, let's retry for at least 30 seconds in 5 second intervals.
retryCount := 0
for !hasLeader() {
if retryCount >= 6 {
continue
}
log.Println("There is current no consul-alerts leader... waiting for one.")
time.Sleep(5 * time.Second)
retryCount++
}
if !leaderCandidate.leader {
log.Println("Currently not the leader. Ignoring checks.")
continue
}
log.Println("Running health check.")
changeThreshold := consulClient.CheckChangeThreshold()
for elapsed := 0; elapsed < changeThreshold; elapsed += 10 {
consulClient.UpdateCheckData()
time.Sleep(10 * time.Second)
}
consulClient.UpdateCheckData()
log.Println("Processing health checks for notification.")
alerts := consulClient.NewAlerts()
if len(alerts) > 0 {
notify(alerts)
}
}
}
示例2: handleChecks
func (c *CheckProcessor) handleChecks(checks []consul.Check) {
consulClient.LoadConfig()
retryCount := 0
for !hasLeader() {
if retryCount >= 6 {
return
}
log.Println("There is current no consul-alerts leader... waiting for one.")
time.Sleep(5 * time.Second)
retryCount++
}
if !c.leaderElection.leader {
log.Println("Currently not the leader. Ignoring checks.")
return
}
log.Println("Running health check.")
changeThreshold := consulClient.CheckChangeThreshold()
for elapsed := 0; elapsed < changeThreshold; elapsed += 10 {
consulClient.UpdateCheckData()
time.Sleep(10 * time.Second)
}
consulClient.UpdateCheckData()
log.Println("Processing health checks for notification.")
alerts := consulClient.NewAlerts()
if len(alerts) > 0 {
c.notify(alerts)
}
}
示例3: Notify
func (influxdb *InfluxdbNotifier) Notify(messages Messages) bool {
// Make client
influxdbClient, err := client.NewHTTPClient(client.HTTPConfig{
Addr: influxdb.Host,
Username: influxdb.Username,
Password: influxdb.Password,
})
if err != nil {
log.Println("unable to access influxdb. can't send notification. ", err)
return false
}
bp, _ := client.NewBatchPoints(client.BatchPointsConfig{
Database: influxdb.Database,
Precision: "ms",
})
influxdb.toBatchPoints(messages, bp)
err = influxdbClient.Write(bp)
if err != nil {
log.Println("unable to send notifications: ", err)
return false
}
log.Println("influxdb notification sent.")
return true
}
示例4: watchMode
func watchMode(arguments map[string]interface{}) {
loglevelString, _ := arguments["--log-level"].(string)
if loglevelString != "" {
loglevel, err := log.ParseLevel(loglevelString)
if err == nil {
log.SetLevel(loglevel)
} else {
log.Println("Log level not set:", err)
}
}
checkMode := arguments["checks"].(bool)
eventMode := arguments["event"].(bool)
addr := arguments["--alert-addr"].(string)
var watchType string
switch {
case checkMode:
watchType = "checks"
case eventMode:
watchType = "events"
}
url := fmt.Sprintf("http://%s/v1/process/%s", addr, watchType)
resp, err := http.Post(url, "text/json", os.Stdin)
if err != nil {
log.Println("consul-alert daemon is not running.", err)
os.Exit(2)
} else {
resp.Body.Close()
}
}
示例5: handleEvents
func (ep *EventProcessor) handleEvents(events []consul.Event) {
for _, event := range events {
log.Println("----------------------------------------")
log.Printf("Processing event %s:\n", event.ID)
log.Println("----------------------------------------")
eventHandlers := consulClient.EventHandlers(event.Name)
for _, eventHandler := range eventHandlers {
data, err := json.Marshal(&event)
if err != nil {
log.Println("Unable to read event: ", event)
// then what?
}
input := bytes.NewReader(data)
output := new(bytes.Buffer)
cmd := exec.Command(eventHandler)
cmd.Stdin = input
cmd.Stdout = output
cmd.Stderr = output
if err := cmd.Run(); err != nil {
log.Println("error running handler: ", err)
} else {
log.Printf(">>> \n%s -> %s:\n %s\n", event.ID, eventHandler, output)
}
}
log.Printf("Event Processed.\n\n")
}
}
示例6: sendCustom
func (n *NotifEngine) sendCustom(messages notifier.Messages) {
for notifName, notifCmd := range consulClient.CustomNotifiers() {
filteredMessages := make(notifier.Messages, 0)
for _, m := range messages {
if boolVal, exists := m.NotifList[notifName]; (exists && boolVal) || len(m.NotifList) == 0 {
filteredMessages = append(filteredMessages, m)
}
}
if len(filteredMessages) == 0 {
continue
}
data, err := json.Marshal(&filteredMessages)
if err != nil {
log.Println("Unable to read messages: ", err)
return
}
input := bytes.NewReader(data)
output := new(bytes.Buffer)
cmd := exec.Command(notifCmd)
cmd.Stdin = input
cmd.Stdout = output
cmd.Stderr = output
if err := cmd.Run(); err != nil {
log.Println("error running notifier: ", err)
} else {
log.Println(">>> notification sent to:", notifCmd)
}
log.Println(output)
}
}
示例7: processChecks
func processChecks() {
for {
<-checksChannel
for leaderCandidate.Leader() == "" {
log.Println("There is current no consul-alerts leader... waiting for one.")
time.Sleep(5 * time.Second)
}
if !leaderCandidate.IsLeader() {
log.Println("Currently not the leader. Ignoring checks.")
continue
}
log.Println("Running health check.")
changeThreshold := consulClient.CheckChangeThreshold()
for elapsed := 0; elapsed < changeThreshold; elapsed += 10 {
consulClient.UpdateCheckData()
time.Sleep(10 * time.Second)
}
consulClient.UpdateCheckData()
log.Println("Processing health checks for notification.")
alerts := consulClient.NewAlerts()
if len(alerts) > 0 {
notify(alerts)
}
}
}
示例8: Notify
func (opsgenie *OpsGenieNotifier) Notify(messages Messages) bool {
overallStatus, pass, warn, fail := messages.Summary()
client := new(ogcli.OpsGenieClient)
client.SetApiKey(opsgenie.ApiKey)
alertCli, cliErr := client.Alert()
if cliErr != nil {
log.Println("Opsgenie notification trouble with client")
return false
}
for _, message := range messages {
title := fmt.Sprintf("\n%s:%s:%s is %s.", message.Node, message.Service, message.Check, message.Status)
content := fmt.Sprintf(header, opsgenie.ClusterName, overallStatus, fail, warn, pass)
content += fmt.Sprintf("\n%s:%s:%s is %s.", message.Node, message.Service, message.Check, message.Status)
content += fmt.Sprintf("\n%s", message.Output)
// create the alert
response, alertErr := opsgenie.Send(alertCli, title, content)
if alertErr != nil {
log.Println("Opsgenie notification trouble.", response.Status)
return false
}
}
log.Println("Opsgenie notification send.")
return true
}
示例9: Send
func (awssns *AwsSnsNotifier) Send(subject string, message string) bool {
svc := sns.New(session.New(&aws.Config{
Region: aws.String(awssns.Region),
}))
params := &sns.PublishInput{
Message: aws.String(message),
MessageAttributes: map[string]*sns.MessageAttributeValue{
"Key": {
DataType: aws.String("String"),
StringValue: aws.String("String"),
},
},
MessageStructure: aws.String("messageStructure"),
Subject: aws.String(subject),
TopicArn: aws.String(awssns.TopicArn),
}
resp, err := svc.Publish(params)
if err != nil {
log.Println(err.Error())
return false
}
log.Println(resp)
return true
}
示例10: runWatcher
func runWatcher(address, datacenter, watchType string) {
consulAlert := os.Args[0]
cmd := exec.Command(
"consul", "watch",
"-http-addr", address,
"-datacenter", datacenter,
"-type", watchType,
consulAlert, "watch", watchType)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
var exitCode int
switch err.(type) {
case *exec.ExitError:
exitError, _ := err.(*exec.ExitError)
status, _ := exitError.Sys().(syscall.WaitStatus)
exitCode = status.ExitStatus()
log.Println("Shutting down watcher --> Exit Code: ", exitCode)
case *exec.Error:
exitCode = 1
log.Println("Shutting down watcher --> Something went wrong running consul watch: ", err.Error())
default:
exitCode = 127
log.Println("Shutting down watcher --> Unknown error: ", err.Error())
}
os.Exit(exitCode)
} else {
log.Printf("Execution complete.")
}
}
示例11: NewClient
func NewClient(address, dc, aclToken string) (*ConsulAlertClient, error) {
config := consulapi.DefaultConfig()
config.Address = address
config.Datacenter = dc
config.Token = aclToken
api, _ := consulapi.NewClient(config)
alertConfig := DefaultAlertConfig()
client := &ConsulAlertClient{
api: api,
config: alertConfig,
}
try := 1
for {
try += try
log.Println("Checking consul agent connection...")
_, err := client.api.Status().Leader()
if err != nil {
log.Println("Waiting for consul:", err)
if try > 10 {
return nil, err
}
time.Sleep(10000 * time.Millisecond)
} else {
break
}
}
client.LoadConfig()
client.UpdateCheckData()
return client, nil
}
示例12: postToBeary
func (beary *BearyNotifier) postToBeary() bool {
data, err := json.Marshal(beary)
if err != nil {
log.Println("Unable to marshal beary payload:", err)
return false
}
log.Debugf("struct = %+v, json = %s", beary, string(data))
b := bytes.NewBuffer(data)
if res, err := http.Post(beary.Url, "application/json", b); err != nil {
log.Println("Unable to send data to beary:", err)
return false
} else {
defer res.Body.Close()
statusCode := res.StatusCode
if statusCode != 200 {
body, _ := ioutil.ReadAll(res.Body)
log.Println("Unable to notify beary:", string(body))
return false
} else {
log.Println("Beary notification sent.")
return true
}
}
}
示例13: Notify
func (influxdb *InfluxdbNotifier) Notify(messages Messages) bool {
config := &client.ClientConfig{
Host: influxdb.Host,
Username: influxdb.Username,
Password: influxdb.Password,
Database: influxdb.Database,
}
influxdbClient, err := client.New(config)
if err != nil {
log.Println("unable to access influxdb. can't send notification. ", err)
return false
}
seriesList := influxdb.toSeries(messages)
err = influxdbClient.WriteSeries(seriesList)
if err != nil {
log.Println("unable to send notifications: ", err)
return false
}
log.Println("influxdb notification sent.")
return true
}
示例14: processEvent
func processEvent(event consul.Event) {
log.Println("----------------------------------------")
log.Printf("Processing event %s:\n", event.ID)
log.Println("----------------------------------------")
eventHandlers := consulClient.EventHandlers(event.Name)
for _, eventHandler := range eventHandlers {
executeEventHandler(event, eventHandler)
}
log.Printf("Event Processed.\n\n")
}
示例15: toWatchObject
func toWatchObject(reader io.Reader, v interface{}) {
data, err := ioutil.ReadAll(reader)
if err != nil {
log.Println("stdin read error: ", err)
// todo: what to do when can't read?
}
err = json.Unmarshal(data, v)
if err != nil {
log.Println("json unmarshall error: ", err)
// todo: what if we can't serialise?
}
}