예제 #1
0
파일: models.py 프로젝트: Stupeflix/japper
    def send_alert(self, prev_state, new_state, user=None, debug_timestamp=''):
        if user is None or not user.email.strip():
            return

        context = Context({
            'prev_state': prev_state,
            'new_state': new_state,
            'state_url': build_absolute_uri(new_state.get_absolute_url()),
            'debug_timestamp': debug_timestamp,
        })
        subject_template = get_template('django_email/subject.txt')
        subject = subject_template.render(context).strip()
        body_template = get_template('django_email/body.txt')
        body = body_template.render(context)
        send_mail(subject, body, settings.FROM_EMAIL, [user.email])
예제 #2
0
    def send_alert(self, prev_state, new_state, user=None, debug_timestamp=''):
        if user is None or not user.email.strip():
            return

        context = Context({
            'prev_state':
            prev_state,
            'new_state':
            new_state,
            'state_url':
            build_absolute_uri(new_state.get_absolute_url()),
            'debug_timestamp':
            debug_timestamp,
        })
        subject_template = get_template('django_email/subject.txt')
        subject = subject_template.render(context).strip()
        body_template = get_template('django_email/body.txt')
        body = body_template.render(context)
        send_mail(subject, body, settings.FROM_EMAIL, [user.email])
예제 #3
0
파일: models.py 프로젝트: Stupeflix/japper
    def send_alert(self, prev_state, new_state, user=None, debug_timestamp=''):
        # Send to global channel or user
        if (user is not None
                and user.profile.slack_nickname is not None
                and user.profile.slack_nickname.strip()):
            channel = '@%s' % user.profile.slack_nickname
        elif self.channel is not None and self.channel.strip():
            channel = '#%s' % self.channel
        else:
            channel = None

        icon_url = build_absolute_uri(
            staticfiles_storage.url('img/Puppy-Bones.png')
        )

        if new_state.status == Status.passing:
            color = '#36A64F'
        elif new_state.status == Status.warning:
            color = '#DAA038'
        elif new_state.status == Status.critical:
            color = '#D00000'
        else:
            color = None

        if new_state.status.is_problem():
            text_prefix = '*PROBLEM*'
        else:
            text_prefix = '*RECOVERY*'
        state_link = format_slack_link(
            build_absolute_uri(new_state.get_absolute_url()),
            new_state.full_path()
        )
        text = '%s - %s is *%s* %s' % (text_prefix,
                                       state_link,
                                       new_state.status.name.upper(),
                                       debug_timestamp)

        if prev_state:
            attachment_title = 'State changed from %s to %s' % (
                prev_state.status.name.upper(),
                new_state.status.name.upper()
            )
        else:
            attachment_title = None

        source = format_slack_link(
            build_absolute_uri(build_search_url(source=new_state.source)),
            new_state.source
        )
        if new_state.host:
            host = format_slack_link(
                build_absolute_uri(build_search_url(host=new_state.host)),
                new_state.host
            )
        else:
            host = ''
        name = format_slack_link(
            build_absolute_uri(build_search_url(name=new_state.name)),
            new_state.name
        )

        if new_state.output:
            attachment_text = 'Output: %s' % new_state.output
        else:
            attachment_text = ''
        attachment_text += '''
Source: {source}
Host: {host}
Name: {name}'''.format(source=source, host=host, name=name)

        self.client.post_message(
            text,
            channel=channel,
            icon_url=icon_url,
            attachment_color=color,
            attachment_title=attachment_title,
            attachment_text=attachment_text
        )
예제 #4
0
    def send_alert(self, prev_state, new_state, user=None, debug_timestamp=''):
        # Send to global channel or user
        if (user is not None and user.profile.slack_nickname is not None
                and user.profile.slack_nickname.strip()):
            channel = '@%s' % user.profile.slack_nickname
        elif self.channel is not None and self.channel.strip():
            channel = '#%s' % self.channel
        else:
            channel = None

        icon_url = build_absolute_uri(
            staticfiles_storage.url('img/Puppy-Bones.png'))

        if new_state.status == Status.passing:
            color = '#36A64F'
        elif new_state.status == Status.warning:
            color = '#DAA038'
        elif new_state.status == Status.critical:
            color = '#D00000'
        else:
            color = None

        if new_state.status.is_problem():
            text_prefix = '*PROBLEM*'
        else:
            text_prefix = '*RECOVERY*'
        state_link = format_slack_link(
            build_absolute_uri(new_state.get_absolute_url()),
            new_state.full_path())
        text = '%s - %s is *%s* %s' % (text_prefix, state_link,
                                       new_state.status.name.upper(),
                                       debug_timestamp)

        if prev_state:
            attachment_title = 'State changed from %s to %s' % (
                prev_state.status.name.upper(), new_state.status.name.upper())
        else:
            attachment_title = None

        source = format_slack_link(
            build_absolute_uri(build_search_url(source=new_state.source)),
            new_state.source)
        if new_state.host:
            host = format_slack_link(
                build_absolute_uri(build_search_url(host=new_state.host)),
                new_state.host)
        else:
            host = ''
        name = format_slack_link(
            build_absolute_uri(build_search_url(name=new_state.name)),
            new_state.name)

        if new_state.output:
            attachment_text = 'Output: %s' % new_state.output
        else:
            attachment_text = ''
        attachment_text += '''
Source: {source}
Host: {host}
Name: {name}'''.format(source=source, host=host, name=name)

        self.client.post_message(text,
                                 channel=channel,
                                 icon_url=icon_url,
                                 attachment_color=color,
                                 attachment_title=attachment_title,
                                 attachment_text=attachment_text)