upstreamstatus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 811c0ee8607c7d2df2cf95ecca29f9ff4fe8cb3d
4
+ data.tar.gz: cdf0c61c45065e1d2dcdf12d9d744544d8bf2b87
5
+ SHA512:
6
+ metadata.gz: a2a06a3f92881b1dd18dd4c35e27cb07b199c192a31571812b9e4934b7066313fd8a053d6fadff8ad93fb4c5f00d2dc1aac7b82596629bb447eb60ee88feb24a
7
+ data.tar.gz: ec5e72d8561a0ac2754706fd5718c493058e081ef6db8f0ee865f3fc2cfb3ede02770a0c82dd4f399f6dc862af861e07b524e3517ff8133d911d23acece9d524
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in upstreamstatus.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Eric Herot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Upstreamstatus
2
+
3
+ A really lightweight Gem to get a yes or no answer about whether or not one of your hosts is down according to [The Upstream Status Check Module](https://github.com/yaoweibin/nginx_upstream_check_module)
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem install upstreamstatus
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ $ upstream-status
14
+
15
+ ## Development
16
+
17
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
18
+
19
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/upstreamstatus.
24
+
25
+
26
+ ## License
27
+
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
29
+
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "upstreamstatus"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
File without changes
@@ -0,0 +1,3 @@
1
+ module Upstreamstatus
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'upstreamstatus/version'
2
+
3
+ module Upstreamstatus
4
+ extend Forwardable
5
+
6
+ require 'unirest'
7
+ require 'yaml'
8
+ require 'ostruct'
9
+
10
+ def_delegators :@conf,
11
+ :status_check_url
12
+
13
+ def initialize
14
+ @conf = OpenStruct.new load_conf
15
+ end
16
+
17
+ def run
18
+ down_hosts =
19
+ current_status['servers']['server'].select { |s| s['status'] != 'up' }
20
+
21
+ exit 0 if down_hosts.empty?
22
+ print_hosts down_hosts
23
+ exit 1
24
+ end
25
+
26
+ private
27
+
28
+ def print_hosts(hosts)
29
+ hosts.each do |host|
30
+ host.each { |k, v| puts "#{k}: #{v}" }
31
+ puts
32
+ end
33
+ end
34
+
35
+ def current_status
36
+ r = Unirest.get status_check_url
37
+
38
+ unless (200..299).include?(r.code)
39
+ fail "Error code: #{r.code}\n" \
40
+ "Headers: #{r.headers}" \
41
+ "Body: #{r.body}"
42
+ end
43
+
44
+ r.body
45
+ end
46
+
47
+ def load_conf
48
+ conf_file = '/etc/upstreamstatus.yml'
49
+ yaml_conf = File.exist?(conf_file) ? YAML.load_file(conf_file) : {}
50
+ defaults.merge(yaml_conf)
51
+ end
52
+
53
+ def defaults
54
+ {
55
+ 'status_check_url' => 'http://localhost:8069/status?format=json'
56
+ }
57
+ end
58
+ end
data/test.yaml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ key: value
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'upstreamstatus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'upstreamstatus'
8
+ spec.version = Upstreamstatus::VERSION
9
+ spec.authors = ['Eric Herot']
10
+ spec.email = ['eric.github@herot.com']
11
+
12
+ spec.summary = 'Parse the output of the Nginx Upstream Check plugin'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/evertrue/upstreamstatus'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.10'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec'
33
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: upstreamstatus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Herot
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-21 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Parse the output of the Nginx Upstream Check plugin
56
+ email:
57
+ - eric.github@herot.com
58
+ executables:
59
+ - upstream-status
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - exe/upstream-status
73
+ - lib/upstreamstatus.rb
74
+ - lib/upstreamstatus/version.rb
75
+ - test.yaml
76
+ - upstreamstatus.gemspec
77
+ homepage: https://github.com/evertrue/upstreamstatus
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Parse the output of the Nginx Upstream Check plugin
102
+ test_files: []
103
+ has_rdoc: