本文整理汇总了Golang中github.com/sensu/uchiwa/uchiwa/logger.Warningf函数的典型用法代码示例。如果您正苦于以下问题:Golang Warningf函数的具体用法?Golang Warningf怎么用?Golang Warningf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warningf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BuildEventsMetrics
// BuildEventsMetrics builds the metrics for the events
func BuildEventsMetrics(events *[]interface{}) *structs.StatusMetrics {
metrics := structs.StatusMetrics{}
metrics.Total = len(*events)
for _, e := range *events {
event := e.(map[string]interface{})
check, ok := event["check"].(map[string]interface{})
if !ok {
logger.Warningf("Could not assert this check to an interface: %+v", event["check"])
continue
}
status, ok := check["status"].(float64)
if !ok {
logger.Warningf("Could not assert this status to a flot64: %+v", check["status"])
continue
}
if status == 2.0 {
metrics.Critical++
continue
} else if status == 1.0 {
metrics.Warning++
continue
}
metrics.Unknown++
}
return &metrics
}
示例2: initSensu
func initSensu(apis []SensuConfig) []SensuConfig {
for i, api := range apis {
// Set a datacenter name if missing
if api.Name == "" {
logger.Warningf("Sensu API %s has no name property, make sure to set it in your configuration. Generating a temporary one...", api.URL)
apis[i].Name = fmt.Sprintf("sensu-%v", rand.Intn(100))
}
// Escape special characters in DC name
r := strings.NewReplacer(":", "", "/", "", ";", "", "?", "")
apis[i].Name = r.Replace(apis[i].Name)
// Make sure the host is not empty
if api.Host == "" {
logger.Fatalf("Sensu API %q Host is missing", api.Name)
}
// Determine the protocol to use
prot := "http"
if api.Ssl {
prot += "s"
}
// Set the API URL
apis[i].URL = fmt.Sprintf("%s://%s:%d%s", prot, api.Host, api.Port, api.Path)
}
return apis
}
示例3: BuildClientsMetrics
// BuildClientsMetrics builds the metrics for the events
func BuildClientsMetrics(clients *[]interface{}) *structs.StatusMetrics {
metrics := structs.StatusMetrics{}
metrics.Total = len(*clients)
for _, c := range *clients {
client := c.(map[string]interface{})
status, ok := client["status"].(int)
if !ok {
logger.Warningf("Could not assert this status to an int: %+v", client["status"])
continue
}
if status == 2.0 {
metrics.Critical++
continue
} else if status == 1.0 {
metrics.Warning++
continue
} else if status == 0.0 {
continue
}
metrics.Unknown++
}
return &metrics
}
示例4: initSensu
func (c *Config) initSensu() {
for i, api := range c.Sensu {
prot := "http"
if api.Name == "" {
logger.Warningf("Sensu API %s has no name property. Generating random one...", api.URL)
c.Sensu[i].Name = fmt.Sprintf("sensu-%v", rand.Intn(100))
}
// escape special characters in DC name
r := strings.NewReplacer(":", "", "/", "", ";", "", "?", "")
c.Sensu[i].Name = r.Replace(api.Name)
if api.Host == "" {
logger.Fatalf("Sensu API %q Host is missing", api.Name)
}
if api.Timeout == 0 {
c.Sensu[i].Timeout = 10
} else if api.Timeout >= 1000 { // backward compatibility with < 0.3.0 version
c.Sensu[i].Timeout = api.Timeout / 1000
}
if api.Port == 0 {
c.Sensu[i].Port = 4567
}
if api.Ssl {
prot += "s"
}
c.Sensu[i].URL = fmt.Sprintf("%s://%s:%d%s", prot, api.Host, c.Sensu[i].Port, api.Path)
}
}
示例5: WebServer
// WebServer starts the web server and serves GET & POST requests
func (u *Uchiwa) WebServer(publicPath *string, auth auth.Config) {
// Private endpoints
http.Handle("/aggregates", auth.Authenticate(http.HandlerFunc(u.aggregatesHandler)))
http.Handle("/aggregates/", auth.Authenticate(http.HandlerFunc(u.aggregatesHandler)))
http.Handle("/checks", auth.Authenticate(http.HandlerFunc(u.checksHandler)))
http.Handle("/clients", auth.Authenticate(http.HandlerFunc(u.clientsHandler)))
http.Handle("/clients/", auth.Authenticate(http.HandlerFunc(u.clientsHandler)))
http.Handle("/config", auth.Authenticate(http.HandlerFunc(u.configHandler)))
http.Handle("/datacenters", auth.Authenticate(http.HandlerFunc(u.datacentersHandler)))
http.Handle("/events", auth.Authenticate(http.HandlerFunc(u.eventsHandler)))
http.Handle("/events/", auth.Authenticate(http.HandlerFunc(u.eventsHandler)))
http.Handle("/request", auth.Authenticate(http.HandlerFunc(u.requestHandler)))
http.Handle("/results/", auth.Authenticate(http.HandlerFunc(u.resultsHandler)))
http.Handle("/stashes", auth.Authenticate(http.HandlerFunc(u.stashesHandler)))
http.Handle("/stashes/", auth.Authenticate(http.HandlerFunc(u.stashesHandler)))
http.Handle("/subscriptions", auth.Authenticate(http.HandlerFunc(u.subscriptionsHandler)))
if u.Config.Uchiwa.Enterprise == false {
http.Handle("/metrics", auth.Authenticate(http.HandlerFunc(u.metricsHandler)))
}
// Static files
http.Handle("/", http.FileServer(http.Dir(*publicPath)))
// Public endpoints
http.Handle("/config/", http.HandlerFunc(u.configHandler))
http.Handle("/health", http.HandlerFunc(u.healthHandler))
http.Handle("/health/", http.HandlerFunc(u.healthHandler))
http.Handle("/login", auth.GetIdentification())
listen := fmt.Sprintf("%s:%d", u.Config.Uchiwa.Host, u.Config.Uchiwa.Port)
logger.Warningf("Uchiwa is now listening on %s", listen)
logger.Fatal(http.ListenAndServe(listen, nil))
}
示例6: setDc
func setDc(v interface{}, dc string) {
m, ok := v.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert interface: %+v", v)
} else {
m["dc"] = dc
}
}
示例7: buildClientHistory
func (u *Uchiwa) buildClientHistory(client, dc string, history []interface{}) []interface{} {
for _, h := range history {
m, ok := h.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert this client history to an interface: %+v", h)
continue
}
// Set some attributes for easier frontend consumption
check, ok := m["check"].(string)
if !ok {
continue
}
m["client"] = client
m["dc"] = dc
m["acknowledged"] = helpers.IsAcknowledged(check, client, dc, u.Data.Stashes)
// Add missing attributes to last_result object
if m["last_result"] != nil {
if m["last_status"] == 0.0 {
continue
}
event, err := helpers.GetEvent(check, client, dc, &u.Data.Events)
if err != nil {
continue
}
lastResult, ok := m["last_result"].(map[string]interface{})
if !ok {
continue
}
if event["action"] != nil {
lastResult["action"] = event["action"]
}
if event["occurrences"] != nil {
lastResult["occurrences"] = event["occurrences"]
}
}
// Maintain backward compatiblity with Sensu <= 0.17
// by constructing the last_result object
if m["last_status"] != nil && m["last_status"] != 0.0 {
event, err := helpers.GetEvent(check, client, dc, &u.Data.Events)
if err != nil {
continue
}
m["last_result"] = event
} else {
m["last_result"] = map[string]interface{}{"last_execution": m["last_execution"], "status": m["last_status"]}
}
}
return history
}
示例8: findOutput
func (u *Uchiwa) findOutput(id *string, h map[string]interface{}, dc *string) string {
if h["last_status"] == 0 {
return ""
}
for _, e := range u.Data.Events {
// does the dc match?
m, ok := e.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert this event to an interface %+v", e)
continue
}
if m["dc"] != *dc {
continue
}
// does the client match?
c, ok := m["client"].(map[string]interface{})
if !ok {
logger.Warningf("Could not assert this client to an interface: %+v", c)
continue
}
if c["name"] != *id {
continue
}
// does the check match?
k := m["check"].(map[string]interface{})
if !ok {
logger.Warningf("Could not assert this check to an interface: %+v", k)
continue
}
if k["name"] != h["check"] {
continue
}
return k["output"].(string)
}
return ""
}
示例9: FindDcFromInterface
// FindDcFromInterface ...
func FindDcFromInterface(data interface{}, datacenters *[]sensu.Sensu) (*sensu.Sensu, map[string]interface{}, error) {
m, ok := data.(map[string]interface{})
if !ok {
logger.Warningf("Type assertion failed. Could not assert the given interface into a map: %+v", data)
return nil, nil, errors.New("Could not determine the datacenter.")
}
id := m["dc"].(string)
if id == "" {
logger.Warningf("The received interface does not contain any datacenter information: ", data)
return nil, nil, errors.New("Could not determine the datacenter.")
}
for _, dc := range *datacenters {
if dc.Name == id {
return &dc, m, nil
}
}
logger.Warningf("Could not find the datacenter %s into %+v: ", id, data)
return nil, nil, fmt.Errorf("Could not find the datacenter %s", id)
}
示例10: findModel
func findModel(id string, dc string, checks []interface{}) map[string]interface{} {
for _, k := range checks {
m, ok := k.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert check interface %+v", k)
continue
}
if m["name"] == id && m["dc"] == dc {
return m
}
}
return nil
}
示例11: findClientInClients
func (u *Uchiwa) findClientInClients(id *string, dc *string) (map[string]interface{}, error) {
for _, c := range u.Data.Clients {
m, ok := c.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert this client to an interface %+v", c)
continue
}
if m["name"] == *id && m["dc"] == *dc {
return m, nil
}
}
return nil, fmt.Errorf("Could not find client %s", *id)
}
示例12: getSlice
func (s *Sensu) getSlice(endpoint string, limit int) ([]interface{}, error) {
apis := shuffle(s.APIs)
for i := 0; i < len(apis); i++ {
logger.Debugf("GET %s/%s", s.APIs[i].URL, endpoint)
slice, err := apis[i].getSlice(endpoint, limit)
if err == nil {
return slice, err
}
logger.Warningf("GET %s/%s returned: %v", s.APIs[i].URL, endpoint, err)
}
return nil, errors.New("")
}
示例13: postPayload
func (s *Sensu) postPayload(endpoint string, payload string) (map[string]interface{}, error) {
apis := shuffle(s.APIs)
for i := 0; i < len(apis); i++ {
logger.Debugf("POST %s/%s", s.APIs[i].URL, endpoint)
m, err := apis[i].postPayload(endpoint, payload)
if err == nil {
return m, err
}
logger.Warningf("POST %s/%s returned: %v", s.APIs[i].URL, endpoint, err)
}
return nil, errors.New("")
}
示例14: getBytes
func (s *Sensu) getBytes(endpoint string) ([]byte, *http.Response, error) {
apis := shuffle(s.APIs)
for i := 0; i < len(apis); i++ {
logger.Debugf("GET %s/%s", s.APIs[i].URL, endpoint)
bytes, res, err := apis[i].getBytes(endpoint)
if err == nil {
return bytes, res, err
}
logger.Warningf("GET %s/%s returned: %v", s.APIs[i].URL, endpoint, err)
}
return nil, nil, errors.New("")
}
示例15: delete
func (s *Sensu) delete(endpoint string) error {
apis := shuffle(s.APIs)
var err error
for i := 0; i < len(apis); i++ {
logger.Infof("DELETE %s/%s", s.APIs[i].URL, endpoint)
err = apis[i].delete(endpoint)
if err == nil {
return err
}
logger.Warningf("DELETE %s/%s returned: %v", s.APIs[i].URL, endpoint, err)
}
return err
}