backup 4.0.4 → 4.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ca73fdee095965690119b7f88bd58f3275ca09e
4
- data.tar.gz: a8d4446e87d9315ca051bb92a613c3608a777f5e
3
+ metadata.gz: 3962cf879bd26668539060945c2081db3bd13046
4
+ data.tar.gz: 061ae2f749d7fc1494ac20c4f116e1201e8ce86a
5
5
  SHA512:
6
- metadata.gz: 565291689a33745325adc776df783c1d314a50db30e5566bd0ac641a62df0f80788cc2c4c0eb64983a39fed23408047b7a9f6fd24a38d9cc2abfe63870f0d3fd
7
- data.tar.gz: e1928778dc5c60155163f1a1994a74c3a0c07206c711b5f7ff5be58115906f25b6577878054a6a3c5d2e78b66eb1c36a7762a89bd0de60f71a903c99cb459c65
6
+ metadata.gz: 077072ee73e085c6151592a2506c2e65895d9a435cfdec6232c34fc67452a0f70356105de93b7aa40410ad21f6666da0f143a922edb180e8872d97a06a4e9014
7
+ data.tar.gz: bb86e8d7e30d2085691b598a662e3bdb10ffc30c5ba45fe5a2f8065559129dd3a0e931cc27e47eb957809131393d114e515e1d930827dcf5ed6d0cc913c9ff77
@@ -11,6 +11,7 @@ require 'thread'
11
11
 
12
12
  require 'open4'
13
13
  require 'thor'
14
+ require 'shellwords'
14
15
 
15
16
  require 'excon'
16
17
  # Include response.inspect in error messages.
@@ -105,6 +106,7 @@ module Backup
105
106
  autoload :Campfire, File.join(NOTIFIER_PATH, 'campfire')
106
107
  autoload :Prowl, File.join(NOTIFIER_PATH, 'prowl')
107
108
  autoload :Hipchat, File.join(NOTIFIER_PATH, 'hipchat')
109
+ autoload :PagerDuty, File.join(NOTIFIER_PATH, 'pagerduty')
108
110
  autoload :Pushover, File.join(NOTIFIER_PATH, 'pushover')
109
111
  autoload :Slack, File.join(NOTIFIER_PATH, 'slack')
110
112
  autoload :HttpPost, File.join(NOTIFIER_PATH, 'http_post')
@@ -42,7 +42,7 @@ module Backup
42
42
  ],
43
43
  # Notifiers
44
44
  ['Mail', 'Twitter', 'Campfire', 'Prowl',
45
- 'Hipchat', 'Pushover', 'HttpPost', 'Nagios',
45
+ 'Hipchat', 'PagerDuty', 'Pushover', 'HttpPost', 'Nagios',
46
46
  'Slack', 'FlowDock', 'Zabbix']
47
47
  ]
48
48
  )
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'shellwords'
3
2
 
4
3
  module Backup
5
4
  module Database
@@ -88,7 +88,7 @@ module Backup
88
88
  end
89
89
 
90
90
  def password_option
91
- "PGPASSWORD='#{ password }' " if password
91
+ "PGPASSWORD=#{ Shellwords.escape(password) } " if password
92
92
  end
93
93
 
94
94
  def sudo_option
@@ -96,7 +96,7 @@ module Backup
96
96
  end
97
97
 
98
98
  def username_option
99
- "--username='#{ username }'" if username
99
+ "--username=#{ Shellwords.escape(username) }" if username
100
100
  end
101
101
 
102
102
  def connectivity_options
@@ -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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Backup
4
- VERSION = '4.0.4'
4
+ VERSION = '4.0.5'
5
5
  end
@@ -0,0 +1,12 @@
1
+ ##
2
+ # PagerDuty [Notifier]
3
+ #
4
+
5
+ notify_by PagerDuty do |pagerduty|
6
+ pagerduty.on_success = true
7
+ pagerduty.on_warning = true
8
+ pagerduty.on_failure = true
9
+
10
+ pagerduty.service_key = '0123456789abcdef01234567890abcde'
11
+ pagerduty.resolve_on_warning = true
12
+ end
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
4
+ version: 4.0.5
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-08-26 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -416,6 +416,20 @@ dependencies:
416
416
  - - '='
417
417
  - !ruby/object:Gem::Version
418
418
  version: 1.3.0
419
+ - !ruby/object:Gem::Dependency
420
+ name: pagerduty
421
+ requirement: !ruby/object:Gem::Requirement
422
+ requirements:
423
+ - - '='
424
+ - !ruby/object:Gem::Version
425
+ version: 2.0.0
426
+ type: :runtime
427
+ prerelease: false
428
+ version_requirements: !ruby/object:Gem::Requirement
429
+ requirements:
430
+ - - '='
431
+ - !ruby/object:Gem::Version
432
+ version: 2.0.0
419
433
  - !ruby/object:Gem::Dependency
420
434
  name: polyglot
421
435
  requirement: !ruby/object:Gem::Requirement
@@ -596,6 +610,7 @@ files:
596
610
  - lib/backup/notifier/http_post.rb
597
611
  - lib/backup/notifier/mail.rb
598
612
  - lib/backup/notifier/nagios.rb
613
+ - lib/backup/notifier/pagerduty.rb
599
614
  - lib/backup/notifier/prowl.rb
600
615
  - lib/backup/notifier/pushover.rb
601
616
  - lib/backup/notifier/slack.rb
@@ -649,6 +664,7 @@ files:
649
664
  - templates/cli/notifiers/http_post
650
665
  - templates/cli/notifiers/mail
651
666
  - templates/cli/notifiers/nagios
667
+ - templates/cli/notifiers/pagerduty
652
668
  - templates/cli/notifiers/prowl
653
669
  - templates/cli/notifiers/pushover
654
670
  - templates/cli/notifiers/slack