backup 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/backup.rb +1 -0
- data/lib/backup/config/dsl.rb +1 -1
- data/lib/backup/notifier/slack.rb +149 -0
- data/lib/backup/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0598ab928bc914fc5be6f4e473a2dba3f3b80c41
|
4
|
+
data.tar.gz: d8c34be3b2896bb9a1cc024c67df93783ae1853c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eed55c0c9b7e63ba902db61e8148413a430d21755175c34926ae5348318aefde89876a5dd8231dccef11adaad44ec08575f3e244e7b3ab235e2100e764b9b079
|
7
|
+
data.tar.gz: 20d0efa09f22cf70b9bdaf94ac49d43f1fbe0d499b44bfe31ac93c0b867559c3db83c87a70953d5def9cfe53caff2308f36dc40cc0b1406cf284d310749c80b2
|
data/lib/backup.rb
CHANGED
@@ -105,6 +105,7 @@ module Backup
|
|
105
105
|
autoload :Prowl, File.join(NOTIFIER_PATH, 'prowl')
|
106
106
|
autoload :Hipchat, File.join(NOTIFIER_PATH, 'hipchat')
|
107
107
|
autoload :Pushover, File.join(NOTIFIER_PATH, 'pushover')
|
108
|
+
autoload :Slack, File.join(NOTIFIER_PATH, 'slack')
|
108
109
|
autoload :HttpPost, File.join(NOTIFIER_PATH, 'http_post')
|
109
110
|
autoload :Nagios, File.join(NOTIFIER_PATH, 'nagios')
|
110
111
|
end
|
data/lib/backup/config/dsl.rb
CHANGED
@@ -0,0 +1,149 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Backup
|
6
|
+
module Notifier
|
7
|
+
class Slack < Base
|
8
|
+
|
9
|
+
##
|
10
|
+
# The Team name
|
11
|
+
attr_accessor :team
|
12
|
+
|
13
|
+
##
|
14
|
+
# The Integration Token
|
15
|
+
attr_accessor :token
|
16
|
+
|
17
|
+
##
|
18
|
+
# The channel to send messages to
|
19
|
+
attr_accessor :channel
|
20
|
+
|
21
|
+
##
|
22
|
+
# The username to display along with the notification
|
23
|
+
attr_accessor :username
|
24
|
+
|
25
|
+
##
|
26
|
+
# Array of statuses for which the log file should be attached.
|
27
|
+
#
|
28
|
+
# Available statuses are: `:success`, `:warning` and `:failure`.
|
29
|
+
# Default: [:warning, :failure]
|
30
|
+
attr_accessor :send_log_on
|
31
|
+
|
32
|
+
def initialize(model, &block)
|
33
|
+
super
|
34
|
+
instance_eval(&block) if block_given?
|
35
|
+
|
36
|
+
@send_log_on ||= [:warning, :failure]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
##
|
42
|
+
# Notify the user of the backup operation results.
|
43
|
+
#
|
44
|
+
# `status` indicates one of the following:
|
45
|
+
#
|
46
|
+
# `:success`
|
47
|
+
# : The backup completed successfully.
|
48
|
+
# : Notification will be sent if `on_success` is `true`.
|
49
|
+
#
|
50
|
+
# `:warning`
|
51
|
+
# : The backup completed successfully, but warnings were logged.
|
52
|
+
# : Notification will be sent if `on_warning` or `on_success` is `true`.
|
53
|
+
#
|
54
|
+
# `:failure`
|
55
|
+
# : The backup operation failed.
|
56
|
+
# : Notification will be sent if `on_warning` or `on_success` is `true`.
|
57
|
+
#
|
58
|
+
def notify!(status)
|
59
|
+
tag = case status
|
60
|
+
when :success then '[Backup::Success]'
|
61
|
+
when :failure then '[Backup::Failure]'
|
62
|
+
when :warning then '[Backup::Warning]'
|
63
|
+
end
|
64
|
+
message = "#{ tag } #{ model.label } (#{ model.trigger })"
|
65
|
+
|
66
|
+
data = { :text => message }
|
67
|
+
[:channel, :username].each do |param|
|
68
|
+
val = send(param)
|
69
|
+
data.merge!(param => val) if val
|
70
|
+
end
|
71
|
+
|
72
|
+
data.merge!(:attachments => [attachment(status)])
|
73
|
+
|
74
|
+
options = {
|
75
|
+
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
76
|
+
:body => URI.encode_www_form(:payload => JSON.dump(data))
|
77
|
+
}
|
78
|
+
options.merge!(:expects => 200) # raise error if unsuccessful
|
79
|
+
Excon.post(uri, options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def attachment(status)
|
83
|
+
{
|
84
|
+
:fallback => "#{title(status)} - Job: #{model.label} (#{model.trigger})",
|
85
|
+
:text => title(status),
|
86
|
+
:color => color(status),
|
87
|
+
:fields => [
|
88
|
+
{
|
89
|
+
:title => "Job",
|
90
|
+
:value => "#{model.label} (#{model.trigger})",
|
91
|
+
:short => false
|
92
|
+
},
|
93
|
+
{
|
94
|
+
:title => "Started",
|
95
|
+
:value => model.started_at,
|
96
|
+
:short => true
|
97
|
+
},
|
98
|
+
{
|
99
|
+
:title => "Finished",
|
100
|
+
:value => model.finished_at,
|
101
|
+
:short => true
|
102
|
+
},
|
103
|
+
{
|
104
|
+
:title => "Duration",
|
105
|
+
:value => model.duration,
|
106
|
+
:short => true
|
107
|
+
},
|
108
|
+
{
|
109
|
+
:title => "Version",
|
110
|
+
:value => "Backup v#{Backup::VERSION}\nRuby: #{RUBY_DESCRIPTION}",
|
111
|
+
:short => false
|
112
|
+
},
|
113
|
+
log_field(status)
|
114
|
+
].compact
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def log_field(status)
|
119
|
+
send_log = send_log_on.include?(status)
|
120
|
+
|
121
|
+
return {
|
122
|
+
:title => "Detailed Backup Log",
|
123
|
+
:value => Logger.messages.map(&:formatted_lines).flatten.join("\n"),
|
124
|
+
:short => false,
|
125
|
+
} if send_log
|
126
|
+
end
|
127
|
+
|
128
|
+
def color(status)
|
129
|
+
case status
|
130
|
+
when :success then 'good'
|
131
|
+
when :failure then 'danger'
|
132
|
+
when :warning then 'warning'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def title(status)
|
137
|
+
case status
|
138
|
+
when :success then 'Backup Completed Successfully!'
|
139
|
+
when :failure then 'Backup Failed!'
|
140
|
+
when :warning then 'Backup Completed Successfully (with Warnings)!'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def uri
|
145
|
+
@uri ||= "https://#{team}.slack.com/services/hooks/incoming-webhook?token=#{token}"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/lib/backup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -582,6 +582,7 @@ files:
|
|
582
582
|
- lib/backup/notifier/nagios.rb
|
583
583
|
- lib/backup/notifier/prowl.rb
|
584
584
|
- lib/backup/notifier/pushover.rb
|
585
|
+
- lib/backup/notifier/slack.rb
|
585
586
|
- lib/backup/notifier/twitter.rb
|
586
587
|
- lib/backup/package.rb
|
587
588
|
- lib/backup/packager.rb
|
@@ -683,7 +684,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
683
684
|
version: '0'
|
684
685
|
requirements: []
|
685
686
|
rubyforge_project:
|
686
|
-
rubygems_version: 2.2.
|
687
|
+
rubygems_version: 2.2.2
|
687
688
|
signing_key:
|
688
689
|
specification_version: 4
|
689
690
|
summary: Provides an elegant DSL in Ruby for performing backups on UNIX-like systems.
|