Skip to content

Commit ea9d3b9

Browse files
committed
Add cluster name
1 parent 4fb255b commit ea9d3b9

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

example-deployment.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@ spec:
1616
imagePullPolicy: Always
1717
name: k8s-events-streamer
1818
env:
19-
# - name: K8S_EVENTS_STREAMER_INCOMING_WEB_HOOK_URL
20-
# value: PUT-WEB-HOOK-URL-HERE
19+
- name: K8S_EVENTS_STREAMER_CLUSTER_NAME
20+
value: my-cluster
21+
- name: K8S_EVENTS_STREAMER_INCOMING_WEB_HOOK_URL
22+
value: PUT-WEB-HOOK-URL-HERE
2123
- name: K8S_EVENTS_STREAMER_AWS_REGION
2224
value: 'us-east-1'
2325
- name: K8S_EVENTS_STREAMER_CW_LOG_GROUP
2426
value: PUT-CW-LOG-GROUP-NAME-HERE
2527
- name: K8S_EVENTS_STREAMER_NAMESPACE
2628
value: 'default'
27-
# - name: K8S_EVENTS_STREAMER_DEBUG
28-
# value: 'true'
29+
- name: K8S_EVENTS_STREAMER_DEBUG
30+
value: 'true'
2931
- name: K8S_EVENTS_STREAMER_SKIP_DELETE_EVENTS
3032
value: 'True'
31-
# It is imporatnt that you use <> around user names
32-
# https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
33-
# - name: K8S_EVENTS_STREAMER_USERS_TO_NOTIFY
34-
# value: '<@andrey9kin>'
35-
# - name: K8S_EVENTS_STREAMER_LIST_OF_REASONS_TO_SKIP
36-
# value: 'Scheduled ScalingReplicaSet Pulling Pulled Created Started Killing SuccessfulMountVolume SuccessfulUnMountVolume'
33+
# It is imporatnt that you use <> around user names
34+
# https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
35+
- name: K8S_EVENTS_STREAMER_USERS_TO_NOTIFY
36+
value: '<@andrey9kin>'
37+
- name: K8S_EVENTS_STREAMER_LIST_OF_REASONS_TO_SKIP
38+
value: 'Scheduled ScalingReplicaSet Pulling Pulled Created Started Killing SuccessfulMountVolume SuccessfulUnMountVolume'
3739
- name: K8S_EVENTS_STREAMER_LIST_OF_REASONS_TO_INCLUDE
3840
value: 'SuccessfulRescale'

k8s-events-streamer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ def is_reason_in_include_list(event, include_list):
4343
return True if event['object'].reason in include_list else False
4444

4545

46-
def format_k8s_event_to_slack_message(event_object, notify=''):
46+
def format_k8s_event_to_slack_message(event_object, cluster_name, notify=''):
4747
event = event_object['object']
4848
message = {
4949
'attachments': [{
5050
'color': '#36a64f',
51-
'title': event.message,
51+
'title': '[{}] {}'.format(cluster_name, event.message),
5252
'text': 'event type: {}, event reason: {}'.format(event_object['type'], event.reason),
5353
'footer': 'First time seen: {}, Last time seen: {}, Count: {}'.format(event.first_timestamp.strftime('%d/%m/%Y %H:%M:%S %Z'),
5454
event.last_timestamp.strftime(
@@ -90,6 +90,8 @@ def main():
9090
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
9191

9292
logger.info("Reading configuration...")
93+
k8s_cluster_name = read_env_variable_or_die(
94+
'K8S_EVENTS_STREAMER_CLUSTER_NAME')
9395
aws_region = os.environ.get('K8S_EVENTS_STREAMER_AWS_REGION', 'us-east-1')
9496
k8s_namespace_name = os.environ.get(
9597
'K8S_EVENTS_STREAMER_NAMESPACE', 'default')
@@ -169,7 +171,7 @@ def main():
169171

170172
if slack_web_hook_url:
171173
message = format_k8s_event_to_slack_message(
172-
event, users_to_notify)
174+
event, k8s_cluster_name, users_to_notify)
173175
post_slack_message(slack_web_hook_url, message)
174176
logger.info('No more events. Wait 30 sec and check again')
175177
time.sleep(30)

0 commit comments

Comments
 (0)