stashboard_notifier 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ruby_string="ruby-1.8.7-p334"
4
+ gemset_name="stashboard_notifier"
5
+
6
+ if rvm list strings | grep -q "${ruby_string}" ; then
7
+
8
+ # Load or create the specified environment
9
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
10
+ && -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
11
+ \. "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}"
12
+ else
13
+ rvm --create "${ruby_string}@${gemset_name}"
14
+ fi
15
+
16
+ else
17
+
18
+ # Notify the user to install the desired interpreter before proceeding.
19
+ echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into the project directory."
20
+
21
+ fi
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.0.1 - Initial version
4
+
5
+ * Initial release
6
+ * Lists services and statuses
7
+ * Enables creation of events for already defined services
8
+ * Config specified in command line, or can be loaded from $HOME/.stashboard_notifier
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in stashboard_notifier.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Stashboard Notifier
2
+
3
+ Command line executable for sending messages to a Stashboard instance
4
+ ([http://www.stashboard.org]((http://www.stashboard.org)).
5
+
6
+ Uses the stashboard gem to send messages.
7
+
8
+ ## Intended uses
9
+
10
+ This is intended for integration with a tool like Nagios, which can be
11
+ configured to call arbitrary commands should certain events happen in your
12
+ server infrastructure. These commands can be anything, but they need some sort
13
+ of command line tool to send the messages.
14
+
15
+ ## Usage
16
+
17
+ List services
18
+
19
+ $ stashboard_notifier services
20
+
21
+ List statuses
22
+
23
+ $ stashboard_notifier statuses
24
+
25
+ Create a new event for a service
26
+
27
+ $ stashboard_notifier events --service=website --status=down "Website is down"
28
+
29
+ ## Configuration
30
+
31
+ Every command needs at minimum 3 config options: the url to the stashboard
32
+ instance, and an oauth_token and oauth_secret for that stashboard. These can be
33
+ passed in as flags with each command invocation, but for convenience they can
34
+ be specified in a config file, which is written into
35
+ $HOME/.stashboard_notifier.
36
+
37
+ A skeleton config file can be generated by running:
38
+
39
+ $ stashboard_notifier initconfig
40
+
41
+ Then this file should be edited to add your relevant details.
42
+
43
+ Subsequently, you won't need to provide any of these details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env ruby
2
+ # 1.9 adds realpath to resolve symlinks; 1.8 doesn't
3
+ # have this method, so we add it so we get resolved symlinks
4
+ # and compatibility
5
+ unless File.respond_to? :realpath
6
+ class File #:nodoc:
7
+ def self.realpath path
8
+ return realpath(File.readlink(path)) if symlink?(path)
9
+ path
10
+ end
11
+ end
12
+ end
13
+
14
+ $: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
15
+
16
+ require 'rubygems'
17
+ require 'bundler/setup'
18
+ require 'gli'
19
+ require 'stashboard_notifier'
20
+ require 'stashboard'
21
+
22
+ include GLI
23
+
24
+ version StashboardNotifier::VERSION
25
+
26
+ desc 'The url of your stashboard instance (should start with https)'
27
+ arg_name '<stashboard_url>'
28
+ flag [:stashboard]
29
+
30
+ desc 'The oath token for accessing that stashboard'
31
+ arg_name '<oauth_token>'
32
+ flag [:oauth_token]
33
+
34
+ desc 'The oath secret for accessing that stashboard'
35
+ arg_name '<oauth_secret>'
36
+ flag [:oauth_secret]
37
+
38
+ config_file '.stashboard_notifier'
39
+
40
+ desc 'Manage services currently managed by the stashboard instance'
41
+ arg_name 'Describe arguments to services here'
42
+ command :services do |c|
43
+ c.action do |global_options,options,args|
44
+
45
+ stashboard = get_stashboard(global_options)
46
+
47
+ services = stashboard.services
48
+
49
+ services.each do |service|
50
+ puts service["id"]
51
+ end
52
+
53
+ # If you have any errors, just raise them
54
+ # raise "that command made no sense"
55
+ end
56
+ end
57
+
58
+
59
+ desc 'Manage statuses currently managed by the stashboard instance'
60
+ arg_name 'Describe arguments to statuses here'
61
+ command :statuses do |c|
62
+
63
+ c.action do |global_options,options,args|
64
+
65
+ stashboard = get_stashboard(global_options)
66
+
67
+ statuses = stashboard.statuses
68
+
69
+ statuses.each do |status|
70
+ puts status["id"]
71
+ end
72
+
73
+ # If you have any errors, just raise them
74
+ # raise "that command made no sense"
75
+ end
76
+ end
77
+
78
+ desc 'Manage events for services'
79
+ long_desc <<-EOS
80
+ This is the main command for sending event notifications to the stashboard
81
+ instance. The service and status parameters are required, then the remaining
82
+ parameter is a string sent as a message associated with the event. As the
83
+ message might contain spaces, then you should wrapp the message in quotes,
84
+ else you won't get a sensible message.
85
+
86
+ Example usage:
87
+
88
+ $ stashboard_notifier events --service=website --status=down "The server is down"
89
+ EOS
90
+ command :events do |c|
91
+ c.desc "Service id this event is for (required)"
92
+ c.arg_name '<service_id>'
93
+ c.flag [:service]
94
+
95
+ c.desc "Status id for this event (required)"
96
+ c.arg_name '<status_id>'
97
+ c.flag [:status]
98
+
99
+ c.action do |global_options,options,args|
100
+
101
+ if options[:service].nil?
102
+ #puts "Must specify a service with --service=<service_name>"
103
+ raise "Must specify a service"
104
+ end
105
+
106
+ if options[:status].nil?
107
+ raise "Must specify a status"
108
+ end
109
+
110
+ if args.size != 3
111
+ raise "Too many arguments"
112
+ end
113
+
114
+ stashboard = get_stashboard(global_options)
115
+
116
+ stashboard.create_event(options[:service], options[:status], args.last)
117
+
118
+ # If you have any errors, just raise them
119
+ # raise "that command made no sense"
120
+ end
121
+ end
122
+
123
+ pre do |global,command,options,args|
124
+ # if global[:config_file]
125
+ # require 'yaml'
126
+ #
127
+ # begin
128
+ # config = YAML.load_file(global[:config_file])
129
+
130
+ # global[:stashboard] = config["stashboard"] unless config["stashboard"].nil?
131
+ # global[:oauth_token] = config["oauth_token"] unless config["oauth_token"].nil?
132
+ # global[:oauth_secret] = config["oauth_secret"] unless config["oauth_secret"].nil?
133
+ #
134
+ # rescue Exception => e
135
+ # msg = "Unable to load config file #{global[:config_file]}: #{e.inspect}"
136
+ # puts msg
137
+ # raise msg
138
+ # end
139
+ # end
140
+ # Return true to proceed; false to abourt and not call the
141
+ # chosen command
142
+ true
143
+ end
144
+
145
+ post do |global,command,options,args|
146
+ # Post logic here
147
+ end
148
+
149
+ on_error do |exception|
150
+ puts "ERROR: #{exception.message}"
151
+ # Error logic here
152
+ # return false to skip default error handling
153
+ true
154
+ end
155
+
156
+ def get_stashboard(options)
157
+ Stashboard::Stashboard.new(options[:stashboard], options[:oauth_token], options[:oauth_secret])
158
+ end
159
+
160
+ exit GLI.run(ARGV)
@@ -0,0 +1,3 @@
1
+ module StashboardNotifier
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'stashboard_notifier/version'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "stashboard_notifier/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "stashboard_notifier"
7
+ s.version = StashboardNotifier::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Samuel Mulube"]
10
+ s.email = ["sam@connectedenvironments.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Simple executable that will send a message to stashboard when called}
13
+ s.description = %q{Installs a simple executable to your path that can be used to send a message to a stashboard instance}
14
+
15
+ s.rubyforge_project = "stashboard_notifier"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency("stashboard", [">= 0.0.2"])
23
+ s.add_runtime_dependency("gli", [">= 1.2.6"])
24
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stashboard_notifier
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Samuel Mulube
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-27 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: stashboard
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 2
34
+ version: 0.0.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: gli
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 6
50
+ version: 1.2.6
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Installs a simple executable to your path that can be used to send a message to a stashboard instance
54
+ email:
55
+ - sam@connectedenvironments.com
56
+ executables:
57
+ - stashboard_notifier
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - .gitignore
64
+ - .rvmrc
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/stashboard_notifier
70
+ - lib/stashboard_notifier.rb
71
+ - lib/stashboard_notifier/version.rb
72
+ - stashboard_notifier.gemspec
73
+ has_rdoc: true
74
+ homepage: ""
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: stashboard_notifier
103
+ rubygems_version: 1.6.1
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Simple executable that will send a message to stashboard when called
107
+ test_files: []
108
+