-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from idealista/develop
3.1.0 release
- Loading branch information
Showing
18 changed files
with
300 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Number of days of inactivity before an issue becomes stale | ||
daysUntilStale: 60 | ||
# Number of days of inactivity before a stale issue is closed | ||
daysUntilClose: 7 | ||
# Issues with these labels will never be considered stale | ||
exemptLabels: | ||
- pinned | ||
- security | ||
# Label to use when marking an issue as stale | ||
staleLabel: wontfix | ||
# Comment to post when marking an issue as stale. Set to `false` to disable | ||
markComment: > | ||
This issue has been automatically marked as stale because it has not had | ||
recent activity. It will be closed if no further activity occurs. Thank you | ||
for your contributions. | ||
# Comment to post when closing a stale issue. Set to `false` to disable | ||
closeComment: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Prom2Teams has been installed. Check its status by running: | ||
kubectl --namespace {{ .Release.Namespace }} get pods -l "release={{ .Release.Name }}" | ||
Prom2Teams has been installed. Check its status by running: | ||
kubectl --namespace {{ .Release.Namespace }} get pods -l "app.kubernetes.io/instance={{ .Release.Name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
import logging | ||
|
||
|
||
from prom2teams.teams.alarm_mapper import map_and_group, map_prom_alerts_to_teams_alarms | ||
from prom2teams.teams.composer import TemplateComposer | ||
from .teams_client import post | ||
from .teams_client import TeamsClient | ||
|
||
log = logging.getLogger('prom2teams') | ||
|
||
|
||
class AlarmSender: | ||
|
||
def __init__(self, template_path=None, group_alerts_by=False): | ||
def __init__(self, template_path=None, group_alerts_by=False, teams_client_config=None): | ||
self.json_composer = TemplateComposer(template_path) | ||
self.group_alerts_by = group_alerts_by | ||
if template_path: | ||
self.json_composer = TemplateComposer(template_path) | ||
else: | ||
self.json_composer = TemplateComposer() | ||
self.teams_client = TeamsClient(teams_client_config) | ||
self.max_payload = self.teams_client.max_payload_length | ||
|
||
def _create_alarms(self, alerts): | ||
if self.group_alerts_by: | ||
alarms = map_and_group(alerts, self.group_alerts_by) | ||
alarms = map_and_group(alerts, self.group_alerts_by, self.json_composer.compose, self.max_payload) | ||
else: | ||
alarms = map_prom_alerts_to_teams_alarms(alerts) | ||
return self.json_composer.compose_all(alarms) | ||
|
||
def send_alarms(self, alerts, teams_webhook_url): | ||
sending_alarms = self._create_alarms(alerts) | ||
for team_alarm in sending_alarms: | ||
log.debug('The message that will be sent is: %s', str(team_alarm)) | ||
post(teams_webhook_url, team_alarm) | ||
self.teams_client.post(teams_webhook_url, team_alarm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,55 @@ | ||
import json | ||
import logging | ||
import requests | ||
from tenacity import retry, wait_fixed, after_log | ||
|
||
from .exceptions import MicrosoftTeamsRequestException | ||
|
||
session = requests.Session() | ||
session.headers.update({'Content-Type': 'application/json'}) | ||
|
||
|
||
def post(teams_webhook_url, message): | ||
response = session.post(teams_webhook_url, data=message) | ||
if not response.ok or response.text is not '1': | ||
exception_msg = 'Error performing request to: {}.\n' \ | ||
' Returned status code: {}.\n' \ | ||
' Returned data: {}\n' \ | ||
' Sent message: {}\n' | ||
raise MicrosoftTeamsRequestException(exception_msg.format(teams_webhook_url, | ||
str(response.status_code), | ||
str(response.text), | ||
str(message)), | ||
code=response.status_code) | ||
log = logging.getLogger('prom2teams') | ||
|
||
|
||
class TeamsClient: | ||
DEFAULT_CONFIG = { | ||
'MAX_PAYLOAD': 24576, | ||
'RETRY_ENABLE': False, | ||
'RETRY_WAIT_TIME': 60 | ||
} | ||
|
||
def __init__(self, config=None): | ||
self.session = requests.Session() | ||
self.session.headers.update({'Content-Type': 'application/json'}) | ||
|
||
if config is None: | ||
config = {} | ||
config = {**TeamsClient.DEFAULT_CONFIG, **config} | ||
self.max_payload_length = config['MAX_PAYLOAD'] | ||
self.retry = config['RETRY_ENABLE'] | ||
self.wait_time = config['RETRY_WAIT_TIME'] | ||
|
||
def post(self, teams_webhook_url, message): | ||
@retry(wait=wait_fixed(self.wait_time), after=after_log(log, logging.WARN)) | ||
def post_with_retry(teams_webhook_url, message): | ||
self._do_post(teams_webhook_url, message) | ||
|
||
def simple_post(teams_webhook_url, message): | ||
self._do_post(teams_webhook_url, message) | ||
|
||
log.debug('The message that will be sent is: ' + message) | ||
if self.retry: | ||
post_with_retry(teams_webhook_url, message) | ||
else: | ||
simple_post(teams_webhook_url, message) | ||
|
||
def _do_post(self, teams_webhook_url, message): | ||
response = self.session.post(teams_webhook_url, data=message, timeout=(5,20)) | ||
if not response.ok or response.text != '1': | ||
exception_msg = 'Error performing request to: {}.\n' \ | ||
' Returned status code: {}.\n' \ | ||
' Returned data: {}\n' \ | ||
' Sent message: {}\n' | ||
exception_msg.format(teams_webhook_url, | ||
str(response.status_code), | ||
str(response.text), | ||
str(message)) | ||
raise MicrosoftTeamsRequestException( | ||
exception_msg, code=response.status_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.