backup-ssh 4.1.10

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.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +24 -0
  3. data/README.md +25 -0
  4. data/bin/backup +5 -0
  5. data/lib/backup.rb +141 -0
  6. data/lib/backup/archive.rb +170 -0
  7. data/lib/backup/binder.rb +22 -0
  8. data/lib/backup/cleaner.rb +116 -0
  9. data/lib/backup/cli.rb +374 -0
  10. data/lib/backup/cloud_io/base.rb +41 -0
  11. data/lib/backup/cloud_io/cloud_files.rb +298 -0
  12. data/lib/backup/cloud_io/s3.rb +260 -0
  13. data/lib/backup/compressor/base.rb +35 -0
  14. data/lib/backup/compressor/bzip2.rb +39 -0
  15. data/lib/backup/compressor/custom.rb +53 -0
  16. data/lib/backup/compressor/gzip.rb +74 -0
  17. data/lib/backup/config.rb +119 -0
  18. data/lib/backup/config/dsl.rb +103 -0
  19. data/lib/backup/config/helpers.rb +143 -0
  20. data/lib/backup/database/base.rb +85 -0
  21. data/lib/backup/database/mongodb.rb +186 -0
  22. data/lib/backup/database/mysql.rb +200 -0
  23. data/lib/backup/database/openldap.rb +95 -0
  24. data/lib/backup/database/postgresql.rb +133 -0
  25. data/lib/backup/database/redis.rb +179 -0
  26. data/lib/backup/database/riak.rb +82 -0
  27. data/lib/backup/database/sqlite.rb +57 -0
  28. data/lib/backup/encryptor/base.rb +29 -0
  29. data/lib/backup/encryptor/gpg.rb +747 -0
  30. data/lib/backup/encryptor/open_ssl.rb +77 -0
  31. data/lib/backup/errors.rb +58 -0
  32. data/lib/backup/logger.rb +199 -0
  33. data/lib/backup/logger/console.rb +51 -0
  34. data/lib/backup/logger/fog_adapter.rb +29 -0
  35. data/lib/backup/logger/logfile.rb +133 -0
  36. data/lib/backup/logger/syslog.rb +116 -0
  37. data/lib/backup/model.rb +454 -0
  38. data/lib/backup/notifier/base.rb +98 -0
  39. data/lib/backup/notifier/campfire.rb +69 -0
  40. data/lib/backup/notifier/datadog.rb +116 -0
  41. data/lib/backup/notifier/flowdock.rb +102 -0
  42. data/lib/backup/notifier/hipchat.rb +93 -0
  43. data/lib/backup/notifier/http_post.rb +122 -0
  44. data/lib/backup/notifier/mail.rb +238 -0
  45. data/lib/backup/notifier/nagios.rb +74 -0
  46. data/lib/backup/notifier/pagerduty.rb +81 -0
  47. data/lib/backup/notifier/prowl.rb +69 -0
  48. data/lib/backup/notifier/pushover.rb +80 -0
  49. data/lib/backup/notifier/ses.rb +94 -0
  50. data/lib/backup/notifier/slack.rb +154 -0
  51. data/lib/backup/notifier/twitter.rb +64 -0
  52. data/lib/backup/notifier/zabbix.rb +68 -0
  53. data/lib/backup/package.rb +51 -0
  54. data/lib/backup/packager.rb +101 -0
  55. data/lib/backup/pipeline.rb +124 -0
  56. data/lib/backup/splitter.rb +76 -0
  57. data/lib/backup/storage/base.rb +57 -0
  58. data/lib/backup/storage/cloud_files.rb +158 -0
  59. data/lib/backup/storage/cycler.rb +65 -0
  60. data/lib/backup/storage/dropbox.rb +236 -0
  61. data/lib/backup/storage/ftp.rb +98 -0
  62. data/lib/backup/storage/local.rb +64 -0
  63. data/lib/backup/storage/ninefold.rb +74 -0
  64. data/lib/backup/storage/rsync.rb +248 -0
  65. data/lib/backup/storage/s3.rb +155 -0
  66. data/lib/backup/storage/scp.rb +67 -0
  67. data/lib/backup/storage/sftp.rb +82 -0
  68. data/lib/backup/syncer/base.rb +70 -0
  69. data/lib/backup/syncer/cloud/base.rb +179 -0
  70. data/lib/backup/syncer/cloud/cloud_files.rb +83 -0
  71. data/lib/backup/syncer/cloud/local_file.rb +100 -0
  72. data/lib/backup/syncer/cloud/s3.rb +110 -0
  73. data/lib/backup/syncer/rsync/base.rb +48 -0
  74. data/lib/backup/syncer/rsync/local.rb +31 -0
  75. data/lib/backup/syncer/rsync/pull.rb +51 -0
  76. data/lib/backup/syncer/rsync/push.rb +205 -0
  77. data/lib/backup/template.rb +46 -0
  78. data/lib/backup/utilities.rb +224 -0
  79. data/lib/backup/version.rb +5 -0
  80. data/templates/cli/archive +28 -0
  81. data/templates/cli/compressor/bzip2 +4 -0
  82. data/templates/cli/compressor/custom +7 -0
  83. data/templates/cli/compressor/gzip +4 -0
  84. data/templates/cli/config +123 -0
  85. data/templates/cli/databases/mongodb +15 -0
  86. data/templates/cli/databases/mysql +18 -0
  87. data/templates/cli/databases/openldap +24 -0
  88. data/templates/cli/databases/postgresql +16 -0
  89. data/templates/cli/databases/redis +16 -0
  90. data/templates/cli/databases/riak +17 -0
  91. data/templates/cli/databases/sqlite +11 -0
  92. data/templates/cli/encryptor/gpg +27 -0
  93. data/templates/cli/encryptor/openssl +9 -0
  94. data/templates/cli/model +26 -0
  95. data/templates/cli/notifier/zabbix +15 -0
  96. data/templates/cli/notifiers/campfire +12 -0
  97. data/templates/cli/notifiers/datadog +57 -0
  98. data/templates/cli/notifiers/flowdock +16 -0
  99. data/templates/cli/notifiers/hipchat +15 -0
  100. data/templates/cli/notifiers/http_post +32 -0
  101. data/templates/cli/notifiers/mail +21 -0
  102. data/templates/cli/notifiers/nagios +13 -0
  103. data/templates/cli/notifiers/pagerduty +12 -0
  104. data/templates/cli/notifiers/prowl +11 -0
  105. data/templates/cli/notifiers/pushover +11 -0
  106. data/templates/cli/notifiers/ses +15 -0
  107. data/templates/cli/notifiers/slack +22 -0
  108. data/templates/cli/notifiers/twitter +13 -0
  109. data/templates/cli/splitter +7 -0
  110. data/templates/cli/storages/cloud_files +11 -0
  111. data/templates/cli/storages/dropbox +19 -0
  112. data/templates/cli/storages/ftp +12 -0
  113. data/templates/cli/storages/local +7 -0
  114. data/templates/cli/storages/ninefold +9 -0
  115. data/templates/cli/storages/rsync +17 -0
  116. data/templates/cli/storages/s3 +14 -0
  117. data/templates/cli/storages/scp +14 -0
  118. data/templates/cli/storages/sftp +14 -0
  119. data/templates/cli/syncers/cloud_files +22 -0
  120. data/templates/cli/syncers/rsync_local +20 -0
  121. data/templates/cli/syncers/rsync_pull +28 -0
  122. data/templates/cli/syncers/rsync_push +28 -0
  123. data/templates/cli/syncers/s3 +27 -0
  124. data/templates/general/links +3 -0
  125. data/templates/general/version.erb +2 -0
  126. data/templates/notifier/mail/failure.erb +16 -0
  127. data/templates/notifier/mail/success.erb +16 -0
  128. data/templates/notifier/mail/warning.erb +16 -0
  129. data/templates/storage/dropbox/authorization_url.erb +6 -0
  130. data/templates/storage/dropbox/authorized.erb +4 -0
  131. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  132. metadata +1057 -0
@@ -0,0 +1,122 @@
1
+ # encoding: utf-8
2
+ require 'uri'
3
+
4
+ module Backup
5
+ module Notifier
6
+ class HttpPost < Base
7
+
8
+ ##
9
+ # URI to post notification to.
10
+ #
11
+ # URI scheme may be `http` or `https`.
12
+ #
13
+ # If Basic Authentication is needed, supply the `user:password` in the URI.
14
+ # e.g. 'https://user:pass@www.example.com/path'
15
+ #
16
+ # Port may also be supplied.
17
+ # e.g. 'http://www.example.com:8080/path'
18
+ attr_accessor :uri
19
+
20
+ ##
21
+ # Hash of additional HTTP headers to send.
22
+ #
23
+ # This notifier sets the following headers:
24
+ # { 'User-Agent' => "Backup/#{ Backup::VERSION }",
25
+ # 'Content-Type' => 'x-www-form-urlencoded' }
26
+ #
27
+ # 'Content-Type' may not be changed.
28
+ # 'User-Agent' may be overridden or omitted by setting it to +nil+.
29
+ # e.g. { 'Authorization' => 'my_auth_info', 'User-Agent' => nil }
30
+ attr_accessor :headers
31
+
32
+ ##
33
+ # Hash of additional POST parameters to send.
34
+ #
35
+ # This notifier will set two parameters:
36
+ # { 'status' => 'success|warning|failure',
37
+ # 'message' => '[Backup::(Success|Warning|Failure)] label (trigger)' }
38
+ #
39
+ # 'status' may not be changed.
40
+ # 'message' may be overridden or omitted by setting a +nil+ value.
41
+ # e.g. { 'auth_token' => 'my_token', 'message' => nil }
42
+ attr_accessor :params
43
+
44
+ ##
45
+ # Successful HTTP Status Code(s) that should be returned.
46
+ #
47
+ # This may be a single code or an Array of acceptable codes.
48
+ # e.g. [200, 201, 204]
49
+ #
50
+ # If any other response code is returned, the request will be retried
51
+ # using `max_retries` and `retry_waitsec`.
52
+ #
53
+ # Default: 200
54
+ attr_accessor :success_codes
55
+
56
+ ##
57
+ # Verify the server's certificate when using SSL.
58
+ #
59
+ # This will default to +true+ for most systems.
60
+ # It may be forced by setting to +true+, or disabled by setting to +false+.
61
+ attr_accessor :ssl_verify_peer
62
+
63
+ ##
64
+ # Path to a +cacert.pem+ file to use for +ssl_verify_peer+.
65
+ #
66
+ # This is provided (via Excon), but may be specified if needed.
67
+ attr_accessor :ssl_ca_file
68
+
69
+ def initialize(model, &block)
70
+ super
71
+ instance_eval(&block) if block_given?
72
+
73
+ @headers ||= {}
74
+ @params ||= {}
75
+ @success_codes ||= 200
76
+ end
77
+
78
+ private
79
+
80
+ ##
81
+ # Notify the user of the backup operation results.
82
+ #
83
+ # `status` indicates one of the following:
84
+ #
85
+ # `:success`
86
+ # : The backup completed successfully.
87
+ # : Notification will be sent if `on_success` is `true`.
88
+ #
89
+ # `:warning`
90
+ # : The backup completed successfully, but warnings were logged.
91
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
92
+ #
93
+ # `:failure`
94
+ # : The backup operation failed.
95
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
96
+ #
97
+ def notify!(status)
98
+ tag = case status
99
+ when :success then '[Backup::Success]'
100
+ when :failure then '[Backup::Failure]'
101
+ when :warning then '[Backup::Warning]'
102
+ end
103
+ message = "#{ tag } #{ model.label } (#{ model.trigger })"
104
+
105
+ opts = {
106
+ :headers => { 'User-Agent' => "Backup/#{ VERSION }" }.
107
+ merge(headers).reject {|k,v| v.nil? }.
108
+ merge('Content-Type' => 'application/x-www-form-urlencoded'),
109
+ :body => URI.encode_www_form({ 'message' => message }.
110
+ merge(params).reject {|k,v| v.nil? }.
111
+ merge('status' => status.to_s)),
112
+ :expects => success_codes # raise error if unsuccessful
113
+ }
114
+ opts.merge!(:ssl_verify_peer => ssl_verify_peer) unless ssl_verify_peer.nil?
115
+ opts.merge!(:ssl_ca_file => ssl_ca_file) if ssl_ca_file
116
+
117
+ Excon.post(uri, opts)
118
+ end
119
+
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,238 @@
1
+ # encoding: utf-8
2
+ require 'mail'
3
+
4
+ module Backup
5
+ module Notifier
6
+ class Mail < Base
7
+
8
+ ##
9
+ # Mail delivery method to be used by the Mail gem.
10
+ #
11
+ # Supported methods:
12
+ #
13
+ # [:smtp - ::Mail::SMTP (default)]
14
+ # Settings used by this method:
15
+ # {#address}, {#port}, {#domain}, {#user_name}, {#password},
16
+ # {#authentication}, {#encryption}, {#openssl_verify_mode}
17
+ #
18
+ # [:sendmail - ::Mail::Sendmail]
19
+ # Settings used by this method:
20
+ # {#sendmail_args}
21
+ #
22
+ # [:exim - ::Mail::Exim]
23
+ # Settings used by this method:
24
+ # {#exim_args}
25
+ #
26
+ # [:file - ::Mail::FileDelivery]
27
+ # Settings used by this method:
28
+ # {#mail_folder}
29
+ #
30
+ attr_accessor :delivery_method
31
+
32
+ ##
33
+ # Sender Email Address
34
+ attr_accessor :from
35
+
36
+ ##
37
+ # Receiver Email Address
38
+ attr_accessor :to
39
+
40
+ ##
41
+ # SMTP Server Address
42
+ attr_accessor :address
43
+
44
+ ##
45
+ # SMTP Server Port
46
+ attr_accessor :port
47
+
48
+ ##
49
+ # Your domain (if applicable)
50
+ attr_accessor :domain
51
+
52
+ ##
53
+ # SMTP Server Username (sender email's credentials)
54
+ attr_accessor :user_name
55
+
56
+ ##
57
+ # SMTP Server Password (sender email's credentials)
58
+ attr_accessor :password
59
+
60
+ ##
61
+ # Authentication type
62
+ #
63
+ # Acceptable values: +:plain+, +:login+, +:cram_md5+
64
+ attr_accessor :authentication
65
+
66
+ ##
67
+ # Set the method of encryption to be used for the +SMTP+ connection.
68
+ #
69
+ # [:starttls (default)]
70
+ # Use +STARTTLS+ to upgrade the connection to a +SSL/TLS+ connection.
71
+ #
72
+ # [:tls or :ssl]
73
+ # Use a +SSL/TLS+ connection.
74
+ #
75
+ # [:none]
76
+ # No encryption will be used.
77
+ attr_accessor :encryption
78
+
79
+ ##
80
+ # OpenSSL Verify Mode
81
+ #
82
+ # Valid modes: +:none+, +:peer+, +:client_once+, +:fail_if_no_peer_cert+
83
+ # See +OpenSSL::SSL+ for details.
84
+ #
85
+ # Use +:none+ for a self-signed and/or wildcard certificate
86
+ attr_accessor :openssl_verify_mode
87
+
88
+ ##
89
+ # Optional arguments to pass to `sendmail`
90
+ #
91
+ # Note that this will override the defaults set by the Mail gem
92
+ # (currently: '-i'). So, if set here, be sure to set all the arguments
93
+ # you require.
94
+ #
95
+ # Example: '-i -X/tmp/traffic.log'
96
+ attr_accessor :sendmail_args
97
+
98
+ ##
99
+ # Optional arguments to pass to `exim`
100
+ #
101
+ # Note that this will override the defaults set by the Mail gem
102
+ # (currently: '-i -t') So, if set here, be sure to set all the arguments
103
+ # you require.
104
+ #
105
+ # Example: '-i -t -X/tmp/traffic.log'
106
+ attr_accessor :exim_args
107
+
108
+ ##
109
+ # Folder where mail will be kept when using the `:file` `delivery_method`.
110
+ #
111
+ # Default location is '$HOME/Backup/emails'
112
+ attr_accessor :mail_folder
113
+
114
+ ##
115
+ # Array of statuses for which the log file should be attached.
116
+ #
117
+ # Available statuses are: `:success`, `:warning` and `:failure`.
118
+ # Default: [:warning, :failure]
119
+ attr_accessor :send_log_on
120
+
121
+ def initialize(model, &block)
122
+ super
123
+ instance_eval(&block) if block_given?
124
+
125
+ @send_log_on ||= [:warning, :failure]
126
+ @encryption ||= :starttls
127
+ end
128
+
129
+ private
130
+
131
+ ##
132
+ # Notify the user of the backup operation results.
133
+ #
134
+ # `status` indicates one of the following:
135
+ #
136
+ # `:success`
137
+ # : The backup completed successfully.
138
+ # : Notification will be sent if `on_success` is `true`.
139
+ #
140
+ # `:warning`
141
+ # : The backup completed successfully, but warnings were logged.
142
+ # : Notification will be sent, including a copy of the current
143
+ # : backup log, if `on_warning` or `on_success` is `true`.
144
+ #
145
+ # `:failure`
146
+ # : The backup operation failed.
147
+ # : Notification will be sent, including a copy of the current
148
+ # : backup log, if `on_failure` is `true`.
149
+ #
150
+ def notify!(status)
151
+ tag = case status
152
+ when :success then '[Backup::Success]'
153
+ when :warning then '[Backup::Warning]'
154
+ when :failure then '[Backup::Failure]'
155
+ end
156
+
157
+ email = new_email
158
+ email.subject = "#{ tag } #{ model.label } (#{ model.trigger })"
159
+
160
+ send_log = send_log_on.include?(status)
161
+ template = Backup::Template.new({ :model => model, :send_log => send_log })
162
+ email.body = template.result('notifier/mail/%s.erb' % status.to_s)
163
+
164
+ if send_log
165
+ email.convert_to_multipart
166
+ email.attachments["#{ model.time }.#{ model.trigger }.log"] = {
167
+ :mime_type => 'text/plain;',
168
+ :content => Logger.messages.map(&:formatted_lines).flatten.join("\n")
169
+ }
170
+ end
171
+
172
+ email.deliver! # raise error if unsuccessful
173
+ end
174
+
175
+ ##
176
+ # Configures the Mail gem by setting the defaults.
177
+ # Creates and returns a new email, based on the @delivery_method used.
178
+ def new_email
179
+ method = %w{ smtp sendmail exim file test }.
180
+ index(@delivery_method.to_s) ? @delivery_method.to_s : 'smtp'
181
+
182
+ options =
183
+ case method
184
+ when 'smtp'
185
+ { :address => @address,
186
+ :port => @port,
187
+ :domain => @domain,
188
+ :user_name => @user_name,
189
+ :password => @password,
190
+ :authentication => @authentication,
191
+ :enable_starttls_auto => @encryption == :starttls,
192
+ :openssl_verify_mode => @openssl_verify_mode,
193
+ :ssl => @encryption == :ssl,
194
+ :tls => @encryption == :tls
195
+ }
196
+ when 'sendmail'
197
+ opts = {}
198
+ opts.merge!(:location => utility(:sendmail))
199
+ opts.merge!(:arguments => @sendmail_args) if @sendmail_args
200
+ opts
201
+ when 'exim'
202
+ opts = {}
203
+ opts.merge!(:location => utility(:exim))
204
+ opts.merge!(:arguments => @exim_args) if @exim_args
205
+ opts
206
+ when 'file'
207
+ @mail_folder ||= File.join(Config.root_path, 'emails')
208
+ { :location => File.expand_path(@mail_folder) }
209
+ when 'test' then {}
210
+ end
211
+
212
+ ::Mail.defaults do
213
+ delivery_method method.to_sym, options
214
+ end
215
+
216
+ email = ::Mail.new
217
+ email.to = @to
218
+ email.from = @from
219
+ email
220
+ end
221
+
222
+ end
223
+ end
224
+ end
225
+
226
+ # Patch mail v2.5.4 Exim delivery method
227
+ # https://github.com/backup/backup/issues/446
228
+ # https://github.com/mikel/mail/pull/546
229
+ module Mail
230
+ class Exim
231
+ def self.call(path, arguments, destinations, encoded_message)
232
+ popen "#{path} #{arguments}" do |io|
233
+ io.puts encoded_message.to_lf
234
+ io.flush
235
+ end
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Notifier
5
+ class Nagios < Base
6
+
7
+ ##
8
+ # Host of Nagios server to notify on backup completion.
9
+ attr_accessor :nagios_host
10
+
11
+ ##
12
+ # Port of Nagios server to notify on backup completion.
13
+ attr_accessor :nagios_port
14
+
15
+ ##
16
+ # Nagios nrpe configuration file.
17
+ attr_accessor :send_nsca_cfg
18
+
19
+ ##
20
+ # Name of the Nagios service for the backup check.
21
+ attr_accessor :service_name
22
+
23
+ ##
24
+ # Host name in Nagios for the backup check.
25
+ attr_accessor :service_host
26
+
27
+ def initialize(model, &block)
28
+ super
29
+ instance_eval(&block) if block_given?
30
+
31
+ @nagios_host ||= Config.hostname
32
+ @nagios_port ||= 5667
33
+ @send_nsca_cfg||= "/etc/nagios/send_nsca.cfg"
34
+ @service_name ||= "Backup #{ model.trigger }"
35
+ @service_host ||= Config.hostname
36
+ end
37
+
38
+ private
39
+
40
+ ##
41
+ # Notify the user of the backup operation results.
42
+ #
43
+ # `status` indicates one of the following:
44
+ #
45
+ # `:success`
46
+ # : The backup completed successfully.
47
+ # : Notification will be sent if `on_success` is `true`.
48
+ #
49
+ # `:warning`
50
+ # : The backup completed successfully, but warnings were logged.
51
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
52
+ #
53
+ # `:failure`
54
+ # : The backup operation failed.
55
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
56
+ #
57
+ def notify!(status)
58
+ message = case status
59
+ when :success then 'Completed Successfully'
60
+ when :warning then 'Completed Successfully (with Warnings)'
61
+ when :failure then 'Failed'
62
+ end
63
+ send_message("#{ message } in #{ model.duration }")
64
+ end
65
+
66
+ def send_message(message)
67
+ cmd = "#{ utility(:send_nsca) } -H '#{ nagios_host }' -p '#{ nagios_port }' -c '#{ send_nsca_cfg }'"
68
+ msg = [service_host, service_name, model.exit_status, message].join("\t")
69
+ run("echo '#{ msg }' | #{ cmd }")
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+ require 'pagerduty'
3
+
4
+ module Backup
5
+ module Notifier
6
+ class PagerDuty < Base
7
+
8
+ ##
9
+ # PagerDuty Service API Key. Should be a 32 character hex string.
10
+ attr_accessor :service_key
11
+
12
+ ##
13
+ # Determines if a backup with a warning should resolve an incident rather
14
+ # than trigger one.
15
+ #
16
+ # Defaults to false.
17
+ attr_accessor :resolve_on_warning
18
+
19
+ def initialize(mode, &block)
20
+ super
21
+ instance_eval(&block) if block_given?
22
+
23
+ @resolve_on_warning ||= false
24
+ end
25
+
26
+ private
27
+
28
+ ##
29
+ # Trigger or resolve a PagerDuty incident for this model
30
+ #
31
+ # `status` indicates one of the following:
32
+ #
33
+ # `:success`
34
+ # : The backup completed successfully.
35
+ # : The incident will be resolved if `on_success` is `true`.
36
+ #
37
+ # `:warning`
38
+ # : The backup completed successfully, but warnings were logged.
39
+ # : An incident will be triggered if `on_warning` or `on_success` is `true`.
40
+ #
41
+ # `:failure`
42
+ # : The backup operation failed.
43
+ # : An incident will be triggered if `on_failure` is `true`.
44
+ #
45
+ def notify!(status)
46
+ incident_description = "Backup - #{model.label}"
47
+ incident_key = "backup/#{model.trigger}"
48
+ incident_details = {
49
+ :incident_key => incident_key,
50
+ :details => {
51
+ :trigger => model.trigger,
52
+ :label => model.label,
53
+ :started_at => model.started_at,
54
+ :finished_at => model.finished_at,
55
+ :duration => model.duration,
56
+ :status => status,
57
+ :exception => model.exception
58
+ }
59
+ }
60
+
61
+ event_type = case status
62
+ when :success then :resolve
63
+ when :warning then resolve_on_warning ? :resolve : :trigger
64
+ when :failure then :trigger
65
+ end
66
+
67
+ case event_type
68
+ when :trigger
69
+ pagerduty.trigger(incident_description, incident_details)
70
+ when :resolve
71
+ incident = pagerduty.get_incident(incident_key)
72
+ incident.resolve(incident_description, incident_details)
73
+ end
74
+ end
75
+
76
+ def pagerduty
77
+ @pagerduty ||= Pagerduty.new(service_key)
78
+ end
79
+ end
80
+ end
81
+ end