stashboard-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e28d6db972c33a1f1693f13a3bc910c1306261e5
4
+ data.tar.gz: 687361e79130eeafd1b60c88cc5b563be84d56a7
5
+ SHA512:
6
+ metadata.gz: c3240f9555c430b4b8c1041efd6b0a966f62113dc0d2485789fb1ac85a9b64357741a7a6bc73b4bb68292d2c47bcf1d3722371f8d754707379be27527328b36d
7
+ data.tar.gz: da535101c27dc2f27a05d100ce7ec037f9f271a709523674c2899406ae5f770a000997b2602d7db017d800e129b7f120111063267fd48d490609f4ceac4899c7
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ doc/*
5
+ .yardoc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in stashboard.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stashboard (0.0.1)
5
+ oauth (>= 0.4.4)
6
+ yajl-ruby (>= 0.8.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ oauth (0.4.4)
12
+ yajl-ruby (0.8.1)
13
+ yard (0.6.4)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ oauth (>= 0.4.4)
20
+ stashboard!
21
+ yajl-ruby (>= 0.8.1)
22
+ yard (>= 0.6.4)
@@ -0,0 +1,158 @@
1
+ # Updated Stashboard gem
2
+
3
+ Simple little ruby library for interacting with a Stashboard instance
4
+ ([http://www.stashboard.org](http://www.stashboard.org).
5
+
6
+ Stashboard is a Python application designed to be run on the Google App Engine,
7
+ which provides a system status type page for your application similar to the
8
+ status pages offered by [Amazon AWS](http://status.aws.amazon.com/), or
9
+ [Google Apps](http://www.google.com/appsstatus).
10
+
11
+ This library doesn't address setting up your Stashboard instance, but
12
+ simplifies interacting with it from Ruby.
13
+
14
+ This is an updated version of the stashboard gem from [Sam Mulbe](https://github.com/smulube/stashboard-ruby), with fixes from [Brian Stolz](https://github.com/tecnobrat/stashboard-ruby). This new gem has been created to implement some much-needed updates, as the previous gem is no longer being actively maintained.
15
+
16
+ I've tried to add some extra set-up instructions to the below usage to help beginners aswell.
17
+
18
+ # Setup
19
+
20
+ ### 1. Download the SDK
21
+ Download the latest [Python SDK for Google App Engine](http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Python).
22
+
23
+ ### 2. Get the project
24
+ Download and extract the [Stashboard project](http://github.com/twilio/stashboard/tarball/master) to your computer.
25
+
26
+ ### 3. Run Locally
27
+ Open the SDK, choose
28
+ ```
29
+ File > Add Existing Application...
30
+ ```
31
+
32
+ Navigate to:
33
+ ```
34
+ Propject folder > stashboard
35
+ ```
36
+ Select open, press Run and navigate to *http://localhost:{port}* to see your Stashboard installation.
37
+
38
+ ### 4. Deploy to AppSpot
39
+ 4.1. [Sign up for an AppSpot account](https://developers.google.com/appengine/docs/python/gettingstartedpython27/uploading?csw=1).
40
+
41
+ 4.2. Create an application within AppSpot - specifying Python as the language.
42
+
43
+ 4.3. Update your *app.yaml* file (within the local project folder) and change the *application-id* to the name of your newly created application.
44
+
45
+ 4.4. Hit the 'Deploy' button, wait a couple of seconds, and then navigate to *http://{app-name}.appspot.com* to enjoy your new status dashboard
46
+
47
+ # Usage
48
+ Into your Gemfile add the line
49
+ ```ruby
50
+ gem "stashboard-ruby"
51
+ ```
52
+
53
+ Inside of your project, first create a new Stashboard
54
+ ```ruby
55
+ stashboard = Stashboard::Stashboard.new("https://your-app.appspot.com", "<stashboard_oauth_token>", "<stashboard_oauth_secret>")
56
+ ```
57
+
58
+ To receive an array of services:
59
+ ```ruby
60
+ stashboard.services
61
+ =begin
62
+ => [
63
+ {
64
+ "description"=>"Mail Service",
65
+ "url"=>"https://YOURAPP.appspot.com/api/v1/services/mail-service",
66
+ "list"=>{
67
+ "url"=>"https://YOURAPP.appspot.com/api/v1/service-lists/application-services",
68
+ "description"=>"The main services that run the application",
69
+ "name"=>"Application Services",
70
+ "id"=>"application-services"
71
+ },
72
+ "current-event"=>nil,
73
+ "id"=>"mail-service",
74
+ "name"=>"Mail Service"
75
+ },
76
+ {
77
+ "description"=>"PDF Cleaner",
78
+ "url"=>"https://YOURAPP.appspot.com/api/v1/services/pdf-cleaner",
79
+ "list"=>{
80
+ "url"=>"https://YOURAPP.appspot.com/api/v1/service-lists/helper-services",
81
+ "description"=>"The little bits that help without being part of the app itself",
82
+ "name"=>"Helper Services", "id"=>"helper-services"
83
+ },
84
+ "current-event"=>nil,
85
+ "id"=>"pdf-cleaner",
86
+ "name"=>"PDF Cleaner"
87
+ },
88
+ {
89
+ "description"=>"Website service",
90
+ "url"=>"https://YOURAPP.appspot.com/api/v1/services/website",
91
+ "current-event"=>{
92
+ "status"=>{
93
+ "description"=>"The service is up",
94
+ "level"=>"NORMAL",
95
+ "default"=>true,
96
+ "image"=>"https://YOURAPP.appspot.com/images/icons/iconic/check_alt.png",
97
+ "url"=>"https://YOURAPP.appspot.com/api/v1/statuses/up",
98
+ "id"=>"up",
99
+ "name"=>"Up"
100
+ },
101
+ "url"=>"https://YOURAPP.appspot.com/api/v1/services/website/events/ag5zfnBsYW5ocS1zdGF0c3ISCxIFRXZlbnQYgICAgN6QwQsM",
102
+ "timestamp"=>"Mon, 28 Apr 2014 14:48:16 GMT",
103
+ "sid"=>"ag5zfnBsYW5ocS1zdGF0c3ISCxIFRXZlbnQYgICAgN6QwQsM",
104
+ "message"=>"Web server running A-OK",
105
+ "informational"=>false
106
+ },
107
+ "id"=>"website",
108
+ "name"=>"Website"
109
+ }
110
+ ]
111
+ =end
112
+ ```
113
+
114
+ To receive an array of service ids:
115
+ ```ruby
116
+ stashboard.service_ids
117
+ # => ["mail-service", "pdf-cleaner", "website"]
118
+ ```
119
+
120
+ To get details of a service based on it's id:
121
+ ```ruby
122
+ stashboard.service("website")
123
+ =begin
124
+ => {
125
+ "description"=>"Website service",
126
+ "url"=>"https://YOURAPP.appspot.com/api/v1/services/website",
127
+ "current-event"=>{
128
+ "status"=>{
129
+ "description"=>"The service is up",
130
+ "level"=>"NORMAL",
131
+ "default"=>true,
132
+ "image"=>"https://YOURAPP.appspot.com/images/icons/iconic/check_alt.png",
133
+ "url"=>"https://YOURAPP.appspot.com/api/v1/statuses/up",
134
+ "id"=>"up",
135
+ "name"=>"Up"
136
+ },
137
+ "url"=>"https://YOURAPP.appspot.com/api/v1/services/website/events/ag5zfnBsYW5ocS1zdGF0c3ISCxIFRXZlbnQYgICAgN6QwQsM",
138
+ "timestamp"=>"Mon, 28 Apr 2014 14:48:16 GMT",
139
+ "sid"=>"ag5zfnBsYW5ocS1zdGF0c3ISCxIFRXZlbnQYgICAgN6QwQsM",
140
+ "message"=>"Web server running A-OK",
141
+ "informational"=>false
142
+ },
143
+ "id"=>"website",
144
+ "name"=>"Website"
145
+ }
146
+ =end
147
+ ```
148
+
149
+ To generate an event for a service:
150
+ ```ruby
151
+ # Service Status Message
152
+ stashboard.create_event("website", "down", "Server unavailable, attempting to restart")
153
+ ```
154
+
155
+ # FAQs
156
+ Here are some of the frequesntly asked questions about this project
157
+ ### Where do I get my oauth token and secret?
158
+ Once you have deployed your application onto AppSpot, you will need to run the 'setup' at *http://{app-name}.appspot.com/admin* once that is done, there is an 'credentials' link that has them both there.
@@ -0,0 +1,28 @@
1
+ require 'rake/clean'
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ CLEAN.include("pkg")
7
+ CLOBBER.include("doc")
8
+
9
+ namespace :doc do
10
+ project_root = File.expand_path(File.dirname(__FILE__))
11
+ doc_destination = File.join(project_root, 'doc', 'rdoc')
12
+
13
+ begin
14
+ require 'yard'
15
+ require 'yard/rake/yardoc_task'
16
+
17
+ YARD::Rake::YardocTask.new(:generate) do |yt|
18
+ yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
19
+ [File.join(project_root, 'README.md') ]
20
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
21
+ end
22
+ rescue LoadError
23
+ desc "Generate YARD Documentation"
24
+ task :generate do
25
+ abort "Please install the YARD gem to generate rdoc."
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require "stashboard/version"
4
+ require "stashboard/stashboard"
@@ -0,0 +1,176 @@
1
+ require 'rubygems'
2
+ require 'oauth'
3
+ require 'yajl/json_gem'
4
+
5
+ module Stashboard
6
+ # Main class for interacting with Stashboard.
7
+ class Stashboard
8
+
9
+ # Create a new Stashboard instance.
10
+ #
11
+ # @param [String] the url of your stashboard instance (this should use https)
12
+ # @param [String] the oauth_token generated by your Stashboard instance (this is the long one)
13
+ # @param [String] the oauth_secret generated by your Stashboard instance (this is the shorter one)
14
+ def initialize(base_url, oauth_token, oauth_secret)
15
+ @consumer = OAuth::Consumer.new("anonymous", "anonymous", { :site => base_url })
16
+ @client = OAuth::AccessToken.new(@consumer, oauth_token, oauth_secret)
17
+ end
18
+
19
+ # Gets a list of all services currently managed by the Stashboard instance
20
+ #
21
+ # @return [Hash] containing an array of service detail hashes, or an error message
22
+ def services
23
+ response = JSON.parse(@client.get("/api/v1/services").body)
24
+ return response["services"] || response
25
+ end
26
+
27
+ # Gets an array of service ids. This is just for convenience
28
+ #
29
+ # @return [Array] containing just the service ids
30
+ def service_ids
31
+ services.collect { |s| s["id"] }
32
+ end
33
+
34
+ # Get the details of an individual service managed by the Stashboard instance.
35
+ #
36
+ # @param [String] the unique id of the service (generated by Stashboard)
37
+ # @return [Hash] hash containing the service details
38
+ def service(service_id)
39
+ response = @client.get("/api/v1/services/#{service_id}")
40
+ return JSON.parse(response.body)
41
+ end
42
+
43
+ # Create a new service.
44
+ #
45
+ # @param [String] the name of the service
46
+ # @param [String] the description of the service
47
+ # @return [Hash] response containing the complete service details generated by Stashboard
48
+ def create_service(name, description)
49
+ response = @client.post("/admin/api/v1/services", { "name" => name, "description" => description })
50
+ return JSON.parse(response.body)
51
+ end
52
+
53
+ # Delete a service. This will delete all alerts for this service, so be careful.
54
+ #
55
+ # @param [String] the service id to delete
56
+ # @return [Hash] details of the service we've just deleted
57
+ def delete_service(service_id)
58
+ response = @client.delete("/api/v1/services/#{service_id}")
59
+ return JSON.parse(response.body)
60
+ end
61
+
62
+ # Updates details of an existing service with a new name or description.
63
+ # You can't change the service_id however.
64
+ #
65
+ # @param [String] the id of the service to update
66
+ # @param [String] the new name
67
+ # @param [String] the new description
68
+ # @return [Hash] the updated service details
69
+ def update_service(service_id, name, description)
70
+ response = @client.post("/admin/api/v1/services/#{service_id}", { "name" => name, "description" => description })
71
+ return JSON.parse(response.body)
72
+ end
73
+
74
+ # Returns the different levels that new statuses can use.
75
+ #
76
+ # @return [Array] an array of the level strings
77
+ def levels
78
+ response = JSON.parse(@client.get("/api/v1/levels").body)
79
+ return response["levels"] || response
80
+ end
81
+
82
+ # Get events for the specified service.
83
+ #
84
+ # @param [String] the service id we wer interested in
85
+ # @param [Hash] optional hash that restricts the returned events. Only keys that do anything are "start" and "end" which can be used to constrain the time period from which events will be returned.
86
+ # @return [Hash] an array of event hashes describing events for the service, or an error hash
87
+ def events(service_id, options = {})
88
+ response = JSON.parse(@client.get("/api/v1/services/#{service_id}/events", options).body)
89
+ return response["events"] || response
90
+ end
91
+
92
+ # Create an event of a service. Events are the main way we
93
+ # indicate problems or resolutions of issues.
94
+ #
95
+ # @param [String] the id of the service
96
+ # @param [String] the id of an already existing status (i.e. "up", "down", "warning")
97
+ # @param [String] a descriptive message
98
+ # @return [Hash] the event details
99
+ def create_event(service_id, status_id, message)
100
+ response = @client.post("/admin/api/v1/services/#{service_id}/events", { "status" => status_id, "message" => message })
101
+ return JSON.parse(response.body)
102
+ end
103
+
104
+ # Get the current event for the specified service.
105
+ #
106
+ # @param [String] the id of the service
107
+ # @return [Hash] hash containing the current event details
108
+ def current_event(service_id)
109
+ response = @client.get("/api/v1/services/#{service_id}/events/current")
110
+ return JSON.parse(response.body)
111
+ end
112
+
113
+ # Get details of an individual event
114
+ #
115
+ # @param [String] the id of the service
116
+ # @param [String] the sid of the event. This is a unique key returned in the response when an event is created
117
+ # @return [Hash] hash containing the current event details
118
+ def event(service_id, event_sid)
119
+ response = @client.get("/api/v1/services/#{service_id}/events/#{event_sid}")
120
+ return JSON.parse(response.body)
121
+ end
122
+
123
+ # Delete an event.
124
+ #
125
+ # (see #event)
126
+ def delete_event(service_id, event_sid)
127
+ response = @client.delete("/admin/api/v1/services/#{service_id}/events/#{event_sid}")
128
+ return JSON.parse(response.body)
129
+ end
130
+
131
+ # Get all statuses.
132
+ #
133
+ # @return [Array] an array of status hashes, each hash is an individual status
134
+ def statuses
135
+ response = JSON.parse(@client.get("/api/v1/statuses").body)
136
+ return response["statuses"] || response
137
+ end
138
+
139
+ # Convenience method to return just the status ids.
140
+ #
141
+ # @return [Array] an array of just the status ids
142
+ def status_ids
143
+ statuses.collect { |s| s["id"] }
144
+ end
145
+
146
+ # Get the details of the individual status.
147
+ #
148
+ # @param [String] the id of the status
149
+ # @return [Hash] hash containing the status details
150
+ def status(status_id)
151
+ response = @client.get("/api/v1/statuses/#{status_id}")
152
+ return JSON.parse(response.body)
153
+ end
154
+
155
+ # Create a new status. Statuses exist independently of any Service, and are
156
+ # required before creating any events that use this status
157
+ #
158
+ # @param [String] the name of this status
159
+ # @param [String] description of the status
160
+ # @param [String] level string. Must be one of the levels returned from #levels
161
+ # @param [String] name of an image to use for this status. The complete list of images can be retrieved using #status_images, and this value should just be the image name without the directory name or the file extension.
162
+ # @return [Hash] hash containing the created statuses details
163
+ def create_status(name, description, level, image)
164
+ response = @client.post("/admin/api/v1/statuses", { "name" => name, "description" => description, "level" => level, "image" => image })
165
+ return JSON.parse(response.body)
166
+ end
167
+
168
+ # Return a list of all the status images that the Stashboard server knows about.
169
+ #
170
+ # @return [Array] array of image hashes
171
+ def status_images
172
+ response = JSON.parse(@client.get("/api/v1/status-images").body)
173
+ return response["images"] || response
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,3 @@
1
+ module Stashboard
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "stashboard/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "stashboard-ruby"
7
+ s.version = Stashboard::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.date = '2014-04-29'
10
+ s.authors = ["Sam Mulube", "Brian Stolz", "Matthew Rayner"]
11
+ s.email = ["sam@connectedenvironments.com", "brian@tecnobrat.com", "matt@mattrayner.co.uk"]
12
+ s.homepage = "http://github.com/mattrayner/stashboard-ruby"
13
+ s.summary = %q{Library for interacting with the Stashboard api. Updated to allow writes with the latest release.}
14
+ s.description = %q{Little library written to make interacting with the stashboard api a bit easier.}
15
+
16
+ s.rubygems_version = ">= 1.3.6"
17
+
18
+ s.add_dependency('yajl-ruby', '>= 0.8.1')
19
+ s.add_dependency('oauth', '>= 0.4.4')
20
+
21
+ s.add_development_dependency('yard', '>= 0.6.4')
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stashboard-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Mulube
8
+ - Brian Stolz
9
+ - Matthew Rayner
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-04-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yajl-ruby
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: 0.8.1
29
+ - !ruby/object:Gem::Dependency
30
+ name: oauth
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: 0.4.4
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.4.4
43
+ - !ruby/object:Gem::Dependency
44
+ name: yard
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: 0.6.4
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.6.4
57
+ description: Little library written to make interacting with the stashboard api a
58
+ bit easier.
59
+ email:
60
+ - sam@connectedenvironments.com
61
+ - brian@tecnobrat.com
62
+ - matt@mattrayner.co.uk
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - README.md
71
+ - Rakefile
72
+ - lib/stashboard.rb
73
+ - lib/stashboard/stashboard.rb
74
+ - lib/stashboard/version.rb
75
+ - stashboard.gemspec
76
+ homepage: http://github.com/mattrayner/stashboard-ruby
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Library for interacting with the Stashboard api. Updated to allow writes
99
+ with the latest release.
100
+ test_files: []