Remove HipChat notification type

This commit is contained in:
beeankha 2020-05-19 09:13:21 -04:00
parent bfdd136a46
commit bc4d789da0
8 changed files with 55 additions and 140 deletions

View File

@ -0,0 +1,34 @@
# Generated by Django 2.2.11 on 2020-05-19 02:27
from django.db import migrations, models
def remove_hipchat_notifications(apps, schema_editor):
'''
HipChat notifications are no longer in service, remove any that are found.
'''
Notification = apps.get_model('main', 'Notification')
Notification.objects.filter(notification_type='hipchat').delete()
NotificationTemplate = apps.get_model('main', 'NotificationTemplate')
NotificationTemplate.objects.filter(notification_type='hipchat').delete()
class Migration(migrations.Migration):
dependencies = [
('main', '0115_v370_schedule_set_null'),
]
operations = [
migrations.RunPython(remove_hipchat_notifications),
migrations.AlterField(
model_name='notification',
name='notification_type',
field=models.CharField(choices=[('email', 'Email'), ('grafana', 'Grafana'), ('irc', 'IRC'), ('mattermost', 'Mattermost'), ('pagerduty', 'Pagerduty'), ('rocketchat', 'Rocket.Chat'), ('slack', 'Slack'), ('twilio', 'Twilio'), ('webhook', 'Webhook')], max_length=32),
),
migrations.AlterField(
model_name='notificationtemplate',
name='notification_type',
field=models.CharField(choices=[('email', 'Email'), ('grafana', 'Grafana'), ('irc', 'IRC'), ('mattermost', 'Mattermost'), ('pagerduty', 'Pagerduty'), ('rocketchat', 'Rocket.Chat'), ('slack', 'Slack'), ('twilio', 'Twilio'), ('webhook', 'Webhook')], max_length=32),
),
]

View File

@ -23,7 +23,6 @@ from awx.main.notifications.email_backend import CustomEmailBackend
from awx.main.notifications.slack_backend import SlackBackend
from awx.main.notifications.twilio_backend import TwilioBackend
from awx.main.notifications.pagerduty_backend import PagerDutyBackend
from awx.main.notifications.hipchat_backend import HipChatBackend
from awx.main.notifications.webhook_backend import WebhookBackend
from awx.main.notifications.mattermost_backend import MattermostBackend
from awx.main.notifications.grafana_backend import GrafanaBackend
@ -44,7 +43,6 @@ class NotificationTemplate(CommonModelNameNotUnique):
('twilio', _('Twilio'), TwilioBackend),
('pagerduty', _('Pagerduty'), PagerDutyBackend),
('grafana', _('Grafana'), GrafanaBackend),
('hipchat', _('HipChat'), HipChatBackend),
('webhook', _('Webhook'), WebhookBackend),
('mattermost', _('Mattermost'), MattermostBackend),
('rocketchat', _('Rocket.Chat'), RocketChatBackend),

View File

@ -1,54 +0,0 @@
# Copyright (c) 2016 Ansible, Inc.
# All Rights Reserved.
import logging
import requests
from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
from awx.main.notifications.base import AWXBaseEmailBackend
from awx.main.notifications.custom_notification_base import CustomNotificationBase
logger = logging.getLogger('awx.main.notifications.hipchat_backend')
class HipChatBackend(AWXBaseEmailBackend, CustomNotificationBase):
init_parameters = {"token": {"label": "Token", "type": "password"},
"rooms": {"label": "Destination Rooms", "type": "list"},
"color": {"label": "Notification Color", "type": "string"},
"api_url": {"label": "API Url (e.g: https://mycompany.hipchat.com)", "type": "string"},
"notify": {"label": "Notify room", "type": "bool"},
"message_from": {"label": "Label to be shown with notification", "type": "string"}}
recipient_parameter = "rooms"
sender_parameter = "message_from"
def __init__(self, token, color, api_url, notify, fail_silently=False, **kwargs):
super(HipChatBackend, self).__init__(fail_silently=fail_silently)
self.token = token
if color is not None:
self.color = color.lower()
self.api_url = api_url
self.notify = notify
def send_messages(self, messages):
sent_messages = 0
for m in messages:
for rcp in m.recipients():
r = requests.post("{}/v2/room/{}/notification".format(self.api_url, rcp),
params={"auth_token": self.token},
verify=False,
json={"color": self.color,
"message": m.subject,
"notify": self.notify,
"from": m.from_email,
"message_format": "text"})
if r.status_code != 204:
logger.error(smart_text(_("Error sending messages: {}").format(r.text)))
if not self.fail_silently:
raise Exception(smart_text(_("Error sending message to hipchat: {}").format(r.text)))
sent_messages += 1
return sent_messages

View File

@ -168,22 +168,6 @@ export default ['i18n', function(i18n) {
subForm: 'typeSubForm',
ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)'
},
rooms: {
label: i18n._('Destination Channels'),
type: 'textarea',
rows: 3,
awPopOver: i18n._('Enter one HipChat channel per line. The pound symbol (#) is not required.'),
dataTitle: i18n._('Destination Channels'),
dataPlacement: 'right',
dataContainer: "body",
awRequiredWhen: {
reqExpression: "room_required",
init: "false"
},
ngShow: "notification_type.value == 'hipchat'",
subForm: 'typeSubForm',
ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)'
},
token: {
labelBind: 'tokenLabel',
type: 'sensitive',
@ -344,18 +328,6 @@ export default ['i18n', function(i18n) {
subForm: 'typeSubForm',
ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)'
},
api_url: {
label: i18n._('API URL'),
type: 'text',
placeholder: 'https://mycompany.hipchat.com',
awRequiredWhen: {
reqExpression: "hipchat_required",
init: "false"
},
ngShow: "notification_type.value == 'hipchat' ",
subForm: 'typeSubForm',
ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)'
},
message_from: {
label: i18n._('Notification Label'),
type: 'text',

View File

@ -81,6 +81,7 @@ The following notes are changes that may require changes to playbooks:
- `tower_job_template` no longer supports the deprecated `extra_vars_path` parameter, please use `extra_vars` with the lookup plugin to replace this functionality.
- The `notification_configuration` parameter of `tower_notification` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict.
- `tower_credential` no longer supports passing a file name to ssh_key_data.
- The HipChat notification type has been removed and can no longer be created using the `tower_notification` module.
## Running Unit Tests

View File

@ -46,7 +46,6 @@ options:
choices:
- 'email'
- 'grafana'
- 'hipchat'
- 'irc'
- 'mattermost'
- 'pagerduty'
@ -159,7 +158,7 @@ options:
api_url:
description:
- The HipChat API URL.
- This parameter has been deprecated, please use 'notification_configuration' instead.
- The HipChat notification type has been deprecated.
type: str
color:
description:
@ -170,7 +169,7 @@ options:
rooms:
description:
- HipChat rooms to send the notification to.
- This parameter has been deprecated, please use 'notification_configuration' instead.
- The HipChat notification type has been deprecated.
type: list
elements: str
notify:
@ -293,21 +292,6 @@ EXAMPLES = '''
state: present
tower_config_file: "~/tower_cli.cfg"
- name: Add HipChat notification
tower_notification:
name: hipchat notification
notification_type: hipchat
notification_configuration:
token: a_token
message_from: user1
api_url: https://hipchat.example.com
color: red
rooms:
- room-A
notify: yes
state: present
tower_config_file: "~/tower_cli.cfg"
- name: Add IRC notification
tower_notification:
name: irc notification
@ -336,13 +320,17 @@ RETURN = ''' # '''
from ..module_utils.tower_api import TowerModule
HIPCHAT_PARAMS = (
'api_url', 'rooms',
)
OLD_INPUT_NAMES = (
'username', 'sender', 'recipients', 'use_tls',
'host', 'use_ssl', 'password', 'port',
'channels', 'token', 'account_token', 'from_number',
'to_numbers', 'account_sid', 'subdomain', 'service_key',
'client_name', 'message_from', 'api_url', 'color',
'rooms', 'notify', 'url', 'headers', 'server',
'client_name', 'message_from', 'color',
'notify', 'url', 'headers', 'server',
'nickname', 'targets',
)
@ -355,7 +343,7 @@ def main():
description=dict(),
organization=dict(),
notification_type=dict(choices=[
'email', 'grafana', 'hipchat', 'irc', 'mattermost',
'email', 'grafana', 'irc', 'mattermost',
'pagerduty', 'rocketchat', 'slack', 'twilio', 'webhook'
]),
notification_configuration=dict(type='dict'),
@ -395,7 +383,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
new_name = module.params.get("new_name")
new_name = module.params.get('new_name')
description = module.params.get('description')
organization = module.params.get('organization')
notification_type = module.params.get('notification_type')
@ -403,10 +391,16 @@ def main():
messages = module.params.get('messages')
state = module.params.get('state')
# Deprecation warnings
# Deprecation/removal warnings for HipChat notification type
for hipchat_params in HIPCHAT_PARAMS:
if module.params.get(hipchat_params) is not None:
module.deprecate(msg='{0} parameter has been deprecated; the HipChat notification type can no longer be generated'.format(hipchat_params),
version="4.0")
# Deprecation warnings for all other params
for legacy_input in OLD_INPUT_NAMES:
if module.params.get(legacy_input) is not None:
module.deprecate(msg='{0} parameter has been deprecated, please use notification_configuration instead.'.format(legacy_input), version="3.6")
module.deprecate(msg='{0} parameter has been deprecated, please use notification_configuration instead'.format(legacy_input), version="3.6")
# Attempt to look up the related items the user specified (these will fail the module if not found)
organization_id = None

View File

@ -6,7 +6,6 @@
email_not: "AWX-Collection-tests-tower_notification-email-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
twillo_not: "AWX-Collection-tests-tower_notification-twillo-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
pd_not: "AWX-Collection-tests-tower_notification-pd-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
hipchat_not: "AWX-Collection-tests-tower_notification-hipchat-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
irc_not: "AWX-Collection-tests-tower_notification-irc-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Test deprecation warnings
@ -212,36 +211,6 @@
that:
- result is changed
- name: Add HipChat notification
tower_notification:
name: "{{ hipchat_not }}"
organization: Default
notification_type: hipchat
token: a_token
message_from: user1
api_url: https://hipchat.example.com
color: red
rooms:
- room-A
notify: true
state: present
register: result
- assert:
that:
- result is changed
- name: Delete HipChat notification
tower_notification:
name: "{{ hipchat_not }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Add IRC notification
tower_notification:
name: "{{ irc_not }}"

View File

@ -72,7 +72,6 @@ The currently-defined Notification Types are:
* Email
* Slack
* HipChat
* Mattermost
* Rocket.Chat
* Pagerduty
@ -83,6 +82,8 @@ The currently-defined Notification Types are:
Each of these have their own configuration and behavioral semantics and testing them may need to be approached in different ways. The following sections will give as much detail as possible.
> **Note:** The HipChat notification type will be unavailable as of Tower 4.0
## Email
The email notification type supports a wide variety of SMTP servers and has support for SSL/TLS connections and timeouts.