lita-pagerduty-oncall 0.0.1

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/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Ben Rockwood
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # lita-pagerduty-oncall
2
+
3
+ PagerDuty (http://pagerduty.com) handler for checking who's on call.
4
+
5
+ This handler has no external dependancies. It directly calls the PagerDuty API via HTTPS.
6
+
7
+ I created it because the various PagerDuty Lita handlers didn't suppor the functionality we cared about most. Furthermore I learned that this is because the PagerDuty Ruby Gems they are based on don't implemented it. Harlan Barnes solved this problem as well (https://github.com/harlanbarnes/lita-pagerduty, see branch "issue-3") but his patch outputs contact information for persons who are oncall, rather than showing the oncall escalation tree.
8
+
9
+ This is my first non-trivial Lita Handler, for the time being it is a work in progress. Be ye thus warned.
10
+
11
+ ## Installation
12
+
13
+ This handler isn't yet packaged as a Gem. If you wish to try it, git clone this repo in your Lita directory and add the following line to your Gemfile:
14
+
15
+ ``` ruby
16
+ gem "lita-pagerduty-oncall", :path => "lita-pagerduty-oncall/"
17
+ ```
18
+
19
+ Then run "bundle install".
20
+
21
+ ## Configuration
22
+
23
+ Add the following variables to your Lita config file:
24
+
25
+ ``` ruby
26
+ config.handlers.pagerduty_oncall.api_key = ''
27
+ config.handlers.pagerduty_oncall.subdomain = ''
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ Invoke with the "oncall" command:
33
+
34
+ ```
35
+ @BotName oncall
36
+ ```
37
+
38
+ Exmaple output seen in room:
39
+
40
+ ```
41
+ Testing:
42
+ 1: Paul Paulison (static)
43
+
44
+ Dev Escalation:
45
+ 1: Bob Smith (02/02/15 08:00 - 02/09/15 08:00 UTC)
46
+
47
+ IT Support:
48
+ -- Empty Rotation --
49
+
50
+ Operations:
51
+ 1: Josh Johnson (02/02/15 17:00 - 02/09/15 17:00 UTC)
52
+ 2: Ian Iradium (02/02/15 16:00 - 02/09/15 16:00 UTC)
53
+ 3: Stephen Summers (02/03/15 02:00 - 02/06/15 02:00 UTC)
54
+ ```
55
+
56
+ ## License
57
+
58
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/pagerduty_oncall"
8
+
9
+ Lita::Handlers::PagerdutyOncall.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,86 @@
1
+ require "time"
2
+ require "json"
3
+ require "net/http"
4
+
5
+ module Lita
6
+ module Handlers
7
+ class PagerdutyOncall < Handler
8
+
9
+ route(
10
+ /^oncall$/,
11
+ :print_oncall,
12
+ command: true,
13
+ help: { }
14
+ )
15
+
16
+ def print_oncall(resp)
17
+ oc = pdapi_get_oc
18
+ fmt = parse_escalation_policy(oc)
19
+ resp.reply(fmt)
20
+ end
21
+
22
+ def self.default_config(config)
23
+ config.api_key = nil
24
+ config.subdomain = nil
25
+ end
26
+
27
+ def base_url
28
+ "https://#{subdomain}.pagerduty.com/api/v1"
29
+ end
30
+
31
+ def subdomain
32
+ Lita.config.handlers.pagerduty_oncall.subdomain
33
+ end
34
+
35
+ def api_key
36
+ Lita.config.handlers.pagerduty_oncall.api_key
37
+ end
38
+
39
+ def pdapi_get_oc
40
+ #base_url = "https://#{subdomain}.pagerduty.com/api/v1"
41
+ uri = URI("#{base_url}/escalation_policies/on_call")
42
+
43
+ req = Net::HTTP::Get.new(uri)
44
+ req.add_field("Content-type", "application/json")
45
+ req.add_field("Authorization", "Token token=#{api_key}")
46
+
47
+ res = Net::HTTP.start(uri.host, uri.port,
48
+ :use_ssl => uri.scheme == 'https') do |http|
49
+ http.request(req)
50
+ end
51
+ res.body
52
+ end
53
+
54
+ def parse_escalation_policy(json_resp)
55
+ fmt = ""
56
+ JSON.parse(json_resp)["escalation_policies"].each do |p|
57
+ fmt.concat("#{p["name"]}:\n")
58
+
59
+ count = 0
60
+ p["on_call"].each do |oc|
61
+ oc_time = "" ##### "#{oc["start"]} - #{oc["end"]}"
62
+ if oc["start"].to_s.empty?
63
+ oc_time = "static"
64
+ else
65
+ stime = Time.parse(oc["start"]).strftime("%m/%d/%y %H:%M")
66
+ etime = Time.parse(oc["end"]).strftime("%m/%d/%y %H:%M %Z")
67
+ oc_time = "#{stime} - #{etime}"
68
+ end
69
+
70
+ fmt.concat(" #{oc["level"]}: #{oc["user"]["name"]} (#{oc_time})\n")
71
+ count += 1
72
+ end #/p.each
73
+
74
+ if count == 0
75
+ fmt.concat(" -- Empty Rotation --\n")
76
+ end
77
+ fmt.concat("\n")
78
+ end #/JSON.prase
79
+ fmt
80
+ end #/def
81
+
82
+ end #/Class
83
+
84
+ Lita.register_handler(PagerdutyOncall)
85
+ end #/Module
86
+ end
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-pagerduty-oncall"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Ben Rockwood"]
5
+ spec.email = ["benr@joyent.com"]
6
+ spec.description = %q{Calls pager duty api to find who is oncall}
7
+ spec.summary = %q{Lita Pager Duty plugin}
8
+ spec.homepage = "https://github.com/GaryCarneiro/lita-pagerduty-oncall"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", ">= 4.2"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rack-test"
21
+ spec.add_development_dependency "rspec", ">= 3.0.0"
22
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ pagerduty_oncall:
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::PagerdutyOncall, lita_handler: true do
4
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-pagerduty-oncall"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-pagerduty-oncall
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ben Rockwood
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2015-04-03 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: lita
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 31
30
+ segments:
31
+ - 4
32
+ - 2
33
+ version: "4.2"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 9
45
+ segments:
46
+ - 1
47
+ - 3
48
+ version: "1.3"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rake
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rack-test
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 7
88
+ segments:
89
+ - 3
90
+ - 0
91
+ - 0
92
+ version: 3.0.0
93
+ type: :development
94
+ version_requirements: *id005
95
+ description: Calls pager duty api to find who is oncall
96
+ email:
97
+ - benr@joyent.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files: []
103
+
104
+ files:
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - lib/lita-pagerduty-oncall.rb
110
+ - lib/lita/handlers/pagerduty_oncall.rb
111
+ - lita-pagerduty-oncall.gemspec
112
+ - locales/en.yml
113
+ - spec/lita/handlers/pagerduty_oncall_spec.rb
114
+ - spec/spec_helper.rb
115
+ - templates/.gitkeep
116
+ has_rdoc: true
117
+ homepage: https://github.com/GaryCarneiro/lita-pagerduty-oncall
118
+ licenses:
119
+ - MIT
120
+ post_install_message:
121
+ rdoc_options: []
122
+
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ hash: 3
140
+ segments:
141
+ - 0
142
+ version: "0"
143
+ requirements: []
144
+
145
+ rubyforge_project:
146
+ rubygems_version: 1.3.7
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Lita Pager Duty plugin
150
+ test_files:
151
+ - spec/lita/handlers/pagerduty_oncall_spec.rb
152
+ - spec/spec_helper.rb