Skip to content

Commit

Permalink
Release v1.9.3 - Several bugfixes, update frontend. (#429)
Browse files Browse the repository at this point in the history
* Release v1.9.3 - Several bugfixes, update frontend.

* Stock config.yaml
  • Loading branch information
echoboomer committed Jan 15, 2024
1 parent 099ccef commit cf8b64b
Show file tree
Hide file tree
Showing 12 changed files with 1,701 additions and 1,653 deletions.
6 changes: 2 additions & 4 deletions backend/bot/incident/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,7 @@ async def handle_incident_optional_features(
"""
If this is an internal incident, parse additional values
"""
if internal and config.active.options.get("create_from_reaction").get(
"enabled"
):
if internal and config.active.options.get("create_from_reaction"):
original_channel = request_parameters.channel
original_message_timestamp = (
request_parameters.original_message_timestamp
Expand All @@ -553,7 +551,7 @@ async def handle_incident_optional_features(
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Here is a link to the original message: <{link_to_message}>",
"text": f"Here is a link to the original message: <{link_to_message}>\nThe reaction was added by <@{request_parameters.user}>.",
},
},
],
Expand Down
105 changes: 55 additions & 50 deletions backend/bot/slack/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,45 +373,51 @@ def handle_incident_set_severity(ack, body):

@app.event("reaction_added")
def reaction_added(event, say):
emoji = event["reaction"]
channel_id = event["item"]["channel"]
ts = event["item"]["ts"]
# Automatically create incident based on reaction with specific emoji
if emoji == config.active.options.get("create_from_reaction").get(
"reacji"
) and config.active.options.get("create_from_reaction").get("enabled"):
# Retrieve the content of the message that was reacted to
try:
result = slack_web_client.conversations_history(
channel=channel_id, inclusive=True, oldest=ts, limit=1
)
message = result["messages"][0]
message_reacted_to_content = message["text"]
except Exception as error:
logger.error(f"Error when trying to retrieve a message: {error}")
# Create request parameters object
try:
request_parameters = incident.RequestParameters(
channel=channel_id,
incident_description=f"auto-{tools.random_suffix}",
user="internal_auto_create",
severity="sev4",
message_reacted_to_content=message_reacted_to_content,
original_message_timestamp=ts,
is_security_incident=False,
private_channel=False,
)
except ConfigurationError as error:
logger.error(error)
# Create an incident based on the message using the internal path
try:
incident.create_incident(
internal=True, request_parameters=request_parameters
)
except Exception as error:
logger.error(f"Error when trying to create an incident: {error}")
reacji = event.get("reaction")
channel_id = event.get("item").get("channel")
ts = event.get("item").get("ts")

# Automatically create incident based on reaction with specific reacji if enabled
if config.active.options.get("create_from_reaction"):
if reacji == config.active.options.get("create_from_reaction"):
# Retrieve the content of the message that was reacted to
try:
result = slack_web_client.conversations_history(
channel=channel_id, inclusive=True, oldest=ts, limit=1
)
message = result["messages"][0]
message_reacted_to_content = message["text"]
except Exception as error:
logger.error(
f"Error when trying to retrieve a message: {error}"
)

# Create request parameters object
try:
request_parameters = incident.RequestParameters(
channel=channel_id,
incident_description=f"auto-{tools.random_suffix}",
user=event.get("user"),
severity="sev4",
message_reacted_to_content=message_reacted_to_content,
original_message_timestamp=ts,
is_security_incident=False,
private_channel=False,
)
except ConfigurationError as error:
logger.error(error)

# Create an incident based on the message using the internal path
try:
incident.create_incident(
internal=True, request_parameters=request_parameters
)
except Exception as error:
logger.error(
f"Error when trying to create an incident: {error}"
)
# Pinned content for incidents
if emoji == "pushpin":
if reacji == "pushpin":
channel_info = slack_web_client.conversations_info(channel=channel_id)

prefix = config.default_incident_channel_name_prefix
Expand Down Expand Up @@ -476,18 +482,6 @@ def reaction_added(event, say):
channel=channel_id,
text=f":wave: Hey there! It looks like that's not an image. I can currently only attach images.",
)
else:
write_content(
incident_id=channel_info["channel"]["name"],
content=message["text"],
ts=tools.fetch_timestamp(short=True),
user=get_user_name(user_id=message["user"]),
)
except Exception as error:
logger.error(
f"Error when trying to retrieve a message: {error}"
)
finally:
try:
slack_web_client.reactions_add(
channel=channel_id,
Expand All @@ -505,6 +499,17 @@ def reaction_added(event, say):
channel=channel_id,
text=f":wave: Hey there! I was unable to pin that message. {reason}",
)
else:
write_content(
incident_id=channel_info["channel"]["name"],
content=message["text"],
ts=tools.fetch_timestamp(short=True),
user=get_user_name(user_id=message["user"]),
)
except Exception as error:
logger.error(
f"Error when trying to retrieve a message: {error}"
)


"""
Expand Down
2 changes: 1 addition & 1 deletion backend/bot/templates/incident/digest_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def update(
"type": "button",
"text": {
"type": "plain_text",
"text": "Postmortem",
"text": "🩺 Postmortem",
},
"style": "danger",
"url": postmortem_link,
Expand Down
44 changes: 21 additions & 23 deletions backend/bot/templates/incident/resolution_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,29 @@ def create(channel: str):
]
)

blocks = (
[
{"type": "divider"},
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":white_check_mark: Incident Resolved",
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This incident has been marked as resolved.",
},
blocks = [
{"type": "divider"},
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":white_check_mark: Incident Resolved",
},
{
"block_id": "resolution_buttons",
"type": "actions",
"elements": button_el,
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This incident has been marked as resolved.",
},
{"type": "divider"},
],
)
},
{
"block_id": "resolution_buttons",
"type": "actions",
"elements": button_el,
},
{"type": "divider"},
]

return {
"channel": channel,
Expand Down
24 changes: 4 additions & 20 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from iblog import logger, log_level
from typing import Dict, List

__version__ = "v1.9.1"
__version__ = "v1.9.3"

# .env parse
dotenv_path = os.path.join(os.path.dirname(__file__), ".env")
Expand Down Expand Up @@ -183,19 +183,8 @@ def validate(self):
},
"create_from_reaction": {
"required": False,
"type": "dict",
"schema": {
"enabled": {
"required": True,
"type": "boolean",
"empty": False,
},
"reacji": {
"required": True,
"type": "string",
"empty": False,
},
},
"type": "string",
"empty": False,
},
"show_most_recent_incidents_app_home_limit": {
"required": False,
Expand Down Expand Up @@ -514,12 +503,7 @@ def env_check(required_envs: List[str]):
if os.getenv(e) == "":
logger.fatal(f"The environment variable {e} cannot be empty.")
sys.exit(1)
if active.options.get("create_from_reaction"):
if active.options.get("create_from_reaction").get("reacji") is None:
logger.fatal(
f"If enabling auto create via react, the reacji field in config.yaml should be set."
)
sys.exit(1)

# Integrations checks
if "atlassian" in active.integrations:
if "confluence" in active.integrations.get("atlassian"):
Expand Down
9 changes: 3 additions & 6 deletions backend/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ options:
# If not using Zoom auto-create
conference_bridge_link: 'https://zoom.us'
# Allow creation of an incident by reacting to a message
create_from_reaction:
# Set to true to enable
enabled: false
# The name of the reacji
# It must exist in your workspace
reacji: create-incident
# The value is the name of the reacji that will trigger the action
# It must exist in your workspace
# create_from_reaction: create-incident
# Ignore logging for requests from the following user-agents
skip_logs_for_user_agent:
# Kubernetes health check user-agent
Expand Down
4 changes: 2 additions & 2 deletions deploy/charts/incident-bot/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.9.1
version: 1.9.3

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: '1.9.1'
appVersion: '1.9.3'
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bases:

images:
- name: eb129/incident-bot
newTag: v1.9.1
newTag: v1.9.3

configMapGenerator:
- name: incident-bot-config
Expand Down
19 changes: 13 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,9 @@ options:
# If not using Zoom auto-create
conference_bridge_link: 'https://zoom.us'
# Allow creation of an incident by reacting to a message
create_from_reaction:
# Set to true to enable
enabled: false
# The name of the reacji
# It must exist in your workspace
reacji: create-incident
# The value is the name of the reacji that will trigger the action
# It must exist in your workspace
create_from_reaction: create-incident
# Ignore logging for requests from the following user-agents
skip_logs_for_user_agent:
# Kubernetes health check user-agent
Expand Down Expand Up @@ -272,3 +269,13 @@ jobs:
```

This would disable sending updates for incidents that have a status set to `some-custom status`.

### Creating Via Reactions

It is possible to create an incident by reacting to a Slack message with the reacji specified by the `create_from_reaction` field of the `options` section in `config.yaml`.

By setting this field and then reacting using the reacji, an incident will be created and the message that was reacted to will be automatically quoted in the incident channel.

!!! warning

If you wish to monitor for these reactions, the bot must be present in channels where the reaction will be applied.
2 changes: 1 addition & 1 deletion docs/deploy/overlays/production/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bases:

images:
- name: eb129/incident-bot-docs
newTag: v1.9.1
newTag: v1.9.3

generatorOptions:
disableNameSuffixHash: true
Loading

0 comments on commit cf8b64b

Please sign in to comment.