本文整理汇总了Golang中github.com/sensu/uchiwa/uchiwa/logger.Warningf函数的典型用法代码示例。如果您正苦于以下问题:Golang Warningf函数的具体用法?Golang Warningf怎么用?Golang Warningf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warningf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:cgeers,项目名称:uchiwa,代码行数:33,代码来源:helpers.go
示例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
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:28,代码来源:config.go
示例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
}
开发者ID:cgeers,项目名称:uchiwa,代码行数:29,代码来源:helpers.go
示例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)
}
}
开发者ID:jsoriano,项目名称:uchiwa,代码行数:28,代码来源:config.go
示例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))
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:34,代码来源:server.go
示例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
}
}
开发者ID:jsoriano,项目名称:uchiwa,代码行数:8,代码来源:helpers.go
示例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
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:56,代码来源:client.go
示例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 ""
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:41,代码来源:client.go
示例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)
}
开发者ID:jsoriano,项目名称:uchiwa,代码行数:23,代码来源:helpers.go
示例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
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:13,代码来源:helpers.go
示例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)
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:13,代码来源:client.go
示例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("")
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:14,代码来源:loadbalancing.go
示例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("")
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:14,代码来源:loadbalancing.go
示例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("")
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:14,代码来源:loadbalancing.go
示例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
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:15,代码来源:loadbalancing.go
示例16: loadFile
// loadFile loads a Config struct from a configuration file
func loadFile(path string) (*Config, error) {
logger.Warningf("Loading the configuration file %s", path)
c := new(Config)
file, err := os.Open(path)
if err != nil {
if len(path) > 1 {
return nil, fmt.Errorf("Error: could not read config file %s.", path)
}
}
decoder := json.NewDecoder(file)
err = decoder.Decode(c)
if err != nil {
return nil, fmt.Errorf("Error decoding file %s: %s", path, err)
}
return c, nil
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:20,代码来源:config.go
示例17: stashesHandler
// Stashes
func (u *Uchiwa) stashesHandler(w http.ResponseWriter, r *http.Request) {
token := auth.GetTokenFromContext(r)
resources := strings.Split(r.URL.Path, "/")
// DELETE on /stashes/{dc}/{path}
if r.Method == "DELETE" && len(resources) >= 3 {
dc := resources[2]
path := strings.Join(resources[3:], "/")
if dc == "" || path == "" {
http.Error(w, "", http.StatusBadRequest)
return
}
unauthorized := FilterGetRequest(dc, token)
if unauthorized {
http.Error(w, fmt.Sprint(""), http.StatusNotFound)
return
}
err := u.DeleteStash(dc, path)
if err != nil {
logger.Warningf("Could not delete the stash '%s': %s", path, err)
http.Error(w, "Could not create the stash", http.StatusNotFound)
return
}
} else if r.Method == "GET" {
// GET on /stashes
stashes := FilterStashes(&u.Data.Stashes, token)
// Create header
w.Header().Add("Accept-Charset", "utf-8")
w.Header().Add("Content-Type", "application/json")
w.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(w)
defer gz.Close()
if err := json.NewEncoder(gz).Encode(stashes); err != nil {
http.Error(w, fmt.Sprintf("Cannot encode response data: %v", err), http.StatusInternalServerError)
return
}
return
} else if r.Method == "POST" {
// POST on /stashes
decoder := json.NewDecoder(r.Body)
var data stash
err := decoder.Decode(&data)
if err != nil {
http.Error(w, "Could not decode body", http.StatusInternalServerError)
return
}
// verify that the authenticated user is authorized to access this resource
unauthorized := FilterGetRequest(data.Dc, token)
if unauthorized {
http.Error(w, fmt.Sprint(""), http.StatusNotFound)
return
}
if token != nil && token.Claims["Username"] != nil {
data.Content["username"] = token.Claims["Username"]
}
err = u.PostStash(data)
if err != nil {
http.Error(w, "Could not create the stash", http.StatusNotFound)
return
}
} else {
http.Error(w, "", http.StatusBadRequest)
return
}
}
开发者ID:matthelgen,项目名称:uchiwa,代码行数:74,代码来源:server.go
示例18: GetIdentification
// GetIdentification retrieves the user & pass from a POST and authenticates the user against the Identification driver
func (a *Config) GetIdentification() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Redirect(w, r, "/#/login", http.StatusFound)
return
}
decoder := json.NewDecoder(r.Body)
var data interface{}
err := decoder.Decode(&data)
if err != nil {
logger.Warningf("Could not decode the body: %s", err)
http.Error(w, "", http.StatusInternalServerError)
return
}
m, ok := data.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert the body: %s", err)
http.Error(w, "", http.StatusInternalServerError)
return
}
u := m["user"].(string)
p := m["pass"].(string)
if u == "" || p == "" {
logger.Info("Authentication failed: user and password must not be empty")
http.Error(w, "", http.StatusUnauthorized)
return
}
// validate the user with the Login authentication driver
user, err := a.Driver(u, p)
if err != nil {
message := fmt.Sprintf("Authentication failed: %s", err)
// Output to stdout
logger.Info(message)
// Output to audit log
log := structs.AuditLog{Action: "loginfailure", Level: "default", Output: message}
log.RemoteAddr = helpers.GetIP(r)
audit.Log(log)
http.Error(w, "", http.StatusUnauthorized)
return
}
// obfuscate the user's salt & hash
user.PasswordHash = ""
user.PasswordSalt = ""
token, err := GetToken(&user.Role, u)
if err != nil {
logger.Warningf("Authentication failed, could not create the token: %s", err)
http.Error(w, "", http.StatusInternalServerError)
return
}
// Add token to the user struct
user.Token = token
j, err := json.Marshal(user)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(j)
return
})
}
开发者ID:jsoriano,项目名称:uchiwa,代码行数:74,代码来源:handlers.go
示例19: buildEvents
// BuildEvents constructs events objects for frontend consumption
func (d *Daemon) buildEvents() {
for _, e := range d.Data.Events {
m := e.(map[string]interface{})
// build backward compatible event object for Sensu < 0.13.0
if m["id"] == nil {
// build client object
c := m["client"]
delete(m, "client")
m["client"] = map[string]interface{}{"name": c}
// build check object
c = m["check"]
delete(m, "check")
m["check"] = map[string]interface{}{"name": c, "issued": m["issued"], "output": m["output"], "status": m["status"]}
// is flapping?
if m["action"] == false {
m["action"] = "create"
} else {
m["action"] = "flapping"
}
// remove old entries
delete(m, "issued")
delete(m, "output")
delete(m, "status")
}
// we assume the event isn't acknowledged in case we can't assert the following values
m["acknowledged"] = false
// get client name
c, ok := m["client"].(map[string]interface{})
if !ok {
logger.Warningf("Could not assert event's client interface from %+v", c)
continue
}
clientName, ok := c["name"].(string)
if !ok {
logger.Warningf("Could not assert event's client name from %+v", c)
continue
}
// get check name
k, ok := m["check"].(map[string]interface{})
if !ok {
logger.Warningf("Could not assert event's check interface from %+v", k)
continue
}
checkName, ok := k["name"].(string)
if !ok {
logger.Warningf("Could not assert event's check name from %+v", k)
continue
}
// get dc name
dcName, ok := m["dc"].(string)
if !ok {
logger.Warningf("Could not assert event's datacenter name from %+v", m)
continue
}
// determine if the event is acknowledged
m["acknowledged"] = IsAcknowledged(clientName, checkName, dcName, d.Data.Stashes)
// detertermine if the client is acknowledged
m["client"].(map[string]interface{})["acknowledged"] = IsAcknowledged(clientName, "", dcName, d.Data.Stashes)
}
}
开发者ID:jsoriano,项目名称:uchiwa,代码行数:74,代码来源:events.go
示例20: fetchData
// getData retrieves all endpoints for every datacenter
func (d *Daemon) fetchData() {
d.Data.Health.Sensu = make(map[string]structs.SensuHealth, len(*d.Datacenters))
for _, datacenter := range *d.Datacenters {
logger.Infof("Updating the datacenter %s", datacenter.Name)
// set default health status
d.Data.Health.Sensu[datacenter.Name] = structs.SensuHealth{Output: datacenterErrorString, Status: 2}
d.Data.Health.Uchiwa = "ok"
// fetch sensu data from the datacenter
stashes, err := datacenter.GetStashes()
if err != nil {
logger.Warningf("Connection failed to the datacenter %s", datacenter.Name)
continue
}
checks, err := datacenter.GetChecks()
if err != nil {
logger.Warningf("Connection failed to the datacenter %s", datacenter.Name)
continue
}
clients, err := datacenter.GetClients()
if err != nil {
logger.Warningf("Connection failed to the datacenter %s", datacenter.Name)
continue
}
events, err := datacenter.GetEvents()
if err != nil {
logger.Warningf("Connection failed to the datacenter %s", datacenter.Name)
continue
}
info, err := datacenter.GetInfo()
if err != nil {
logger.Warningf("Connection failed to the datacenter %s", datacenter.Name)
continue
}
aggregates, err := datacenter.GetAggregates()
if err != nil {
logger.Warningf("Connection failed to the datacenter %s", datacenter.Name)
continue
}
if d.Enterprise {
d.Data.SERawMetrics = *getEnterpriseMetrics(&datacenter, &d.Data.SERawMetrics)
}
// Determine the status of the datacenter
if !info.Redis.Connected {
d.Data.Health.Sensu[datacenter.Name] = structs.SensuHealth{Output: "Not connected to Redis", Status: 1}
} else if !info.Transport.Connected {
d.Data.Health.Sensu[datacenter.Name] = structs.SensuHealth{Output: "Not connected to the transport", Status: 1}
} else {
d.Data.Health.Sensu[datacenter.Name] = structs.SensuHealth{Output: "ok", Status: 0}
}
// add fetched data into d.Data interface
for _, v := range stashes {
setDc(v, datacenter.Name)
d.Data.Stashes = append(d.Data.Stashes, v)
}
for _, v := range checks {
setDc(v, datacenter.Name)
d.Data.Checks = append(d.Data.Checks, v)
}
for _, v := range clients {
setDc(v, datacenter.Name)
d.Data.Clients = append(d.Data.Clients, v)
}
for _, v := range events {
setDc(v, datacenter.Name)
d.Data.Events = append(d.Data.Events, v)
}
for _, v := range aggregates {
setDc(v, datacenter.Name)
d.Data.Aggregates = append(d.Data.Aggregates, v)
}
// build datacenter
dc := d.buildDatacenter(&datacenter.Name, info)
dc.Stats["aggregates"] = len(aggregates)
dc.Stats["checks"] = len(checks)
dc.Stats["clients"] = len(clients)
dc.Stats["events"] = len(events)
dc.Stats["stashes"] = len(stashes)
d.Data.Dc = append(d.Data.Dc, dc)
}
}
开发者ID:nhooey,项目名称:uchiwa,代码行数:88,代码来源:daemon.go
注:本文中的github.com/sensu/uchiwa/uchiwa/logger.Warningf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论