Skip to content
Snippets Groups Projects
Commit a0377a79 authored by Christian Dresen's avatar Christian Dresen
Browse files

[WarpInfra] Added Mattermost incomming Webhook

parent 3caf02ba
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ RUN pip3 install \ ...@@ -30,6 +30,7 @@ RUN pip3 install \
ldap3 \ ldap3 \
uwsgi \ uwsgi \
django-two-factor-auth \ django-two-factor-auth \
matterhook \
--upgrade --upgrade
RUN pip3 install git+https://github.com/nkunihiko/django-bootstrap3-datetimepicker.git RUN pip3 install git+https://github.com/nkunihiko/django-bootstrap3-datetimepicker.git
......
...@@ -5,6 +5,9 @@ DEBUG = true ...@@ -5,6 +5,9 @@ DEBUG = true
SECRET_KEY = '4m4c(_$ubwued9p-insp!950g&r0yu851bp287$2a3ydj^y=0=' SECRET_KEY = '4m4c(_$ubwued9p-insp!950g&r0yu851bp287$2a3ydj^y=0='
PW_RESET_TOKEN_LIFETIME = 5 PW_RESET_TOKEN_LIFETIME = 5
[mattermost]
API_KEY = bohtwe6zy7y43p5n36skph7ejy
[ldap] [ldap]
LDAP_HOST = ldap LDAP_HOST = ldap
LDAP_BIND_DN = cn=admin,dc=warpzone,dc=ms LDAP_BIND_DN = cn=admin,dc=warpzone,dc=ms
......
...@@ -3,6 +3,8 @@ from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAll ...@@ -3,6 +3,8 @@ from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAll
from django.shortcuts import redirect from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from warpfood.util import * from warpfood.util import *
from warpzone.util import send_to_mattermost
from django.utils.translation import ugettext as _
from warpfood.models import * from warpfood.models import *
from reportlab.pdfgen import canvas from reportlab.pdfgen import canvas
from django.http import HttpResponse from django.http import HttpResponse
...@@ -21,7 +23,8 @@ def index(request): ...@@ -21,7 +23,8 @@ def index(request):
if request.method == 'POST': if request.method == 'POST':
form = FoodSheetForm(request.POST) form = FoodSheetForm(request.POST)
if form.is_valid(): if form.is_valid():
form.save() sheet = form.save()
send_to_mattermost("PizzaSheet", "town-square", _("pizza_sheet_opened_for_%(est_order_time)s_at_%(pizza_service)s") % ({'est_order_time': sheet.estimated_order_time, 'pizza_service':sheet.food_service}))
time_threshold = datetime.now() - timedelta(days=1) time_threshold = datetime.now() - timedelta(days=1)
FoodSheet.objects.filter(order_time__lte=time_threshold).delete() FoodSheet.objects.filter(order_time__lte=time_threshold).delete()
......
...@@ -39,6 +39,9 @@ EMAIL_SUBJECT_PREFIX = config.get('email','SUBJECT_PREFIX') ...@@ -39,6 +39,9 @@ EMAIL_SUBJECT_PREFIX = config.get('email','SUBJECT_PREFIX')
PW_RESET_TOKEN_LIFETIME = config.get('security','PW_RESET_TOKEN_LIFETIME') PW_RESET_TOKEN_LIFETIME = config.get('security','PW_RESET_TOKEN_LIFETIME')
SECRET_KEY = config.get('security','SECRET_KEY') SECRET_KEY = config.get('security','SECRET_KEY')
# MATTERMOST
API_KEY = config.get('mattermost','API_KEY')
# DEBUG # DEBUG
DEBUG = config.getboolean('debug','DEBUG') DEBUG = config.getboolean('debug','DEBUG')
...@@ -185,6 +188,24 @@ AUTH_LDAP_FIND_GROUP_PERMS = True ...@@ -185,6 +188,24 @@ AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_CACHE_GROUPS = True AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 10 AUTH_LDAP_GROUP_CACHE_TIMEOUT = 10
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': '/opt/log/error.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'ERROR',
'propagate': True,
},
},
}
logger = logging.getLogger('django_auth_ldap') logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler()) logger.addHandler(logging.StreamHandler())
hdlr = logging.FileHandler('/tmp/ldap.log') hdlr = logging.FileHandler('/tmp/ldap.log')
......
from django.core.mail import send_mail from django.core.mail import send_mail
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from matterhook import Webhook
import logging
page_context = {'pages': [ page_context = {'pages': [
{"link": "pizza", "name": _("pizza_sheet")}, {"link": "pizza", "name": _("pizza_sheet")},
{"link": "about", "name": _("about")}, {"link": "about", "name": _("about")},
], 'debug': settings.DEBUG} ], 'debug': settings.DEBUG}
def send_to_mattermost(username, channel, message):
try:
if settings.API_KEY:
hook = Webhook("https://mattermost.warpzone.ms", settings.API_KEY)
if settings.DEBUG:
username = "["+channel+"] "+username
channel = "warpinfradebug"
hook.send(message, channel=channel, username=username)
except Exception as e:
logging.getLogger("django").error(e)
def send_email(to_address, subject, content): def send_email(to_address, subject, content):
try: try:
send_mail( send_mail(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment