<commit_before># -*- coding: utf-8 -*-

# -- stdlib --
import json

# -- third party --
import requests

# -- own --
from backend.common import register_backend, Backend

# -- code --


@register_backend
class VictorOpsBackend(Backend):
    def send(self, user, event):
        if 'victorops' not in user:
            return

        url = user['victorops']
        routing_key = event['related_groups'][0]

        #PROBLEM OK EVENT FLAPPING TIMEWAIT ACK
        if event['status'] in ('PROBLEM', 'EVENT', 'FLAPPING'):
            msg_type = 'CRITICAL'
        elif event['status'] in ( 'OK', 'TIMEWAIT'):
            msg_type = 'RECOVERY'
        else:
            msg_type = 'ACK'
        # for leancloud only
        if event['level'] == 5:
            msg_type = 'INFO'

        resp = requests.post(
            url + '/' + routing_key,
            headers={'Content-Type': 'application/json'},
            timeout=10,
            data=json.dumps({
                'entity_id': event['title'],
                'entity_display_name': event['title'],
                'message_type': msg_type,
                'state_message': event['text'],
            }),
        )
        if not resp.ok:
            raise Exception(resp.json())
<commit_msg>victorops: FLAPPING -> INFO<commit_after># -*- coding: utf-8 -*-

# -- stdlib --
import json

# -- third party --
import requests

# -- own --
from backend.common import register_backend, Backend

# -- code --


@register_backend
class VictorOpsBackend(Backend):
    def send(self, user, event):
        if 'victorops' not in user:
            return

        url = user['victorops']
        routing_key = event['related_groups'][0]

        # status: PROBLEM OK EVENT FLAPPING TIMEWAIT ACK
        if event['status'] in ('PROBLEM', 'EVENT'):
            msg_type = 'CRITICAL'
        elif event['status'] in ( 'OK', 'TIMEWAIT'):
            msg_type = 'RECOVERY'
        elif event['status'] in ( 'ACK' ):
            msg_type = 'ACK'
        else:
            msg_type = 'INFO'

        resp = requests.post(
            url + '/' + routing_key,
            headers={'Content-Type': 'application/json'},
            timeout=10,
            data=json.dumps({
                'entity_id': event['title'],
                'entity_display_name': event['title'],
                'priority': event['level'],
                'message_type': msg_type,
                'state_message': event['text'],
            }),
        )
        if not resp.ok:
            raise Exception(resp.json())

{'fraction_non_alphanumeric': 0.139755230951441, 'fraction_numerical': 0.0035530990919857876, 'mean_word_length': 1.7724288840262583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4713900', 'n_tokens_mistral': 752, 'n_tokens_neox': 734, 'n_words': 176}