Add support for monasca-notification hipchat and slack

Also add spec test for the class and new parms

Change-Id: Ic4132374446b417d6bd7f0ecd6451b0070dc74e3
This commit is contained in:
Brad Klein 2016-11-15 14:55:01 -07:00
parent a5aa94e275
commit 86955c96ac
3 changed files with 143 additions and 20 deletions

View File

@ -1,65 +1,99 @@
# == Class: monasca::notifications
# == Class: monasca::notification
#
# Class for configuring monasca notifications
#
# === Parameters:
#
# [*notification_user*]
# name of the monasca notification user
#
# [*from_email_address*]
# email address to send notifications from
# (Optional) Email address to send notifications from.
# Defaults to empty string.
#
# [*hipchat_ca_certs*]
# (Optional) CA cert file for hipchat notifications
# Defaults to "/etc/ssl/certs/ca-certificates.crt"
#
# [*hipchat_insecure*]
# (Optional) Flag to indicate if hipchat notification calls should
# be insecure.
# Defaults to False
#
# [*install_python_deps*]
# flag for whether or not to install python dependencies
# (Optional) Flag for whether or not to install python dependencies.
# Defaults to true.
#
# [*kafka_brokers*]
# list of kafka broker servers and ports
# (Optional) List of kafka broker servers and ports.
# Defaults to 'localhost:9092'.
#
# [*notification_user*]
# (Optional) Name of the monasca notification user.
# Defaults to 'monasca-notification'.
#
# [*pagerduty_url*]
# url of pager duty if used as a notification method
# (Optional) URL of pager duty if used as a notification method.
# Defaults to 'https://events.pagerduty.com/generic/2010-04-15/create_event.json'.
#
# [*periodic_kafka_topics*]
# list of periodic notification kafka topics, defaults
# to '60: 60-seconds-notifications'
# (Optional) List of periodic notification kafka topics
# Defaults to '60: 60-seconds-notifications'
#
# [*periodic_zookeeper_paths*]
# list of periodic notification zookeeper paths, defaults
# to '60: /notification/60_seconds'
# (Optional) List of periodic notification zookeeper paths
# Defaults to '60: /notification/60_seconds'
#
# [*python_dep_ensure*]
# flag for whether or not to ensure/update python dependencies
# (Optional) Flag for whether or not to ensure/update python dependencies.
# Defaults to 'present'.
#
# [*slack_ca_certs*]
# (Optional) CA cert file for slack notifications.
# Defaults to "/etc/ssl/certs/ca-certificates.crt".
#
# [*slack_insecure*]
# (Optional) Flag to indicate if slack notification calls should
# be insecure.
# Defaults to False.
#
# [*smtp_password*]
# password for the smtp server
# (Optional) Password for the smtp server.
# Defaults to empty string.
#
# [*smtp_port*]
# port on the smtp server to send mail to
# (Optional) Port on the smtp server to send mail to.
# Defaults to 25.
#
# [*smtp_server*]
# host of the smtp server
# (Optional) Host of the smtp server.
# Defaults to 'localhost'.
#
# [*smtp_user*]
# name to use when authenticating agains the smtp server
# (Optional) Name to use when authenticating agains the smtp server.
# Defaults to empty string.
#
# [*virtual_env*]
# directory of python virtual environment
#
# [*webhook_url*]
# url for webhook notifications
# (Optional) URL for webhook notifications.
# Defaults to empty string.
#
# [*zookeeper_servers*]
# list of zookeeper servers and ports
# (Optional) List of zookeeper servers and ports.
# Defaults to 'localhost:2181'.
#
class monasca::notification(
$notification_user = 'monasca-notification',
$from_email_address = '',
$hipchat_ca_certs = '/etc/ssl/certs/ca-certificates.crt',
$hipchat_insecure = false,
$install_python_deps = true,
$kafka_brokers = 'localhost:9092',
$notification_user = 'monasca-notification',
$pagerduty_url = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json',
$periodic_kafka_topics = ['60: 60-seconds-notifications'],
$periodic_zookeeper_paths = ['60: /notification/60_seconds'],
$python_dep_ensure = 'present',
$slack_ca_certs = '/etc/ssl/certs/ca-certificates.crt',
$slack_insecure = false,
$smtp_password = '',
$smtp_port = 25,
$smtp_server = 'localhost',

View File

@ -0,0 +1,75 @@
require 'spec_helper'
describe 'monasca::notification' do
describe 'on debian platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'Debian',
})
end
let :cfg_file do
"/etc/monasca/notification.yaml"
end
let :start_script do
"/etc/init/monasca-notification.conf"
end
let :pre_condition do
"include monasca"
end
let(:params) { {
:install_python_deps => false,
} }
it 'starts the notification service' do
is_expected.to contain_service('monasca-notification')
end
it 'builds the notification config file properly' do
is_expected.to contain_file(cfg_file).with_content(/^\s*kafka:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*url: localhost:9092$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*group: monasca-notification$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*alarm_topic: alarm-state-transitions$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*notification_topic: alarm-notifications$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*notification_retry_topic: retry-notifications$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*max_offset_lag: 600$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*periodic:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*60: 60-seconds-notifications$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*mysql:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*host: $/)
is_expected.to contain_file(cfg_file).with_content(/^\s*port: 3306$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*user: $/)
is_expected.to contain_file(cfg_file).with_content(/^\s*passwd: $/)
is_expected.to contain_file(cfg_file).with_content(/^\s*db: mon$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*notification_types:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*plugins:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*- monasca_notification.plugins.hipchat_notifier:HipChatNotifier$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*- monasca_notification.plugins.slack_notifier:SlackNotifier$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*email:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*server: localhost$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*port: 25$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*notifications_size: 256$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*sent_notifications_size: 50$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*notification_path: \/notification\/alarms$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*notification_retry_path: \/notification\/retry$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*60: \/notification\/60_seconds$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*periodic_path:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*logging:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*version: 1$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*disable_existing_loggers: False$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*formatters:$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*filename: \/var\/log\/monasca\/notification.log$/)
is_expected.to contain_file(cfg_file).with_content(/^\s*ca_certs: \/etc\/ssl\/certs\/ca-certificates.crt$/)
end
it 'builds the startup script properly' do
is_expected.to contain_file(start_script).with_content(/^\s*kill timeout 240$/)
is_expected.to contain_file(start_script).with_content(/^\s*setgid monasca$/)
is_expected.to contain_file(start_script).with_content(/^\s*setuid monasca-notification$/)
is_expected.to contain_file(start_script).with_content(/^\s*exec \/var\/www\/monasca-notification\/bin\/monasca-notification > \/dev\/null$/)
end
end
end

View File

@ -20,6 +20,10 @@ mysql:
db: mon
notification_types:
plugins:
- monasca_notification.plugins.hipchat_notifier:HipChatNotifier
- monasca_notification.plugins.slack_notifier:SlackNotifier
email:
server: <%= @smtp_server %>
port: <%= @smtp_port %>
@ -36,6 +40,16 @@ notification_types:
timeout: 5
url: <%= @pagerduty_url %>
hipchat:
timeout: 5
ca_certs: <%= @hipchat_ca_certs %>
insecure: <%= @hipchat_insecure %>
slack:
timeout: 5
ca_certs: <%= @slack_ca_certs %>
insecure: <%= @slack_insecure %>
processors:
alarm:
number: 2