Skip to content

Commit

Permalink
Get slack notification in sync with image-factory / orchestrator
Browse files Browse the repository at this point in the history
  • Loading branch information
sukrit007 committed Jul 20, 2016
1 parent 8a08b3b commit 9003231
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
3 changes: 3 additions & 0 deletions deployer/tasks/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Tasks for notification
"""
import json

import time
from future.builtins import ( # noqa
bytes, dict, int, list, object, range, str,
ascii, chr, hex, input, next, oct, open,
Expand Down Expand Up @@ -68,6 +70,7 @@ def notify_slack(obj, ctx, level, config, security_profile):
url = config.get('url')
notification = util.as_dict(obj)
notification['channel'] = config.get('channel')
notification['date'] = int(time.time())
msg = templatefactory.render_template(
'slack.json.jinja', notification=notification, ctx=ctx,
level=level)
Expand Down
34 changes: 18 additions & 16 deletions deployer/templates/slack.json.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
{
"username": "Deployer ({{ctx.cluster}}-{{ctx.operation}})",
"channel": "{{ notification.channel or '#totem' }}",
"text":
{% if git.type == 'github' %}
"<https://github.com/{{git.owner}}|{{git.owner or 'NA'}}> / <https://github.com/{{git.owner}}/{{git.repo}}|{{git.repo or 'NA'}}> / <https://github.com/{{git.owner}}/{{git.repo}}/{{git.ref}}|{{git.ref or 'NA'}}> / <https://github.com/{{ctx.owner}}/{{ctx.repo}}/commits/{{ctx.commit or ctx.ref}}|{{ctx.commit or ctx.ref or 'NA'}}>"
{% else %}
"{{git.owner or 'NA'}} / {{git.repo or 'NA'}} / {{git.ref or 'NA'}} / {{git.commit or 'NA'}}"
{% endif %},
"text": " ",

"attachments": [
{
"text": "{{ notification.code}}: {{ notification.message | truncate(1000) }}",
"text": "{% if notification.code %}{{ notification.code}}: {% endif %}{{ notification.message | truncate(1000) }}",
"color":
{% if level == 1 %}
"danger"
{% elif level == 2 %}
"warning"
{% elif level == 3 %}
"good"
{% else %}
"#439FE0"
{% endif %}
{% if level == 1 %}
"danger"
{% elif level == 2 %}
"warning"
{% elif level == 3 %}
"good"
{% else %}
"#439FE0"
{% endif %},
"footer":
{% if ctx.github %}
"<https://github.com/{{git.owner}}|{{git.owner or 'NA'}}> / <https://github.com/{{git.owner}}/{{git.repo}}|{{git.repo or 'NA'}}> / <https://github.com/{{git.owner}}/{{git.repo}}/tree/{{git.ref}}|{{git.ref or 'NA'}}> / <https://github.com/{{git.owner}}/{{git.repo}}/commits/{{git.commit or git.ref}}|{{(git.commit or git.ref or 'NA')[0:7]}}>\n"
{% else %}
"{{git.owner or 'NA'}}/{{git.repo or 'NA'}}/{{git.ref or 'NA'}}/{{(git.commit or 'NA')[0:7]}}"
{% endif %},
"ts": "{{ notification.date }}"
}
]

Expand Down

0 comments on commit 9003231

Please sign in to comment.