statuspage 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZThkZDk0MTZhMDBkMDQzMGQ3M2Q4OGU5MGUyZTExNTVmMjAxOTZiYQ==
5
+ data.tar.gz: !binary |-
6
+ ODFhYzQ1MTcyM2Y1MjBmZjBkZGQxMGFhNjlkODVjOTBiOGZkOTBmNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MTA1MzM0MzUzOWYxM2RjY2NmNjIyODBlYjA5M2JmNjA5ZjBhNzdlNTRjYmZj
10
+ MDhjNmRhOWM2MjU5ZjU5NDMzOTBmYjc0MTQ4NzQ1Y2U5MGZmZTg3ZTY1ZmE4
11
+ OTRmMjhlNTVkZDMzYWM0NTNhMGVjOWM0MDdjZWI0YjM3ZTJlMmY=
12
+ data.tar.gz: !binary |-
13
+ ZGY2NmFiMGY5NTRkZGRlNTI1Y2Q2NzQ2ZWNmODBlYTU3ODc2ZWYxYzIzNzVl
14
+ YmVjNGMzZmVmMjI4OWJmNGIyMzhjZDEyZmFhNWQxNjkyYjQwYzYyNzY4MWFk
15
+ OTg4M2I2M2MxMGRmNjViZWMwYjhkMmE2ZmMzMDk4MDllNWQxNzk=
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.swp
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in statuspage.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Richard King
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Statuspage
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'statuspage'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install statuspage
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path("../../lib/statuspage", __FILE__)
4
+
5
+ StatusPage.new(ARGV)
@@ -0,0 +1,128 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'yaml'
4
+
5
+ class StatusPage
6
+ COMPONENT_STATUSES = ["operational", "degraded performance", "partial outage", "major outage"]
7
+ INCIDENT_STATUSES = ["investigating", "identified", "monitoring", "resolved"]
8
+
9
+ def initialize(args=nil)
10
+ @config = File.expand_path("~/statuspage.yml")
11
+ @components = {}
12
+ load_config
13
+ load_components
14
+ start(args) if args
15
+ end
16
+
17
+ def load_config
18
+ config = YAML.load(File.open @config)
19
+ @oauth = config['oauth']
20
+ @base_url = config['base_url']
21
+ @page = config['page']
22
+ end
23
+
24
+ def load_components
25
+ httparty_send(:get, "#{@base_url}#{@page}/components.json").each {|c| @components[c['name'].downcase] = c['id'] }
26
+ end
27
+
28
+ def start(args=[])
29
+ command = args.shift
30
+ if self.respond_to? command
31
+ send(command, *args)
32
+ else
33
+ puts "Command not recognized"
34
+ end
35
+ end
36
+
37
+ # components - show status of all components
38
+ # components <component_name> - show status of specific component
39
+ # components <component_name> <status> - set the status for a component
40
+ def components(*args)
41
+ component_name_valid?(args[0]) unless args.empty?
42
+ if args.empty?
43
+ results = httparty_send :get, "#{@base_url}#{@page}/components.json"
44
+ puts results
45
+ results
46
+ elsif args.size == 1
47
+ component_name = @components.keys.grep(/#{args[0].downcase}/).first
48
+ component_id = @components["#{component_name}"]
49
+
50
+ results = httparty_send :get, "#{@base_url}#{@page}/components.json"
51
+ component = results.select{|c| c['id'] == component_id}.first
52
+ puts "Status of #{component['name']}: #{component['status'].gsub('_',' ')}"
53
+ else
54
+ valid_component_status?(args[1])
55
+ component_name = @components.keys.grep(/#{args[0].downcase}/).first
56
+ component_id = @components["#{component_name}"]
57
+ component_new_status = COMPONENT_STATUSES.grep(/#{args[1].downcase}/).first
58
+ url = "#{@base_url}#{@page}/components/#{component_id}.json"
59
+
60
+ results = httparty_send :patch, url, :body => {"component[status]" => component_new_status.gsub(' ', '_')}
61
+ puts "Status for #{component_name} is now #{results['status'].gsub('_',' ')}"
62
+ end
63
+ end
64
+
65
+ # incidents - show json of all incidents
66
+ # incidents open <incident_name> <incident_status> <incident_message> - create new incident
67
+ # incidents update <incident_status> <incident_message> - update last open incident with new status/message
68
+ def incidents(*args)
69
+ if args.empty?
70
+ results = httparty_send :get, "#{@base_url}#{@page}/incidents.json"
71
+ incidents = results.reject {|i| ['resolved', 'postmortem', 'completed'].include? i['status']}
72
+ if incidents.empty?
73
+ puts "All clear, no unresolved incidents!"
74
+ else
75
+ puts "Unresolved incidents:"
76
+ incidents.each do |i|
77
+ puts "#{i['name']} - status: #{i['status']}, created at #{i['created_at']}"
78
+ end
79
+ end
80
+ elsif args[0] == 'open'
81
+ valid_incident_status?(args[2])
82
+ options = { :body => { "incident[name]" => args[1], "incident[status]" => args[2], "incident[message]" => args[3] } }
83
+ results = httparty_send :post, "#{@base_url}#{@page}/incidents.json", options
84
+ puts results
85
+ elsif args[0] == 'update'
86
+ latest_incident = incidents.reject {|i| ['resolved', 'postmortem', 'completed'].include? i['status']}.first
87
+ if latest_incident.nil?
88
+ puts "No open incidents"
89
+ else
90
+ valid_incident_status?(args[1])
91
+ options = { :body => { "incident[status]" => args[1], "incident[message]" => args[2] } }
92
+ results = httparty_send :patch, "#{@base_url}#{@page}/incidents/#{latest_incident['id']}.json", options
93
+ puts results
94
+ end
95
+ else
96
+ puts "Invalid command"
97
+ end
98
+ end
99
+
100
+ private
101
+
102
+ def component_name_valid?(name)
103
+ unless @components.keys.detect {|n| n =~ /#{name}/}
104
+ puts "Invalid component name"
105
+ exit
106
+ end
107
+ true
108
+ end
109
+
110
+ def valid_component_status?(status)
111
+ unless COMPONENT_STATUSES.grep(/#{status}/)
112
+ raise "#{status} is not a valid component status. Please pick one of the following: #{COMPONENT_STATUSES.to_s}"
113
+ end
114
+ true
115
+ end
116
+
117
+ def valid_incident_status?(status)
118
+ unless INCIDENT_STATUSES.include? status
119
+ raise "#{status} is not a valid incident status. Please pick one of the following: #{INCIDENT_STATUSES.to_s}"
120
+ end
121
+ true
122
+ end
123
+
124
+ def httparty_send(action, url, options={})
125
+ options.merge!(:headers => { "Authorization: OAuth" => @oauth })
126
+ HTTParty.send(action, url, options)
127
+ end
128
+ end
@@ -0,0 +1,3 @@
1
+ module Statuspage
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statuspage/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "statuspage"
8
+ spec.version = Statuspage::VERSION
9
+ spec.authors = ["Richard King"]
10
+ spec.email = ["rkingucla@ymail.com"]
11
+ spec.description = %q{ruby wrapper for statuspage.io api}
12
+ spec.summary = %q{ruby wrapper for statuspage.io api}
13
+ spec.homepage = "https://github.com/richardking/statuspagerb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "httparty"
24
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statuspage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard King
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ruby wrapper for statuspage.io api
56
+ email:
57
+ - rkingucla@ymail.com
58
+ executables:
59
+ - statuspage
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/statuspage
69
+ - lib/statuspage.rb
70
+ - lib/statuspage/version.rb
71
+ - statuspage.gemspec
72
+ homepage: https://github.com/richardking/statuspagerb
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.5
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: ruby wrapper for statuspage.io api
96
+ test_files: []