def send_alarm()

in elkserver/docker/redelk-base/redelkinstalldata/scripts/modules/msteams/module.py [0:0]


    def send_alarm(self, alarm):
        """Send the alarm notification"""
        tmsg = pymsteams.connectorcard(config.notifications["msteams"]["webhook_url"])
        description = alarm["info"]["description"]
        if len(alarm["groupby"]) > 0:
            description += f'\n *Please note that the items below have been grouped by: {pprint(alarm["groupby"])}*'
        tmsg.text(description)
        tmsg.color("red")
        try:
            for hit in alarm["hits"]["hits"]:
                tcs = pymsteams.cardsection()
                tcs.disableMarkdown()
                i = 0
                title = hit["_id"]
                while i < len(alarm["groupby"]):
                    val = get_value(f'_source.{alarm["groupby"][i]}', hit)
                    if i == 0:
                        title = val
                    else:
                        title = f"{title} / {val}"
                    i += 1
                tcs.activityTitle(f"Alarm on item: {title}")
                # tcs.activitySubtitle(alarm['info']['description'])
                for field in alarm["fields"]:
                    val = get_value(f"_source.{field}", hit)
                    tcs.addFact(field, pprint(val))
                tmsg.addSection(tcs)
        # pylint: disable=broad-except
        except Exception as error:
            self.logger.exception(error)

        tmsg.title(
            f'[{config.project_name}] Alarm from {alarm["info"]["name"]} [{alarm["hits"]["total"]} hits]'
        )
        tmsg.send()