pingdominator 0.0.0
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.
- data/lib/pingdominator/built-in.rb +46 -0
- data/lib/pingdominator/check.rb +73 -0
- data/lib/pingdominator/config.rb +59 -0
- data/lib/pingdominator/examples/Capfile +4 -0
- data/lib/pingdominator/examples/config/deploy/staging.rb +7 -0
- data/lib/pingdominator/examples/config/deploy.rb +12 -0
- data/lib/pingdominator/pingdom.rb +59 -0
- data/lib/pingdominator.rb +6 -0
- metadata +118 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
set :pingdom_api_root, "https://api.pingdom.com/api/2.0"
|
2
|
+
set :pingdom_appkey, "xm0egh7qc2mavn2k2v2c68i39pnv4idg"
|
3
|
+
set :pingdom_check_interval, "1" # minutes
|
4
|
+
|
5
|
+
def list_checks
|
6
|
+
capture(
|
7
|
+
"curl", "--request", "GET", "--silent",
|
8
|
+
"--header", "\"App-Key: #{fetch(:pingdom_appkey)}\"",
|
9
|
+
"--user", "\"#{fetch(:pingdom_userpass)}\"",
|
10
|
+
"\"#{fetch(:pingdom_api_root)}/checks\""
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def list_check(id)
|
15
|
+
capture(
|
16
|
+
"curl", "--request", "GET", "--silent",
|
17
|
+
"--header", "\"App-Key: #{fetch(:pingdom_appkey)}\"",
|
18
|
+
"--user", "\"#{fetch(:pingdom_userpass)}\"",
|
19
|
+
"\"#{fetch(:pingdom_api_root)}/checks/#{id.to_s}\""
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_check(id)
|
24
|
+
capture(
|
25
|
+
"curl", "--request", "DELETE", "--silent",
|
26
|
+
"--header", "\"App-Key: #{fetch(:pingdom_appkey)}\"",
|
27
|
+
"--user", "\"#{fetch(:pingdom_userpass)}\"",
|
28
|
+
"\"#{fetch(:pingdom_api_root)}/checks/#{id.to_s}\""
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_check
|
33
|
+
capture(
|
34
|
+
"curl", "--request", "POST", "--silent",
|
35
|
+
"--header", "\"App-Key: #{fetch(:pingdom_appkey)}\"",
|
36
|
+
"--user", "\"#{fetch(:pingdom_userpass)}\"",
|
37
|
+
"\"#{fetch(:pingdom_api_root)}/checks" +
|
38
|
+
"?name=#{host}" +
|
39
|
+
"&url=#{fetch(:pingdom_check_path)}" +
|
40
|
+
"&alert_policy=#{fetch(:pingdom_alert_policy_id)}" +
|
41
|
+
"&type=#{fetch(:pingdom_check_type)}" +
|
42
|
+
"&host=#{host}" +
|
43
|
+
"&encryption=#{fetch(:pingdom_check_https).to_s}" +
|
44
|
+
"&resolution=#{fetch(:pingdom_check_interval)}\""
|
45
|
+
)
|
46
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
namespace :pingdom do
|
2
|
+
namespace :check do
|
3
|
+
|
4
|
+
desc 'Ensure all pingdominator specific settings are set, and warn and exit if not.'
|
5
|
+
task :settings do
|
6
|
+
{
|
7
|
+
(File.dirname(__FILE__) + "/examples/config/deploy.rb") => 'config/deploy.rb',
|
8
|
+
(File.dirname(__FILE__) + "/examples/config/deploy/staging.rb") => "config/deploy/#{fetch(:stage)}.rb"
|
9
|
+
}.each do |abs, rel|
|
10
|
+
Rake::Task['deployinator:settings'].invoke(abs, rel)
|
11
|
+
Rake::Task['deployinator:settings'].reenable
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :settings do
|
16
|
+
desc 'Print example pingdominator specific settings for comparison.'
|
17
|
+
task :print do
|
18
|
+
set :print_all, true
|
19
|
+
Rake::Task['pingdom:check:settings'].invoke
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Check the alert status"
|
26
|
+
task :status => :check do
|
27
|
+
on roles(:pingdom) do |host|
|
28
|
+
fetch(:pingdom_checks).each do |check|
|
29
|
+
results = JSON.parse list_check(check['id'])
|
30
|
+
info JSON.pretty_generate(results)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
task :set_output_verbosity do
|
36
|
+
set :old_output_verbosity, SSHKit.config.output_verbosity
|
37
|
+
if fetch(:debug)
|
38
|
+
SSHKit.config.output_verbosity = Logger::DEBUG
|
39
|
+
else
|
40
|
+
SSHKit.config.output_verbosity = Logger::INFO
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
after 'pingdom:setup:force', :unset_output_verbosity do
|
45
|
+
SSHKit.config.output_verbosity = fetch(:old_output_verbosity)
|
46
|
+
end
|
47
|
+
|
48
|
+
#desc "Check if the alert exists"
|
49
|
+
task :check => [:set_output_verbosity, 'pingdom:check:settings'] do
|
50
|
+
require 'json'
|
51
|
+
run_locally { warn "No #{fetch(:stage)} servers have been given the 'pingdom' role!" unless roles(:pingdom).length > 0 }
|
52
|
+
on roles(:pingdom) do |host|
|
53
|
+
results = JSON.parse list_checks
|
54
|
+
set :pingdom_checks, results['checks'].select { |chk| chk['hostname'] == host.to_s }
|
55
|
+
case
|
56
|
+
when fetch(:pingdom_checks).length > 1
|
57
|
+
warn "There are #{fetch(:pingdom_checks).length} Pingdom alert for this domain! (You may want to manually correct this.) They are:"
|
58
|
+
fetch(:pingdom_checks).each { |a| warn "Name: #{a['name']}, Host: #{a['hostname']}, Type: #{a['type']}, ID: #{a['id']}" }
|
59
|
+
warn ""
|
60
|
+
warn "You can use pingdom:setup:force to be offered to delete and re-create each alert."
|
61
|
+
info "Alert for #{host} is already setup."
|
62
|
+
set :pingdom_alert_exists, true
|
63
|
+
when fetch(:pingdom_checks).length == 1
|
64
|
+
set :pingdom_alert_exists, true
|
65
|
+
info "One pingdom alert found."
|
66
|
+
when fetch(:pingdom_checks).length == 0
|
67
|
+
set :pingdom_alert_exists, false
|
68
|
+
info "No pingdom alert found."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module TaskEnhancements
|
3
|
+
alias_method :pingdom_original_default_tasks, :default_tasks
|
4
|
+
def default_tasks
|
5
|
+
pingdom_original_default_tasks + [
|
6
|
+
"pingdominator:write_built_in",
|
7
|
+
"pingdominator:write_example_configs",
|
8
|
+
"pingdominator:write_example_configs:in_place"
|
9
|
+
]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :pingdominator do
|
15
|
+
|
16
|
+
set :example, "_example"
|
17
|
+
|
18
|
+
desc "Write example config files (with '_example' appended to their names)."
|
19
|
+
task :write_example_configs do
|
20
|
+
run_locally do
|
21
|
+
execute "mkdir", "-p", "config/deploy"
|
22
|
+
{
|
23
|
+
"examples/Capfile" => "Capfile#{fetch(:example)}",
|
24
|
+
"examples/config/deploy.rb" => "config/deploy#{fetch(:example)}.rb",
|
25
|
+
"examples/config/deploy/staging.rb" => "config/deploy/staging#{fetch(:example)}.rb"
|
26
|
+
}.each do |source, destination|
|
27
|
+
config = File.read(File.dirname(__FILE__) + "/#{source}")
|
28
|
+
File.open("./#{destination}", 'w') { |f| f.write(config) }
|
29
|
+
info "Wrote '#{destination}'"
|
30
|
+
end
|
31
|
+
unless fetch(:example).empty?
|
32
|
+
info "Now remove the '#{fetch(:example)}' portion of their names or diff with existing files and add the needed lines."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Write example config files (will overwrite any existing config files).'
|
38
|
+
namespace :write_example_configs do
|
39
|
+
task :in_place do
|
40
|
+
set :example, ""
|
41
|
+
Rake::Task['pingdominator:write_example_configs'].invoke
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Write a file showing the built-in overridable settings.'
|
46
|
+
task :write_built_in do
|
47
|
+
run_locally do
|
48
|
+
{
|
49
|
+
'built-in.rb' => 'built-in.rb',
|
50
|
+
}.each do |source, destination|
|
51
|
+
config = File.read(File.dirname(__FILE__) + "/#{source}")
|
52
|
+
File.open("./#{destination}", 'w') { |f| f.write(config) }
|
53
|
+
info "Wrote '#{destination}'"
|
54
|
+
end
|
55
|
+
info "Now examine the file and copy-paste into your deploy.rb or <stage>.rb and customize."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
##### pingdominator
|
2
|
+
### ------------------------------------------------------------------
|
3
|
+
set :domain, "my-app.example.com"
|
4
|
+
server fetch(:domain),
|
5
|
+
:user => fetch(:deployment_username),
|
6
|
+
:roles => ["pingdom"]
|
7
|
+
### ------------------------------------------------------------------
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# config valid only for Capistrano 3.2.1
|
2
|
+
lock '3.2.1'
|
3
|
+
|
4
|
+
##### pingdominator
|
5
|
+
### ------------------------------------------------------------------
|
6
|
+
set :deployment_username, "deployer"
|
7
|
+
set :pingdom_userpass, "pingdom@example.com:mypassword"
|
8
|
+
set :pingdom_check_path, '/login' # this MUST be single quoted not double quoted (because of slashes)
|
9
|
+
set :pingdom_check_type, "http" # http, ping, (others)
|
10
|
+
set :pingdom_check_https, true # check on https 443 or http 80
|
11
|
+
set :pingdom_alert_policy_id, "1234567" # find this in your browser URL in your pingdom account
|
12
|
+
### ------------------------------------------------------------------
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# TODO prevent down api from breaking deploys
|
2
|
+
namespace :pingdom do
|
3
|
+
|
4
|
+
namespace :setup do
|
5
|
+
|
6
|
+
desc "Offer to remove any existing alert(s) and (re)create"
|
7
|
+
task :force => :check do
|
8
|
+
on roles(:pingdom) do |host|
|
9
|
+
set :not_deleted, false
|
10
|
+
if fetch(:pingdom_alert_exists)
|
11
|
+
fetch(:pingdom_checks).each do |check|
|
12
|
+
warn "Deleting #{JSON.pretty_generate(check)}"
|
13
|
+
set :yes_or_no, ""
|
14
|
+
until fetch(:yes_or_no).chomp.downcase == "yes" or fetch(:yes_or_no).chomp.downcase == "no"
|
15
|
+
ask :yes_or_no, "Are you sure?"
|
16
|
+
end
|
17
|
+
if fetch(:yes_or_no).chomp.downcase == "yes"
|
18
|
+
results = JSON.parse delete_check(check['id'])
|
19
|
+
info results['message']
|
20
|
+
else
|
21
|
+
warn "Not deleting check named #{check['name']}"
|
22
|
+
set :not_deleted, true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
if fetch(:not_deleted)
|
27
|
+
info "We'll now create a new check."
|
28
|
+
set :yes_or_no, ""
|
29
|
+
until fetch(:yes_or_no).chomp.downcase == "yes" or fetch(:yes_or_no).chomp.downcase == "no"
|
30
|
+
ask :yes_or_no, "Are you sure?"
|
31
|
+
end
|
32
|
+
unless fetch(:yes_or_no).chomp.downcase == "yes"
|
33
|
+
next
|
34
|
+
end
|
35
|
+
end
|
36
|
+
results = JSON.parse create_check
|
37
|
+
info "Successfully created Pingdom Alert # #{results['check']['id']} named #{results['check']['name']}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Ensure the alert exists"
|
43
|
+
task :setup => :check do
|
44
|
+
on roles(:pingdom) do |host|
|
45
|
+
unless fetch(:pingdom_alert_exists)
|
46
|
+
Rake::Task['pingdom:setup:force'].invoke
|
47
|
+
else
|
48
|
+
info "Alert for #{host} is already setup, moving on."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if Rake::Task.task_defined?("deploy:publishing")
|
54
|
+
if fetch(:stage) == "production"
|
55
|
+
after 'deploy:publishing', 'pingdom:setup'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pingdominator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- david amick
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: deployinator
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.1.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.1.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 10.3.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.3.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sshkit
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.5.1
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.5.1
|
78
|
+
description: Idempotently Setup Pindom Alerts during Deployment
|
79
|
+
email: davidamick@ctisolutionsinc.com
|
80
|
+
executables: []
|
81
|
+
extensions: []
|
82
|
+
extra_rdoc_files: []
|
83
|
+
files:
|
84
|
+
- lib/pingdominator.rb
|
85
|
+
- lib/pingdominator/pingdom.rb
|
86
|
+
- lib/pingdominator/check.rb
|
87
|
+
- lib/pingdominator/config.rb
|
88
|
+
- lib/pingdominator/built-in.rb
|
89
|
+
- lib/pingdominator/examples/Capfile
|
90
|
+
- lib/pingdominator/examples/config/deploy.rb
|
91
|
+
- lib/pingdominator/examples/config/deploy/staging.rb
|
92
|
+
homepage: https://github.com/snarlysodboxer/pingdominator
|
93
|
+
licenses:
|
94
|
+
- GNU
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.9.3
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements:
|
112
|
+
- curl (on the hosts)
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.23.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Capistrano Plugin to Setup Pindom Alerts
|
118
|
+
test_files: []
|