Ver código fonte

[release] v0.12.0-unstable46

Yann Stepienik 1 ano atrás
pai
commit
2daf467650
4 arquivos alterados com 37 adições e 20 exclusões
  1. 1 1
      package.json
  2. 6 6
      src/docker/events.go
  3. 15 0
      src/metrics/alerts.go
  4. 15 13
      src/proxy/shield.go

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "cosmos-server",
-  "version": "0.12.0-unstable45",
+  "version": "0.12.0-unstable46",
   "description": "",
   "main": "test-server.js",
   "bugs": {

+ 6 - 6
src/docker/events.go

@@ -88,12 +88,12 @@ func DockerListenEvents() error {
 						level,
 						object,
 						map[string]interface{}{
-						"Type": msg.Type,
-						"Action": msg.Action,
-						"Actor": msg.Actor,
-						"Status": msg.Status,
-						"From": msg.From,
-						"Scope": msg.Scope,
+						"type": msg.Type,
+						"action": msg.Action,
+						"actor": msg.Actor,
+						"status": msg.Status,
+						"from": msg.From,
+						"scope": msg.Scope,
 					})
 			}
 		}

+ 15 - 0
src/metrics/alerts.go

@@ -101,6 +101,21 @@ func ExecuteAllActions(alert utils.Alert, actions []utils.AlertAction, metric ut
 func ExecuteAction(alert utils.Alert, action utils.AlertAction, metric utils.AlertMetricTrack) {
 	utils.Log("Executing action " + action.Type + " on " + metric.Key + " " + metric.Object	)
 
+	
+	utils.TriggerEvent(
+		"cosmos.metrics.alert",
+		"Alert triggered",
+		alert.Severity,
+		"",
+		map[string]interface{}{
+			"alert": alert.Name,
+			"metric": metric.Key,
+			"object": metric.Object,
+			"action": action.Type,
+			"severity": alert.Severity,
+			"actions": alert.Actions,
+	})
+
 	if action.Type == "email" {
 		utils.Debug("Sending email to " + action.Target)
 

+ 15 - 13
src/proxy/shield.go

@@ -332,12 +332,13 @@ func SmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func(h
 					level,
 					"route@" + route.Name,
 					map[string]interface{}{
-					"Route": route.Name,
-					"Status": wrapper.Status,
-					"Method": wrapper.Method,
-					"ClientID": wrapper.ClientID,
-					"Time": wrapper.TimeEnded.Sub(wrapper.TimeStarted).Seconds(),
-					"Bytes": wrapper.Bytes,
+					"route": route.Name,
+					"status": wrapper.Status,
+					"method": wrapper.Method,
+					"clientID": wrapper.ClientID,
+					"time": wrapper.TimeEnded.Sub(wrapper.TimeStarted).Seconds(),
+					"bytes": wrapper.Bytes,
+					"url": r.URL,
 				})
 
 				go metrics.PushRequestMetrics(route, wrapper.Status, wrapper.TimeStarted, wrapper.Bytes)
@@ -428,19 +429,20 @@ func SmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func(h
 						statusText = "error"
 						level = "warning"
 					}
-					
+
 					utils.TriggerEvent(
 						"cosmos.proxy.response." + route.Name + "." + statusText,
 						"Proxy Response " + route.Name + " " + statusText,
 						level,
 						"route@" + route.Name,
 						map[string]interface{}{
-						"Route": route.Name,
-						"Status": wrapper.Status,
-						"Method": wrapper.Method,
-						"ClientID": wrapper.ClientID,
-						"Time": wrapper.TimeEnded.Sub(wrapper.TimeStarted).Seconds(),
-						"Bytes": wrapper.Bytes,
+						"route": route.Name,
+						"status": wrapper.Status,
+						"method": wrapper.Method,
+						"clientID": wrapper.ClientID,
+						"time": wrapper.TimeEnded.Sub(wrapper.TimeStarted).Seconds(),
+						"bytes": wrapper.Bytes,
+						"url": r.URL,
 					})
 
 					go metrics.PushRequestMetrics(route, wrapper.Status, wrapper.TimeStarted, wrapper.Bytes)