Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to specify the console url #9

Merged
merged 1 commit into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/puppet/reports/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
SLACK_WEBHOOK_URL = config['webhook_url']
Puppet.debug "Webhook is #{SLACK_WEBHOOK_URL}"
SLACK_CHANNEL = config['channel']
PUPPETCONSOLE = config['puppetconsole']
DISABLED_FILE = File.join([File.dirname(Puppet.settings[:config]), 'slack_disabled'])

def process
disabled = File.exists?(DISABLED_FILE)

if (!disabled && self.status != 'unchanged')
Puppet.debug "Sending notification for #{self.host} to Slack channel #{SLACK_CHANNEL}"
msg = "Puppet run for #{self.host} #{self.status} at #{Time.now.asctime} on #{self.configuration_version} in #{self.environment}. Report available <https://#{Puppet.settings[:ca_server]}/#/node_groups/inventory/node/#{self.host}/reports|here>"
msg = "Puppet run for #{self.host} #{self.status} at #{Time.now.asctime} on #{self.configuration_version} in #{self.environment}. Report available <https://#{PUPPETCONSOLE}/#/node_groups/inventory/node/#{self.host}/reports|here>"
notifier = Slack::Notifier.new SLACK_WEBHOOK_URL, channel: SLACK_CHANNEL, username: 'Puppet'
notifier.ping msg, icon_url: "https://puppetlabs.com/wp-content/uploads/2010/12/PL_logo_vertical_RGB_lg.jpg"
end
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class reportslack (
$webhook,
$channel,
$puppetconsole = $settings::ca_server,
) {
validate_re($webhook, 'https:\/\/hooks.slack.com\/(services\/)?T.+\/B.+\/.+', 'The webhook URL is invalid')
validate_re($channel, '#.+', 'The channel should start with a hash sign')
Expand Down
6 changes: 4 additions & 2 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
let (:params) { {
:webhook => 'https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX',
:channel => '#default',
:puppetconsole => 'master.inf.puppetlabs.demo',
} }
it {
should compile
Expand All @@ -13,7 +14,7 @@
'provider' => 'puppetserver_gem',
})
should contain_file('/etc/puppet/slack.yaml').with ({
'content' => "---\nwebhook_url: \"https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX\"\nchannel: \"#default\"\n",
'content' => "---\nwebhook_url: \"https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX\"\nchannel: \"#default\"\npuppetconsole: \"master.inf.puppetlabs.demo\"\n",
'owner' => 'pe-puppet',
'mode' => '0644',
'group' => 'pe-puppet',
Expand All @@ -37,6 +38,7 @@
let (:params) { {
:webhook => 'https://hooks.slack.com/services/TXXXXX/BXXXXX/XXXXXXXXXX',
:channel => '#default',
:puppetconsole => 'master.inf.puppetlabs.demo',
} }
it {
should compile
Expand All @@ -46,7 +48,7 @@
'provider' => 'puppetserver_gem',
})
should contain_file('/etc/puppet/slack.yaml').with ({
'content' => "---\nwebhook_url: \"https://hooks.slack.com/services/TXXXXX/BXXXXX/XXXXXXXXXX\"\nchannel: \"#default\"\n",
'content' => "---\nwebhook_url: \"https://hooks.slack.com/services/TXXXXX/BXXXXX/XXXXXXXXXX\"\nchannel: \"#default\"\npuppetconsole: \"master.inf.puppetlabs.demo\"\n",
'owner' => 'pe-puppet',
'mode' => '0644',
'group' => 'pe-puppet',
Expand Down
1 change: 1 addition & 0 deletions templates/slack.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
webhook_url: "<%= @webhook %>"
channel: "<%= @channel %>"
puppetconsole: "<%= @puppetconsole %>"