stashboardmanager 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7740e0ee907b9b81a69152969c7510f5e6599b15
4
+ data.tar.gz: 6712adcd6660f6033fb4110203c579a2b73f0678
5
+ SHA512:
6
+ metadata.gz: 5f6f0eaab23573783e631dd2ce77db62ef1858e870bd63c2e63b66c3c327830212469fe10a49a956913a9ba5100e6c964fd6fdf46c4c3155e2e064260868fd5b
7
+ data.tar.gz: f166444d705157cb91e18ff34f9d59bbd77496faaca10d5447d47d5461a38c1692fe7e97b5bb864719c8ef30fc9368514f3f7849c4e3170848f6c4d2355f5a1f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stashboardmanager.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matt Rayner
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Stashboardmanager
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'stashboardmanager'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install stashboardmanager
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/stashboardmanager/fork )
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
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Stashboardmanager
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,100 @@
1
+ require "stashboard"
2
+ require "stashboardmanager/version"
3
+
4
+ module Stashboardmanager
5
+
6
+
7
+ # Main class for interacting with StashboardManager.
8
+ class Manager
9
+
10
+ @stashboard = nil
11
+
12
+ # Create a new StashboardManager instance.
13
+ def initialize(address, token, secret)
14
+ @stashboard = Stashboard::Stashboard.new(address, token, secret)
15
+ end
16
+
17
+ # Check to see if a service is already set as 'status'. If not, update it.
18
+ #
19
+ # @param [String] service The service you are attempting to set
20
+ # @param [String] status The status you are attempting to set
21
+ # @param [String] message The message you wish to attach to this update
22
+ def service_update(service, status, message)
23
+ if service_updatable(service, status)
24
+ self.generate_stashboard_event(service, status, message)
25
+ end
26
+ end
27
+
28
+ # Get all services attached to this stashboard.
29
+ #
30
+ # @return [Hash] services A hash containing an array of service detail hashes, or an error message
31
+ def services
32
+ @stashboard.services
33
+ end
34
+
35
+ # Get an array of service ids. This is just for convenience/
36
+ #
37
+ # @return [Array] Services Array containing just the service ids
38
+ def service_ids
39
+ @stashboard.service_ids
40
+ end
41
+
42
+ # Get the current status of a service.
43
+ #
44
+ # @param [String] service The service you are attempting to set
45
+ # @return [Hash] details A hash containing the details for this service
46
+ def service_status(service)
47
+ #Do we have a service for this set up
48
+ services = self.service_ids
49
+ exists = services.include? service
50
+
51
+ status = false
52
+
53
+ #Make sure we have some services and that this one exists
54
+ if exists
55
+ #Get the service's details
56
+ s = @stashboard.service(service)
57
+
58
+ #Grab the current event
59
+ current_event = s["current-event"]
60
+
61
+ #Make sure we have a current event
62
+ if(!current_event.nil?)
63
+ status = current_event["status"]["id"]
64
+ end
65
+ end
66
+
67
+ status
68
+ end
69
+
70
+ # Is this service updatable?
71
+ #
72
+ # @param [String] service The name of the service you want to check
73
+ # @param [String] status The status you are trying to update the service to
74
+ # @return [Boolean] response Response containing a true if this service should be updated, a false if it shouldn't OR a nil if the service doesn't exist
75
+ def service_updatable(service, status)
76
+ #What is the current service status?
77
+ serv_stat = self.service_status(service)
78
+
79
+ if serv_stat == false #If false then don't continue (the service does not exist on remote)
80
+ return nil
81
+ elsif serv_stat == status #If match don't update
82
+ return false
83
+ else #No match - update
84
+ return true
85
+ end
86
+ end
87
+
88
+ # Create an event of a service. Events are the main way we
89
+ # indicate problems or resolutions of issues.
90
+ #
91
+ # @param [String] service The service you want to update
92
+ # @param [String] id The id of an already existing status (i.e. "up", "down", "warning" or "error")
93
+ # @param [String] message The message we want our event to have attached
94
+ # @return [Hash] event The event details
95
+ def generate_stashboard_event(service, status, message)
96
+ @stashboard.create_event(service, status, message)
97
+ end
98
+ end
99
+
100
+ end
@@ -0,0 +1,37 @@
1
+ require 'stashboardmanager'
2
+
3
+ describe Stashboardmanager::Manager do
4
+ #Setup the remote instance ready for the tests
5
+ puts "Preparing for tests"
6
+ manager = Stashboardmanager::Manager.new("https://stashmanagertest.appspot.com", "1/3x3oY6MRqACaMmuzr0pr76_3J9zkB3sJX_rIMCFU-cU", "p2K71wl3ekDBNF88UcAnFfUi")
7
+
8
+ ids = manager.service_ids
9
+
10
+ puts ids
11
+
12
+ ids.each do |id|
13
+ manager.service_update(id, "up", "Resetting #{id} for testing purposes")
14
+ end
15
+
16
+ id = ids[0]
17
+
18
+ puts id
19
+
20
+ puts manager.service_status(id)
21
+
22
+ it "Has reset all" do
23
+ manager.service_status(id).should eql("up")
24
+ end
25
+
26
+ it "Can update status" do
27
+ manager.service_update(id, "down", "test that we can set #{id} to 'down'")
28
+ manager.service_status(id).should eql("down")
29
+ end
30
+
31
+ it "Can mass-asign" do
32
+ ids.each do |id|
33
+ manager.service_update(id, "warning", "Warning on #{id} for testing purposes")
34
+ manager.service_status(id).should eql("warning")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stashboardmanager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stashboardmanager"
8
+ spec.version = Stashboardmanager::VERSION
9
+ spec.authors = ["Matt Rayner"]
10
+ spec.email = ["matt@mattrayner.co.uk"]
11
+ spec.summary = %q{A manager designed to work with the stashboard-ruby gem and simplify it's use.}
12
+ spec.description = %q{Adds easy management to stashboard events within a ruby environment. This gem adds the ability to update stashboard only when an update is needed. i.e. creating a stashboard event with status "up" is only created when the remote status != "up" allowing you to save on Google App Engine bandwidth.}
13
+ spec.homepage = "https://github.com/mattrayner/stashboardmanager"
14
+ spec.license = "MIT"
15
+
16
+ spec.add_dependency "stashboard-ruby", "~> 0.1.0"
17
+ spec.add_development_dependency "rspec", "~> 2.6"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stashboardmanager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Matt Rayner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stashboard-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Adds easy management to stashboard events within a ruby environment.
70
+ This gem adds the ability to update stashboard only when an update is needed. i.e.
71
+ creating a stashboard event with status "up" is only created when the remote status
72
+ != "up" allowing you to save on Google App Engine bandwidth.
73
+ email:
74
+ - matt@mattrayner.co.uk
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/stashboardmanager.rb
85
+ - lib/stashboardmanager/version.rb
86
+ - spec/manager_spec.rb
87
+ - stashboardmanager.gemspec
88
+ homepage: https://github.com/mattrayner/stashboardmanager
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A manager designed to work with the stashboard-ruby gem and simplify it's
112
+ use.
113
+ test_files:
114
+ - spec/manager_spec.rb