redphone 0.0.4 → 0.0.5
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/README.org +30 -3
- data/lib/redphone/helpers.rb +10 -4
- data/lib/redphone/loggly.rb +19 -5
- data/lib/redphone/pagerduty.rb +11 -9
- data/lib/redphone/pingdom.rb +72 -0
- data/lib/redphone/version.rb +1 -1
- data/test/loggly_test.rb +10 -2
- data/test/pagerduty_test.rb +3 -3
- data/test/pingdom_test.rb +59 -0
- metadata +11 -8
data/README.org
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
* Redphone, the monitoring service ruby library
|
2
2
|
- Pagerduty support (integration, incidents)
|
3
|
-
-
|
3
|
+
- Pingdom support (checks, results, actions)
|
4
|
+
- Loggly support (event, search, facets)
|
4
5
|
[[https://github.com/portertech/redphone/raw/master/redphone.jpg]]
|
6
|
+
- All API request are done over SSL
|
7
|
+
- Response bodies are returned as Ruby hashes
|
5
8
|
* Getting started
|
6
9
|
: gem install redphone
|
7
10
|
* Examples
|
@@ -23,12 +26,27 @@
|
|
23
26
|
: pagerduty.resolve_incident(:incident_key => "redphone/test")
|
24
27
|
: # OR Redphone::Pagerduty.resolve_incident()
|
25
28
|
List/query current and past incidents
|
26
|
-
:
|
29
|
+
: pagerduty.incidents(:incident_key => "redphone/test")
|
27
30
|
You can add the following options for a date range
|
28
31
|
: :since => "2011-08-01",
|
29
32
|
: :until => "2011-10-01"
|
30
33
|
Or if you only care about unresolved incidents
|
31
34
|
: :status => "triggered,acknowledged"
|
35
|
+
** Pingdom
|
36
|
+
: require "redphone/pingdom"
|
37
|
+
: pingdom = Redphone::Pingdom.new(
|
38
|
+
: :user => USER,
|
39
|
+
: :password => PASSWORD
|
40
|
+
: )
|
41
|
+
Create a check
|
42
|
+
: response = pingdom.create_check(
|
43
|
+
: :name => "redphone",
|
44
|
+
: :host => "www.amazon.ca",
|
45
|
+
: :type => "http"
|
46
|
+
: )
|
47
|
+
: check_id = response['check']['id']
|
48
|
+
Delete a check
|
49
|
+
: pingdom.delete_check(:id => check_id)
|
32
50
|
** Loggly
|
33
51
|
: require "redphone/loggly"
|
34
52
|
: loggly = Redphone::Loggly.new(
|
@@ -47,6 +65,15 @@
|
|
47
65
|
: )
|
48
66
|
: # OR Redphone::Loggly.send_event()
|
49
67
|
Search for previous event occurrences
|
50
|
-
:
|
68
|
+
: loggly.search(:q => "json.service:redphone")
|
69
|
+
Faceted search results on date
|
70
|
+
: loggly.facets(:q => "json.service:redphone")
|
71
|
+
Add an option for faceted search results on input name
|
72
|
+
: :facet_type => "input"
|
73
|
+
Or on IP address
|
74
|
+
: :facet_type => "ip"
|
75
|
+
You can add the following options for a date range
|
76
|
+
: :from => "2011-08-01T12:00:00Z",
|
77
|
+
: :until => "2011-10-01T12:00:00Z"
|
51
78
|
* Contributors
|
52
79
|
- [[http://portertech.ca][Sean Porter]]
|
data/lib/redphone/helpers.rb
CHANGED
@@ -11,21 +11,27 @@ def http_request(options={})
|
|
11
11
|
user = options[:user]
|
12
12
|
password = options[:password]
|
13
13
|
headers = options[:headers] || Hash.new
|
14
|
+
parameters = options[:parameters] || Hash.new
|
14
15
|
body = options[:body]
|
15
16
|
http = Net::HTTP.new(uri.host, uri.port)
|
16
17
|
if options[:ssl] == true
|
17
18
|
http.use_ssl = true
|
18
19
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
19
20
|
end
|
21
|
+
request_uri = uri.request_uri
|
22
|
+
unless parameters.empty?
|
23
|
+
request_uri += "?"
|
24
|
+
request_uri += parameters.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
25
|
+
end
|
20
26
|
request = case method
|
21
27
|
when "get"
|
22
|
-
Net::HTTP::Get.new(
|
28
|
+
Net::HTTP::Get.new(request_uri)
|
23
29
|
when "post"
|
24
|
-
Net::HTTP::Post.new(
|
30
|
+
Net::HTTP::Post.new(request_uri)
|
25
31
|
when "put"
|
26
|
-
Net::HTTP::Put.new(
|
32
|
+
Net::HTTP::Put.new(request_uri)
|
27
33
|
when "delete"
|
28
|
-
Net::HTTP::Delete.new(
|
34
|
+
Net::HTTP::Delete.new(request_uri)
|
29
35
|
else
|
30
36
|
raise "Unknown HTTP method: #{method}"
|
31
37
|
end
|
data/lib/redphone/loggly.rb
CHANGED
@@ -3,9 +3,9 @@ require File.join(File.dirname(__FILE__), 'helpers')
|
|
3
3
|
module Redphone
|
4
4
|
class Loggly
|
5
5
|
def initialize(options={})
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
[:subdomain, :user, :password].each do |option|
|
7
|
+
raise "You must supply a #{option}" if options[option].nil?
|
8
|
+
end
|
9
9
|
@subdomain = options[:subdomain]
|
10
10
|
@user = options[:user]
|
11
11
|
@password = options[:password]
|
@@ -15,12 +15,26 @@ module Redphone
|
|
15
15
|
|
16
16
|
def search(options={})
|
17
17
|
raise "You must supply a query string" if options[:q].nil?
|
18
|
-
params = options.map { |key, value| "#{key}=#{CGI.escape(value)}" }.join("&")
|
19
18
|
response = http_request(
|
20
19
|
:user => @user,
|
21
20
|
:password => @password,
|
22
21
|
:ssl => true,
|
23
|
-
:uri => "https://#{@subdomain}.loggly.com/api/search
|
22
|
+
:uri => "https://#{@subdomain}.loggly.com/api/search",
|
23
|
+
:parameters => options
|
24
|
+
)
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def facets(options={})
|
29
|
+
raise "You must supply a query string" if options[:q].nil?
|
30
|
+
facet_type = options[:facet_type] || "date"
|
31
|
+
raise "Facet type must be date, ip, or input" if !%w[date ip input].include?(facet_type)
|
32
|
+
response = http_request(
|
33
|
+
:user => @user,
|
34
|
+
:password => @password,
|
35
|
+
:ssl => true,
|
36
|
+
:uri => "https://#{@subdomain}.loggly.com/api/facets/#{facet_type}/",
|
37
|
+
:parameters => options.reject { |key, value| key == :facet_type }
|
24
38
|
)
|
25
39
|
JSON.parse(response.body)
|
26
40
|
end
|
data/lib/redphone/pagerduty.rb
CHANGED
@@ -3,9 +3,9 @@ require File.join(File.dirname(__FILE__), 'helpers')
|
|
3
3
|
module Redphone
|
4
4
|
class Pagerduty
|
5
5
|
def initialize(options={})
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
[:subdomain, :user, :password].each do |option|
|
7
|
+
raise "You must supply a #{option}" if options[option].nil?
|
8
|
+
end
|
9
9
|
@subdomain = options[:subdomain]
|
10
10
|
@user = options[:user]
|
11
11
|
@password = options[:password]
|
@@ -23,8 +23,9 @@ module Redphone
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.trigger_incident(options={})
|
26
|
-
|
27
|
-
|
26
|
+
[:service_key, :description].each do |option|
|
27
|
+
raise "You must supply a #{option.gsub('_', ' ')}" if options[option].nil?
|
28
|
+
end
|
28
29
|
request_body = options.merge!({:event_type => "trigger"})
|
29
30
|
integration_api(request_body)
|
30
31
|
end
|
@@ -35,8 +36,9 @@ module Redphone
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def self.resolve_incident(options={})
|
38
|
-
|
39
|
-
|
39
|
+
[:service_key, :incident_key].each do |option|
|
40
|
+
raise "You must supply a #{option.gsub('_', ' ')}" if options[option].nil?
|
41
|
+
end
|
40
42
|
request_body = options.merge!({:event_type => "resolve"})
|
41
43
|
integration_api(request_body)
|
42
44
|
end
|
@@ -47,12 +49,12 @@ module Redphone
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def incidents(options={})
|
50
|
-
params = options.map { |key, value| "#{key}=#{CGI.escape(value)}" }.join("&")
|
51
52
|
response = http_request(
|
52
53
|
:user => @user,
|
53
54
|
:password => @password,
|
54
55
|
:ssl => true,
|
55
|
-
:uri => "https://#{@subdomain}.pagerduty.com/api/v1/incidents
|
56
|
+
:uri => "https://#{@subdomain}.pagerduty.com/api/v1/incidents",
|
57
|
+
:parameters => options
|
56
58
|
)
|
57
59
|
JSON.parse(response.body)
|
58
60
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helpers')
|
2
|
+
|
3
|
+
module Redphone
|
4
|
+
class Pingdom
|
5
|
+
def initialize(options={})
|
6
|
+
[:user, :password].each do |option|
|
7
|
+
raise "You must supply a #{option}" if options[option].nil?
|
8
|
+
end
|
9
|
+
@request_options = {
|
10
|
+
:user => options[:user],
|
11
|
+
:password => options[:password],
|
12
|
+
:ssl => true,
|
13
|
+
:headers => {"App-Key" => "ksectgskhysnv4wb7h0z5re2wmeqqxnd"}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_check(options={})
|
18
|
+
[:name, :host, :type].each do |option|
|
19
|
+
raise "You must supply a check #{option}" if options[option].nil?
|
20
|
+
end
|
21
|
+
response = http_request(
|
22
|
+
@request_options.merge({
|
23
|
+
:method => "post",
|
24
|
+
:uri => "https://api.pingdom.com/api/2.0/checks",
|
25
|
+
:parameters => options
|
26
|
+
})
|
27
|
+
)
|
28
|
+
JSON.parse(response.body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def checks
|
32
|
+
response = response = http_request(
|
33
|
+
@request_options.merge({
|
34
|
+
:uri => "https://api.pingdom.com/api/2.0/checks"
|
35
|
+
})
|
36
|
+
)
|
37
|
+
JSON.parse(response.body)
|
38
|
+
end
|
39
|
+
|
40
|
+
def actions(options={})
|
41
|
+
response = http_request(
|
42
|
+
@request_options.merge({
|
43
|
+
:uri => "https://api.pingdom.com/api/2.0/actions",
|
44
|
+
:parameters => options
|
45
|
+
})
|
46
|
+
)
|
47
|
+
JSON.parse(response.body)
|
48
|
+
end
|
49
|
+
|
50
|
+
def results(options={})
|
51
|
+
raise "You must supply a check id" if options[:id].nil?
|
52
|
+
response = http_request(
|
53
|
+
@request_options.merge({
|
54
|
+
:uri => "https://api.pingdom.com/api/2.0/results/#{options[:id]}",
|
55
|
+
:parameters => options.reject { |key, value| key == :id }
|
56
|
+
})
|
57
|
+
)
|
58
|
+
JSON.parse(response.body)
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete_check(options={})
|
62
|
+
raise "You must supply a check id" if options[:id].nil?
|
63
|
+
response = http_request(
|
64
|
+
@request_options.merge({
|
65
|
+
:method => "delete",
|
66
|
+
:uri => "https://api.pingdom.com/api/2.0/checks/#{options[:id]}"
|
67
|
+
})
|
68
|
+
)
|
69
|
+
JSON.parse(response.body)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/redphone/version.rb
CHANGED
data/test/loggly_test.rb
CHANGED
@@ -20,7 +20,7 @@ class TestRedphoneLoggly < MiniTest::Unit::TestCase
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def test_a_send_event
|
24
24
|
response = @loggly.send_event(
|
25
25
|
:input_key => LOGGLY_INPUT_KEY,
|
26
26
|
:input_type => "json",
|
@@ -32,8 +32,16 @@ class TestRedphoneLoggly < MiniTest::Unit::TestCase
|
|
32
32
|
assert_equal 'ok', response['response']
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def test_b_search
|
36
36
|
response = @loggly.search(:q => "json.service:redphone")
|
37
37
|
assert response['numFound'] > 0
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_c_facets
|
41
|
+
response = @loggly.facets(
|
42
|
+
:q => "json.service:redphone",
|
43
|
+
:from => "2011-10-01T12:00:00Z"
|
44
|
+
)
|
45
|
+
assert response['numFound'] > 0
|
46
|
+
end
|
39
47
|
end
|
data/test/pagerduty_test.rb
CHANGED
@@ -20,7 +20,7 @@ class TestRedphonePagerduty < MiniTest::Unit::TestCase
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def test_a_trigger_incident
|
24
24
|
response = @pagerduty.trigger_incident(
|
25
25
|
:service_key => PAGERDUTY_SERVICE_KEY,
|
26
26
|
:description => "Testing Redphone Rubygem",
|
@@ -29,7 +29,7 @@ class TestRedphonePagerduty < MiniTest::Unit::TestCase
|
|
29
29
|
assert_equal 'success', response['status']
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def test_b_resolve_incident
|
33
33
|
response = @pagerduty.resolve_incident(
|
34
34
|
:service_key => PAGERDUTY_SERVICE_KEY,
|
35
35
|
:incident_key => "redphone/test"
|
@@ -37,7 +37,7 @@ class TestRedphonePagerduty < MiniTest::Unit::TestCase
|
|
37
37
|
assert_equal 'success', response['status']
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def test_c_incidents
|
41
41
|
response = @pagerduty.incidents(:incident_key => "redphone/test")
|
42
42
|
assert response['total'] > 0
|
43
43
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
|
2
|
+
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
3
|
+
gem 'minitest'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'redphone/pingdom'
|
6
|
+
|
7
|
+
credentials = File.open("pingdom_credentials.txt", "rb").read.split("\n")
|
8
|
+
PINGDOM_USER, PINGDOM_PASSWORD = credentials.each { |row| row }
|
9
|
+
$test_check_id = nil
|
10
|
+
|
11
|
+
class TestRedphonePingdom < MiniTest::Unit::TestCase
|
12
|
+
i_suck_and_my_tests_are_order_dependent!
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@pingdom = Redphone::Pingdom.new(
|
16
|
+
:user => PINGDOM_USER,
|
17
|
+
:password => PINGDOM_PASSWORD
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_a_create_check
|
22
|
+
response = @pingdom.create_check(
|
23
|
+
:name => "redphone",
|
24
|
+
:host => "www.amazon.ca",
|
25
|
+
:type => "http"
|
26
|
+
)
|
27
|
+
$test_check_id = response['check']['id']
|
28
|
+
assert_equal "redphone", response['check']['name']
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_b_checks
|
32
|
+
response = @pingdom.checks
|
33
|
+
exists = false
|
34
|
+
assert_block(message="assert_block failed.") do
|
35
|
+
response['checks'].each do |check|
|
36
|
+
exists = true if check['name'] == "redphone"
|
37
|
+
end
|
38
|
+
exists
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_c_actions
|
43
|
+
response = @pingdom.actions(:limit => 1)
|
44
|
+
assert response.has_key?("actions")
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_d_results
|
48
|
+
response = @pingdom.results(
|
49
|
+
:id => $test_check_id,
|
50
|
+
:limit => 1
|
51
|
+
)
|
52
|
+
assert response.has_key?("results")
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_e_delete_check
|
56
|
+
response = @pingdom.delete_check(:id => $test_check_id)
|
57
|
+
assert_equal "Deletion of check was successful!", response['message']
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redphone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70239866142400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70239866142400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70239866141860 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70239866141860
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &70239866141380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70239866141380
|
47
47
|
description: A rubygem for talking to monitoring service APIs
|
48
48
|
email:
|
49
49
|
- portertech@gmail.com
|
@@ -59,11 +59,13 @@ files:
|
|
59
59
|
- lib/redphone/helpers.rb
|
60
60
|
- lib/redphone/loggly.rb
|
61
61
|
- lib/redphone/pagerduty.rb
|
62
|
+
- lib/redphone/pingdom.rb
|
62
63
|
- lib/redphone/version.rb
|
63
64
|
- redphone.gemspec
|
64
65
|
- redphone.jpg
|
65
66
|
- test/loggly_test.rb
|
66
67
|
- test/pagerduty_test.rb
|
68
|
+
- test/pingdom_test.rb
|
67
69
|
homepage: https://github.com/portertech/redphone
|
68
70
|
licenses: []
|
69
71
|
post_install_message:
|
@@ -91,3 +93,4 @@ summary: A rubygem for talking to monitoring service APIs
|
|
91
93
|
test_files:
|
92
94
|
- test/loggly_test.rb
|
93
95
|
- test/pagerduty_test.rb
|
96
|
+
- test/pingdom_test.rb
|