Beispiel #1
0
async def notify(
    data,
    notification_type=NOTIFICATION_SUCCESS,
    username=None,
    overwrite_url=False,
    channel=None,
):
    if notification_type == NOTIFICATION_ERROR:
        to_send = helpers.error(data)
    elif notification_type == NOTIFICATION_SUCCESS:
        to_send = helpers.success(data)
    elif notification_type == NOTIFICATION_HELP:
        to_send = helpers.info(data)
    elif notification_type == NOTIFICATION_RAW:
        to_send = data
    else:
        raise UnknownNotificationType
    if username:
        to_send["username"] = username
    url = None
    if overwrite_url is not False:
        url = overwrite_url
    else:
        webhook_url_parameter = await ParameterModel.retrieve("webhook_url")
        if webhook_url_parameter:
            url = webhook_url_parameter.value
    if not url:
        logging.warning(
            "Unconfigure webhook, please add a slash command and use `/tromino config setup `WEBHOOK URL`"
        )
        return
    if channel:
        to_send = {**to_send, "channel": channel}
    tries = 0
    while tries < 5:
        try:
            async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(
                    total=10)) as session:
                async with session.post(url, json=to_send) as resp:
                    if resp.status != 200:  # pragma: no cover
                        logging.warning(
                            f"Notification sent, but response status code is {resp.status}"
                        )
                    return
        except aiohttp.ClientError as e:
            tries += 1
    raise e
Beispiel #2
0
 async def handle_help(self):
     return helpers.info(
         "`/tromino monitor mon-{name} [remove] [set-channel [channel]]`")
Beispiel #3
0
 async def handle_help(self):
     return helpers.info(
         "`/tromino monitor [ types_list | create_monitor | mon-{name} ]`")
Beispiel #4
0
 async def handle_help(self):
     return helpers.info(
         "`/tromino monitor create_monitor {name} {type} {interval] [arg1=value1 arg2=value2...}`"
     )
Beispiel #5
0
 async def handle_help(self):
     return helpers.info(
         "`/tromino monitor types_list` : Give all monitors plugins installed."
     )
Beispiel #6
0
 async def handle_help(self):
     return helpers.info("`/tromino config [setup]`")
Beispiel #7
0
 async def handle_help(self):
     return helpers.info(
         "`/tromino config setup [MATTERMOST INCOMING WEBHOOK URL]`: Setup tromino for the first time"
     )
Beispiel #8
0
 async def handle_help(self):
     return helpers.info("`/tromino [status | config | monitoring]`")