pagerduty 1.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/.document +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.md +34 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/lib/pagerduty.rb +63 -0
- metadata +105 -0
data/.document
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Envato & Charlie Somerville
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
pagerduty
|
2
|
+
=========
|
3
|
+
|
4
|
+
Provides a simple interface for calling into the [Pagerduty](http://pagerduty.com) API.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Make sure you have installed the two gems that pagerduty depends on: `json` and `curb`. Then install pagerduty with this command:
|
10
|
+
|
11
|
+
gem install pagerduty
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
Pagerduty exposes three classes, `Pagerduty`, `PagerdutyIncident` and `PagerdutyException`. Instances of `PagerdutyIncident` are created and returned for every API call.
|
17
|
+
|
18
|
+
`Pagerduty`'s constructor takes a single argument - your `service_key`. You can then use the method `trigger` to trigger a new incident with Pagerduty:
|
19
|
+
|
20
|
+
require 'pagerduty'
|
21
|
+
p = Pagerduty.new "your_pagerduty_service_key"
|
22
|
+
incident = p.trigger "Everything went down!"
|
23
|
+
|
24
|
+
Incidents can be retriggered, acknowledged with the `PagerdutyIncident#acknowledge` method, and resolved with `PagerdutyIncident#resolve`.
|
25
|
+
|
26
|
+
Additionally, all API methods (`trigger`, `acknowledge`, `resolve`) take an optional second parameter `details`, which should be a hash containing any extra information that should be recorded with Pagerduty.
|
27
|
+
|
28
|
+
If the Pagerduty API does not return success, a `PagerdutyException` will be thrown which has the properties `pagerduty_instance` (the instance of either `Pagerduty` or `PagerdutyException` that caused the exception) and `api_response`, which is a hash representation of the JSON response from the Pagerduty API.
|
29
|
+
|
30
|
+
Copyright
|
31
|
+
---------
|
32
|
+
|
33
|
+
Copyright (c) 2010 [Envato](http://envato.com) & [Charlie Somerville](http://charliesomerville.com). See LICENSE.txt for further details.
|
34
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "pagerduty"
|
16
|
+
gem.homepage = "http://github.com/envato/pagerduty"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = "Pagerduty API client library"
|
19
|
+
gem.description = "Provides a simple interface for calling into the Pagerduty API"
|
20
|
+
gem.email = "charlie@charliesomerville.com"
|
21
|
+
gem.authors = ["charliesome"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/rdoctask'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
+
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = "pagerduty #{version}"
|
35
|
+
rdoc.rdoc_files.include('README*')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/pagerduty.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'curb'
|
3
|
+
|
4
|
+
class PagerdutyException < Exception
|
5
|
+
attr_reader :pagerduty_instance, :api_response
|
6
|
+
|
7
|
+
def initialize(instance, resp)
|
8
|
+
@pagerduty_instance = instance
|
9
|
+
@api_response = resp
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Pagerduty
|
14
|
+
|
15
|
+
attr_reader :service_key, :incident_key
|
16
|
+
|
17
|
+
def initialize(service_key)
|
18
|
+
@service_key = service_key
|
19
|
+
@incident_key = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def trigger(description, details = {})
|
23
|
+
resp = api_call("trigger", description, details = {})
|
24
|
+
throw PagerdutyException.new(self, resp) unless resp["status"] == "success"
|
25
|
+
|
26
|
+
PagerdutyIncident.new @service_key, resp["incident_key"]
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def api_call(event_type, description, details = {})
|
31
|
+
params = { :event_type => event_type, :service_key => @service_key, :description => description, :details => details }
|
32
|
+
params.merge!({ :incident_key => @incident_key }) unless @incident_key == nil
|
33
|
+
|
34
|
+
curl = Curl::Easy.new
|
35
|
+
curl.url = "http://events.pagerduty.com/generic/2010-04-15/create_event.json"
|
36
|
+
curl.http_post JSON.generate(params)
|
37
|
+
JSON.parse curl.body_str
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
class PagerdutyIncident < Pagerduty
|
43
|
+
|
44
|
+
def initialize(service_key, incident_key)
|
45
|
+
super service_key
|
46
|
+
@incident_key = incident_key
|
47
|
+
end
|
48
|
+
|
49
|
+
def acknowledge(description, details = {})
|
50
|
+
resp = api_call("acknowledge", description, details = {})
|
51
|
+
throw PagerdutyException.new(self, resp) unless resp["status"] == "success"
|
52
|
+
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def resolve(description, details = {})
|
57
|
+
resp = api_call("resolve", description, details = {})
|
58
|
+
throw PagerdutyException.new(self, resp) unless resp["status"] == "success"
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pagerduty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- charliesome
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-16 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 23
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
name: bundler
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 1
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 5
|
47
|
+
- 1
|
48
|
+
version: 1.5.1
|
49
|
+
type: :development
|
50
|
+
name: jeweler
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Provides a simple interface for calling into the Pagerduty API
|
54
|
+
email: charlie@charliesomerville.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- LICENSE.txt
|
61
|
+
- README.md
|
62
|
+
files:
|
63
|
+
- .document
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- lib/pagerduty.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/envato/pagerduty
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Pagerduty API client library
|
104
|
+
test_files: []
|
105
|
+
|