diff --git a/Dockerfile b/Dockerfile index a9ce08f9..5b3b74b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.14 AS builder ADD . /app WORKDIR /app -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO11MODULE=on go build -mod=vendor -v -a -o /main . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO11MODULE=on go build -mod=vendor -a -o /main . FROM gcr.io/distroless/base COPY --from=builder /main /kubernetes-event-exporter diff --git a/README.md b/README.md index 0089018e..35eeba2e 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ SQS is an AWS service for message queuing that allows high throughput messaging. ```yaml # ... receivers: - - name: "file" + - name: "sqs" sqs: queueName: "/tmp/dump" region: us-west-2 diff --git a/config.example.yaml b/config.example.yaml new file mode 100644 index 00000000..56deaf54 --- /dev/null +++ b/config.example.yaml @@ -0,0 +1,87 @@ +logLevel: debug +logFormat: json +route: + # Main route + routes: + # This route allows dumping all events because it has no fields to match and no drop rules. + - match: + - receiver: "dump" + # This starts another route, drops all the events in *test* namespaces and Normal events + # for capturing critical events + - drop: + - namespace: "*test*" + - type: "Normal" + match: + - receiver: "alert" + - receiver: "pipe" + # This a final route for user messages + - match: + - kind: "Pod|Deployment|ReplicaSet" + labels: + version: "dev" + receiver: "slack" +receivers: + - name: "dump" + elasticsearch: + hosts: + - "http://localhost:9200" + indexFormat: "kube-events-{2006-01-02}" + - name: "alert" + opsgenie: + apiKey: "" + priority: "P3" + message: "Event {{ .Reason }} for {{ .InvolvedObject.Namespace }}/{{ .InvolvedObject.Name }} on K8s cluster" + alias: "{{ .UID }}" + description: "
{{ toPrettyJson . }}" + tags: + - "event" + - "{{ .Reason }}" + - "{{ .InvolvedObject.Kind }}" + - "{{ .InvolvedObject.Name }}" + - name: "slack" + slack: + token: "" + channel: "#mustafa-test" + message: "Received a Kubernetes Event {{ .Message}}" + fields: + message: "{{ .Message }}" + namespace: "{{ .Namespace }}" + reason: "{{ .Reason }}" + object: "{{ .Namespace }}" + - name: "pipe" + webhook: + endpoint: "http://localhost:3000" + headers: + X-API-KEY: "123-456-OPSGENIE-789-ABC" + User-Agent: "kube-event-exporter 1.0" + streamName: "applicationMetric" + layout: + endpoint: "localhost2" + eventType: "kube-event" + createdAt: "{{ .GetTimestampMs }}" + details: + message: "{{ .Message }}" + reason: "{{ .Reason }}" + tip: "{{ .Type }}" + count: "{{ .Count }}" + kind: "{{ .InvolvedObject.Kind }}" + name: "{{ .InvolvedObject.Name }}" + namespace: "{{ .Namespace }}" + component: "{{ .Source.Component }}" + host: "{{ .Source.Host }}" + labels: "{{ toJson .InvolvedObject.Labels}}" + - name: "kafka" + kafka: + topic: "kube-event" + brokers: + - "localhost:9092" + tls: + enable: false + certFile: "kafka-client.crt" + keyFile: "kafka-client.key" + caFile: "kafka-ca.crt" + - name: "pubsub" + pubsub: + gcloud_project_id: "my-project" + topic: "kube-event" + create_topic: False \ No newline at end of file diff --git a/config.yaml b/config.yaml index 56deaf54..66d03716 100644 --- a/config.yaml +++ b/config.yaml @@ -1,87 +1,10 @@ -logLevel: debug +logLevel: error logFormat: json route: - # Main route routes: - # This route allows dumping all events because it has no fields to match and no drop rules. - match: - receiver: "dump" - # This starts another route, drops all the events in *test* namespaces and Normal events - # for capturing critical events - - drop: - - namespace: "*test*" - - type: "Normal" - match: - - receiver: "alert" - - receiver: "pipe" - # This a final route for user messages - - match: - - kind: "Pod|Deployment|ReplicaSet" - labels: - version: "dev" - receiver: "slack" receivers: - name: "dump" - elasticsearch: - hosts: - - "http://localhost:9200" - indexFormat: "kube-events-{2006-01-02}" - - name: "alert" - opsgenie: - apiKey: "" - priority: "P3" - message: "Event {{ .Reason }} for {{ .InvolvedObject.Namespace }}/{{ .InvolvedObject.Name }} on K8s cluster" - alias: "{{ .UID }}" - description: "
{{ toPrettyJson . }}" - tags: - - "event" - - "{{ .Reason }}" - - "{{ .InvolvedObject.Kind }}" - - "{{ .InvolvedObject.Name }}" - - name: "slack" - slack: - token: "" - channel: "#mustafa-test" - message: "Received a Kubernetes Event {{ .Message}}" - fields: - message: "{{ .Message }}" - namespace: "{{ .Namespace }}" - reason: "{{ .Reason }}" - object: "{{ .Namespace }}" - - name: "pipe" - webhook: - endpoint: "http://localhost:3000" - headers: - X-API-KEY: "123-456-OPSGENIE-789-ABC" - User-Agent: "kube-event-exporter 1.0" - streamName: "applicationMetric" - layout: - endpoint: "localhost2" - eventType: "kube-event" - createdAt: "{{ .GetTimestampMs }}" - details: - message: "{{ .Message }}" - reason: "{{ .Reason }}" - tip: "{{ .Type }}" - count: "{{ .Count }}" - kind: "{{ .InvolvedObject.Kind }}" - name: "{{ .InvolvedObject.Name }}" - namespace: "{{ .Namespace }}" - component: "{{ .Source.Component }}" - host: "{{ .Source.Host }}" - labels: "{{ toJson .InvolvedObject.Labels}}" - - name: "kafka" - kafka: - topic: "kube-event" - brokers: - - "localhost:9092" - tls: - enable: false - certFile: "kafka-client.crt" - keyFile: "kafka-client.key" - caFile: "kafka-ca.crt" - - name: "pubsub" - pubsub: - gcloud_project_id: "my-project" - topic: "kube-event" - create_topic: False \ No newline at end of file + file: + path: "/tmp/deneme1" \ No newline at end of file diff --git a/deploy/01-config.yaml b/deploy/01-config.yaml index 55278cbb..f936891c 100644 --- a/deploy/01-config.yaml +++ b/deploy/01-config.yaml @@ -5,12 +5,13 @@ metadata: namespace: monitoring data: config.yaml: | + logLevel: error + logFormat: json route: - match: - - receiver: "dump" + routes: + - match: + - receiver: "dump" receivers: - name: "dump" - elasticsearch: - hosts: - - http://elasticsearch.monitoring.svc.cluster.local:9200 - index: kube-events \ No newline at end of file + file: + path: "/dev/stdout" \ No newline at end of file diff --git a/deploy/02-deployment.yaml b/deploy/02-deployment.yaml index 0e354a75..ecd27d1a 100644 --- a/deploy/02-deployment.yaml +++ b/deploy/02-deployment.yaml @@ -14,7 +14,7 @@ spec: serviceAccountName: event-exporter containers: - name: event-exporter - image: opsgenie/kubernetes-event-exporter:0.7 + image: opsgenie/kubernetes-event-exporter:0.8 imagePullPolicy: IfNotPresent args: - -conf=/data/config.yaml diff --git a/pkg/kube/watcher.go b/pkg/kube/watcher.go index da4b40b3..ad3c8cea 100644 --- a/pkg/kube/watcher.go +++ b/pkg/kube/watcher.go @@ -59,6 +59,7 @@ func (e *EventWatcher) onEvent(event *corev1.Event) { Str("msg", event.Message). Str("namespace", event.Namespace). Str("reason", event.Reason). + Str("involvedObject", event.InvolvedObject.Name). Msg("Received event") ev := &EnhancedEvent{ @@ -77,7 +78,7 @@ func (e *EventWatcher) onEvent(event *corev1.Event) { annotations, err := e.annotationCache.GetAnnotationsWithCache(&event.InvolvedObject) if err != nil { log.Error().Err(err).Msg("Cannot list annotations of the object") - }else { + } else { ev.InvolvedObject.Annotations = annotations ev.InvolvedObject.ObjectReference = *event.InvolvedObject.DeepCopy() }