mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-24 06:55:26 -07:00
Add mailgun notification agent
This commit is contained in:
parent
d019efcf91
commit
e410621164
1 changed files with 167 additions and 1 deletions
|
@ -109,7 +109,8 @@ AGENT_IDS = {'growl': 0,
|
||||||
'plexmobileapp': 26,
|
'plexmobileapp': 26,
|
||||||
'lunasea': 27,
|
'lunasea': 27,
|
||||||
'microsoftteams': 28,
|
'microsoftteams': 28,
|
||||||
'gotify': 29
|
'gotify': 29,
|
||||||
|
'mailgun': 30
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_CUSTOM_CONDITIONS = [{'parameter': '', 'operator': '', 'value': [], 'type': None}]
|
DEFAULT_CUSTOM_CONDITIONS = [{'parameter': '', 'operator': '', 'value': [], 'type': None}]
|
||||||
|
@ -199,6 +200,12 @@ def available_notification_agents():
|
||||||
'class': LUNASEA,
|
'class': LUNASEA,
|
||||||
'action_types': ('all',)
|
'action_types': ('all',)
|
||||||
},
|
},
|
||||||
|
{'label': 'Mailgun',
|
||||||
|
'name': 'mailgun',
|
||||||
|
'id': AGENT_IDS['mailgun'],
|
||||||
|
'class': MAILGUN,
|
||||||
|
'action_types': ('all',)
|
||||||
|
},
|
||||||
{'label': 'Microsoft Teams',
|
{'label': 'Microsoft Teams',
|
||||||
'name': 'microsoftteams',
|
'name': 'microsoftteams',
|
||||||
'id': AGENT_IDS['microsoftteams'],
|
'id': AGENT_IDS['microsoftteams'],
|
||||||
|
@ -2187,6 +2194,165 @@ class JOIN(Notifier):
|
||||||
return config_option
|
return config_option
|
||||||
|
|
||||||
|
|
||||||
|
class MAILGUN(Notifier):
|
||||||
|
"""
|
||||||
|
Mailgun email notifications
|
||||||
|
"""
|
||||||
|
NAME = 'Email'
|
||||||
|
_DEFAULT_CONFIG = {'from_name': 'Tautulli',
|
||||||
|
'from': '',
|
||||||
|
'domain': '',
|
||||||
|
'mailing_list_address': '',
|
||||||
|
'bcc_recipients': 1,
|
||||||
|
'api_key': '',
|
||||||
|
'tags': '',
|
||||||
|
'tracking': 0,
|
||||||
|
'tracking_clicks': 0,
|
||||||
|
'tracking_opens': 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
def agent_notify(self, subject='', body='', action='', **kwargs):
|
||||||
|
if not self.config['api_key']:
|
||||||
|
logger.error("Tautulli Notifiers :: %s notification failed: %s",
|
||||||
|
self.NAME, "Missing API key")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self.config['from']:
|
||||||
|
logger.error("Tautulli Notifiers :: %s notification failed: %s",
|
||||||
|
self.NAME, "Missing sender email address")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self.config['domain']:
|
||||||
|
logger.error("Tautulli Notifiers :: %s notification failed: %s",
|
||||||
|
self.NAME, "Missing domain")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self.config['mailing_list_address']:
|
||||||
|
logger.error("Tautulli Notifiers :: %s notification failed: %s",
|
||||||
|
self.NAME, "Missing recipient email address")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Get emails addresses from Mailgun API
|
||||||
|
try:
|
||||||
|
r = requests.get('https://api.mailgun.net/v3/lists/{}/members'.format(self.config['mailing_list_address']),
|
||||||
|
auth=('api', self.config['api_key']),
|
||||||
|
params={'limit': 100})
|
||||||
|
|
||||||
|
if r.status_code == 200:
|
||||||
|
response_data = r.json()
|
||||||
|
if response_data.get('items'):
|
||||||
|
email_addresses = [item['address'] for item in response_data['items']]
|
||||||
|
|
||||||
|
data = {'from': '{} <{}>'.format(self.config['from_name'], self.config['from']),
|
||||||
|
'subject': subject,
|
||||||
|
'html': body}
|
||||||
|
|
||||||
|
if self.config['bcc_recipients']:
|
||||||
|
data['bcc'] = email_addresses
|
||||||
|
data['to'] = self.config['from']
|
||||||
|
else:
|
||||||
|
data['to'] = email_addresses
|
||||||
|
|
||||||
|
if self.config['tags'] and len(self.config['tags']) > 0:
|
||||||
|
data['o:tag'] = self.config['tags']
|
||||||
|
|
||||||
|
if self.config['tracking']:
|
||||||
|
data['o:tracking'] = 'yes'
|
||||||
|
|
||||||
|
if self.config['tracking_clicks']:
|
||||||
|
data['o:tracking-clicks'] = 'yes'
|
||||||
|
|
||||||
|
if self.config['tracking_opens']:
|
||||||
|
data['o:tracking-opens'] = 'yes'
|
||||||
|
|
||||||
|
r = requests.post('https://api.mailgun.net/v3/{}/messages'.format(self.config['domain']),
|
||||||
|
auth=('api', self.config['api_key']),
|
||||||
|
data=data)
|
||||||
|
|
||||||
|
if r.status_code == 200:
|
||||||
|
logger.info("Tautulli Notifiers :: {name} notification sent.".format(name=self.NAME))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logger.error("Tautulli Notifiers :: {name} notification failed: [{r.status_code}] {r.reason}".format(name=self.NAME, r=r))
|
||||||
|
logger.debug("Tautulli Notifiers :: Request response: {}".format(request.server_message(r, True)))
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
logger.error("Tautulli Notifiers :: Unable to retrieve {name} email addresses: {msg}".format(name=self.NAME, msg=response_data.get('message', '')))
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
logger.error("Tautulli Notifiers :: Unable to retrieve {name} email addresses: [{r.status_code}] {r.reason}".format(name=self.NAME, r=r))
|
||||||
|
logger.debug("Tautulli Notifiers :: Request response: {}".format(request.server_message(r, True)))
|
||||||
|
return False
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
logger.error("Tautulli Notifiers :: Unable to retrieve {name} email addresses: {msg}".format(name=self.NAME, msg=e))
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _return_config_options(self):
|
||||||
|
config_option = [{'label': 'From Name',
|
||||||
|
'value': self.config['from_name'],
|
||||||
|
'name': 'mailgun_from_name',
|
||||||
|
'description': 'The name of the sender.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'From',
|
||||||
|
'value': self.config['from'],
|
||||||
|
'name': 'mailgun_from',
|
||||||
|
'description': 'The email address of the sender.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'Domain',
|
||||||
|
'value': self.config['domain'],
|
||||||
|
'name': 'mailgun_domain',
|
||||||
|
'description': 'The domain to send from.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'Mailing List Address',
|
||||||
|
'value': self.config['mailing_list_address'],
|
||||||
|
'name': 'mailgun_mailing_list_address',
|
||||||
|
'description': 'The email address of the mailing list on Mailgun.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'BCC Recipients',
|
||||||
|
'value': self.config['bcc_recipients'],
|
||||||
|
'name': 'mailgun_bcc_recipients',
|
||||||
|
'description': 'Add users to Bcc instead of To.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
|
},
|
||||||
|
{'label': 'API Key',
|
||||||
|
'value': self.config['api_key'],
|
||||||
|
'name': 'mailgun_api_key',
|
||||||
|
'description': 'API key for Mailgun.',
|
||||||
|
'input_type': 'password'
|
||||||
|
},
|
||||||
|
{'label': 'Tags',
|
||||||
|
'value': self.config['tags'],
|
||||||
|
'name': 'mailgun_tags',
|
||||||
|
'description': 'Comma separated list of tags.',
|
||||||
|
'input_type': 'text'
|
||||||
|
},
|
||||||
|
{'label': 'Tracking',
|
||||||
|
'value': self.config['tracking'],
|
||||||
|
'name': 'mailgun_tracking',
|
||||||
|
'description': 'Enable tracking.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
|
},
|
||||||
|
{'label': 'Tracking Clicks',
|
||||||
|
'value': self.config['tracking_clicks'],
|
||||||
|
'name': 'mailgun_tracking_clicks',
|
||||||
|
'description': 'Enable click tracking.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
|
},
|
||||||
|
{'label': 'Tracking Opens',
|
||||||
|
'value': self.config['tracking_opens'],
|
||||||
|
'name': 'mailgun_tracking_opens',
|
||||||
|
'description': 'Enable open tracking.',
|
||||||
|
'input_type': 'checkbox'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return config_option
|
||||||
|
|
||||||
|
|
||||||
class LUNASEA(Notifier):
|
class LUNASEA(Notifier):
|
||||||
"""
|
"""
|
||||||
LunaSea Notifications
|
LunaSea Notifications
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue