barking 1.0.0
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 +7 -0
- data/.codeclimate.yml +49 -0
- data/.gitignore +9 -0
- data/.travis.yml +25 -0
- data/.yardopts +2 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +11 -0
- data/bark.gemspec +32 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/bark.rb +14 -0
- data/lib/bark/client.rb +102 -0
- data/lib/bark/platform.rb +76 -0
- data/lib/bark/server.rb +117 -0
- data/lib/bark/service.rb +36 -0
- data/lib/bark/status.rb +28 -0
- data/lib/bark/utils/hash_helpers.rb +56 -0
- data/lib/bark/utils/string_helpers.rb +10 -0
- data/lib/bark/version.rb +5 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 103909fb9a464450bd700d6b33cae1c748cd5661
|
4
|
+
data.tar.gz: 573ed2c37ac699a1377d12cb458e10044812828b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a620b6e7541e73a54994d544fc8182546f087e9b5ec54256304c584bf08e2da6d81f8c838369f7994077952e42e796a124aea88ed189c57fd23d1c83ab1799db
|
7
|
+
data.tar.gz: 96f1041b4e70c31bc5ce9912dd95e2f37b85b0add78f6b23635dbdf8e4edc6e15b7187520b544f5e3de2c2f9037b807bd99bf970d8cfc4da26399cd4ae1fc744
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# This is a sample .codeclimate.yml configured for Engine analysis on Code
|
2
|
+
# Climate Platform. For an overview of the Code Climate Platform, see here:
|
3
|
+
# http://docs.codeclimate.com/article/300-the-codeclimate-platform
|
4
|
+
|
5
|
+
# Under the engines key, you can configure which engines will analyze your repo.
|
6
|
+
# Each key is an engine name. For each value, you need to specify enabled: true
|
7
|
+
# to enable the engine as well as any other engines-specific configuration.
|
8
|
+
|
9
|
+
# For more details, see here:
|
10
|
+
# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
|
11
|
+
|
12
|
+
# For a list of all available engines, see here:
|
13
|
+
# http://docs.codeclimate.com/article/296-engines-available-engines
|
14
|
+
|
15
|
+
# languages:
|
16
|
+
# Ruby: true
|
17
|
+
|
18
|
+
engines:
|
19
|
+
rubocop:
|
20
|
+
enabled: true
|
21
|
+
flay:
|
22
|
+
enabled: true
|
23
|
+
bundler-audit:
|
24
|
+
enabled: true
|
25
|
+
|
26
|
+
# Engines can analyze files and report issues on them, but you can separately
|
27
|
+
# decide which files will receive ratings based on those issues. This is
|
28
|
+
# specified by path patterns under the ratings key.
|
29
|
+
|
30
|
+
# For more details see here:
|
31
|
+
# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
|
32
|
+
|
33
|
+
ratings:
|
34
|
+
paths:
|
35
|
+
- bin/**
|
36
|
+
- lib/**
|
37
|
+
- test/**
|
38
|
+
- Rakefile
|
39
|
+
- Nessus6.gemspec
|
40
|
+
- Gemfile
|
41
|
+
# - "**.rb"
|
42
|
+
# - "**.go"
|
43
|
+
|
44
|
+
# You can globally exclude files from being analyzed by any engine using the
|
45
|
+
# exclude_paths key.
|
46
|
+
|
47
|
+
#exclude_paths:
|
48
|
+
#- spec/**/*
|
49
|
+
#- vendor/**/*
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.0.0
|
6
|
+
- 2.1.0
|
7
|
+
- 2.1.5
|
8
|
+
- 2.2.0
|
9
|
+
- 2.2.1
|
10
|
+
- 2.2.2
|
11
|
+
- 2.2.3
|
12
|
+
- rbx-2
|
13
|
+
- ruby-head
|
14
|
+
- jruby-head
|
15
|
+
|
16
|
+
before_install:
|
17
|
+
- gem install bundler -v 1.10.6
|
18
|
+
- gem update --system
|
19
|
+
- gem --version
|
20
|
+
|
21
|
+
gemfile:
|
22
|
+
- Gemfile
|
23
|
+
|
24
|
+
notifications:
|
25
|
+
email: false
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Bark
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bark`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bark'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install bark
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bark.
|
36
|
+
|
data/Rakefile
ADDED
data/bark.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bark/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'barking'
|
8
|
+
spec.version = Bark::VERSION
|
9
|
+
spec.authors = ['Kevin Kirsche']
|
10
|
+
spec.email = ['kev.kirsche@gmail.com']
|
11
|
+
spec.license = 'Apache-2.0)'
|
12
|
+
|
13
|
+
spec.summary = %q{Monit monitoring made easy!}
|
14
|
+
spec.description = %q{Bark: A Gem For Use By Individuals Looking to Retrieve Data From a Monit Server}
|
15
|
+
spec.homepage = 'https://github.com/kkirsche/Bark'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'hurley', '~> 0.2'
|
23
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.8'
|
29
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
30
|
+
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
31
|
+
spec.add_development_dependency 'github-markup', '~> 0.6'
|
32
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bark"
|
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
data/lib/bark.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Dependencies
|
2
|
+
require 'hurley'
|
3
|
+
require 'nokogiri'
|
4
|
+
# Main App
|
5
|
+
require 'bark/client'
|
6
|
+
require 'bark/server'
|
7
|
+
require 'bark/service'
|
8
|
+
require 'bark/status'
|
9
|
+
require 'bark/platform'
|
10
|
+
# Utilities
|
11
|
+
require 'bark/utils/hash_helpers'
|
12
|
+
require 'bark/utils/string_helpers'
|
13
|
+
# Metadata
|
14
|
+
require 'bark/version'
|
data/lib/bark/client.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Bark is a client for interacting with the Monit client.
|
2
|
+
module Bark
|
3
|
+
# The Client class is the primary communicator between the program and the
|
4
|
+
class Client
|
5
|
+
# `:host` = The hostname of the Monit server
|
6
|
+
# `:port` = The port used to connect to the Monit server
|
7
|
+
# `:user` = The username used for basic auth with Monit server
|
8
|
+
# `:password` = The password used for basic auth with Monit server
|
9
|
+
# `:status` = The status xml api endpoint client
|
10
|
+
# `:server` = The server section retrieved via the status xml api
|
11
|
+
# `:platform` = The platform section retrieved via the status xml api
|
12
|
+
# `:service` = The service section retrieved via the status xml api
|
13
|
+
attr_reader :host, :port, :user, :password, :status, :server, :platform, :service
|
14
|
+
def initialize(opts = {})
|
15
|
+
default_if_opts_nil opts
|
16
|
+
@client = Hurley::Client.new "http://#{@user}:#{@password}"\
|
17
|
+
"@#{@host}:#{@port}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Used for access to the top level XML data
|
21
|
+
#
|
22
|
+
# @return [`Bark::Status`] Bark status client
|
23
|
+
def status
|
24
|
+
@status ||= Bark::Status.new @client
|
25
|
+
end
|
26
|
+
|
27
|
+
# Used for access to the server section of the XML data
|
28
|
+
#
|
29
|
+
# @return [`Bark::Server`] Bark server client
|
30
|
+
def server
|
31
|
+
@server ||= Bark::Server.new @client
|
32
|
+
end
|
33
|
+
|
34
|
+
# Used for access to the platform section of the XML data
|
35
|
+
#
|
36
|
+
# @return [`Bark::Platform`] Bark platform client
|
37
|
+
def platform
|
38
|
+
@platform ||= Bark::Platform.new @client
|
39
|
+
end
|
40
|
+
|
41
|
+
# Used for access to the service section of the XML data
|
42
|
+
#
|
43
|
+
# @return [`Bark::Service`] Bark service client
|
44
|
+
def service
|
45
|
+
@service ||= Bark::Service.new @client
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Used to determine whether or not the user provided the Monit server's hostname,
|
51
|
+
# port, username, and password.
|
52
|
+
#
|
53
|
+
# @return [`Symbol`]
|
54
|
+
def default_if_opts_nil(opts)
|
55
|
+
@host = decide_if_default_or_user_input opts[:host], default_host
|
56
|
+
@port = decide_if_default_or_user_input opts[:port], default_port
|
57
|
+
@user = decide_if_default_or_user_input opts[:user], default_user
|
58
|
+
@password = decide_if_default_or_user_input opts[:pass], default_password
|
59
|
+
:ok
|
60
|
+
end
|
61
|
+
|
62
|
+
# Checks if the value / option is nil. If it is, use the default value, otherwise, use the user
|
63
|
+
# provided input.
|
64
|
+
#
|
65
|
+
# @return [`String`]
|
66
|
+
def decide_if_default_or_user_input(opt, default)
|
67
|
+
if opt.nil?
|
68
|
+
return default
|
69
|
+
else
|
70
|
+
return opt
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Monit's default hostname
|
75
|
+
#
|
76
|
+
# @return [`String`]
|
77
|
+
def default_host
|
78
|
+
@host = 'localhost'
|
79
|
+
end
|
80
|
+
|
81
|
+
# Monit's default port number
|
82
|
+
#
|
83
|
+
# @return [`String`]
|
84
|
+
def default_port
|
85
|
+
@port = '2812'
|
86
|
+
end
|
87
|
+
|
88
|
+
# Monit's default username
|
89
|
+
#
|
90
|
+
# @return [`String`]
|
91
|
+
def default_user
|
92
|
+
@user = 'admin'
|
93
|
+
end
|
94
|
+
|
95
|
+
# Monit's default password
|
96
|
+
#
|
97
|
+
# @return [`String`]
|
98
|
+
def default_password
|
99
|
+
@password = 'monit'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Bark is a client for interacting with the Monit client.
|
2
|
+
module Bark
|
3
|
+
# The Platform class hits the Status Monit API endpoint
|
4
|
+
# and then segments it accordingly
|
5
|
+
class Platform
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
@status = Bark::Status.new client
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieves the full platform object
|
12
|
+
#
|
13
|
+
# @return [`Hash`]
|
14
|
+
# {
|
15
|
+
# :name => "Darwin",
|
16
|
+
# :release => "15.0.0",
|
17
|
+
# :version => "Darwin Kernel Version 15.0.0: Wed Aug 26 16:57:32 PDT 2015; root:xnu-3247.1.106~1/RELEASE_X86_64",
|
18
|
+
# :machine => "x86_64",
|
19
|
+
# :cpu => "4",
|
20
|
+
# :memory => "16777216",
|
21
|
+
# :swap => "0"
|
22
|
+
# }
|
23
|
+
def full
|
24
|
+
@status.current[:monit][:platform]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Retrieves the platform's name
|
28
|
+
#
|
29
|
+
# @return [String] `"Darwin"`
|
30
|
+
def name
|
31
|
+
@status.current[:monit][:platform][:name]
|
32
|
+
end
|
33
|
+
|
34
|
+
# Retrieves the platform's release number
|
35
|
+
#
|
36
|
+
# @return [String] `"15.0.0"`
|
37
|
+
def release
|
38
|
+
@status.current[:monit][:platform][:release]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Retrieves the platform's version number
|
42
|
+
#
|
43
|
+
# @return [String] `"Darwin Kernel Version 15.0.0: Wed Aug 26 16:57:32 PDT 2015; root:xnu-3247.1.106~1/RELEASE_X86_64"`
|
44
|
+
def version
|
45
|
+
@status.current[:monit][:platform][:version]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Retrieves the platform's machine type
|
49
|
+
#
|
50
|
+
# @return [String] `"x86_64"`
|
51
|
+
def machine
|
52
|
+
@status.current[:monit][:platform][:machine]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Retrieves the platform's aggregate (user / system) CPU usage
|
56
|
+
#
|
57
|
+
# @return [String] `"4"`
|
58
|
+
def cpu
|
59
|
+
@status.current[:monit][:platform][:cpu]
|
60
|
+
end
|
61
|
+
|
62
|
+
# Retrieves the platform's total RAM (used & available)
|
63
|
+
#
|
64
|
+
# @return [String] `"16777216"`
|
65
|
+
def memory
|
66
|
+
@status.current[:monit][:platform][:memory]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Retrieves the platform's total swap (used & available)
|
70
|
+
#
|
71
|
+
# @return [String] `"0"`
|
72
|
+
def swap
|
73
|
+
@status.current[:monit][:platform][:swap]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/bark/server.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# Bark is a client for interacting with the Monit client.
|
2
|
+
module Bark
|
3
|
+
# The Server class hits the Status Monit API endpoint and then segments
|
4
|
+
# it accordingly
|
5
|
+
class Server
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
@status = Bark::Status.new client
|
9
|
+
end
|
10
|
+
|
11
|
+
# Retrieves the server's status
|
12
|
+
#
|
13
|
+
# @return [Hash] `{:id=>"4674ff31c162bba574525571642b67fd", :incarnation=>"1443740471", :version=>"5.14", :uptime=>"14536", :poll=>"30", :startdelay=>"0", :localhostname=>"JohnDoe-Laptop.com", :controlfile=>"/Users/jdoe/.monitrc", :httpd=>{:address=>"localhost", :port=>"2812", :ssl=>"0"}}`
|
14
|
+
def status
|
15
|
+
@status.current[:monit][:server]
|
16
|
+
end
|
17
|
+
|
18
|
+
# Retrieves the platform's id
|
19
|
+
#
|
20
|
+
# @return [String] `"4674ff31c162bba574525571642b67fd"`
|
21
|
+
def id
|
22
|
+
@status.current[:monit][:server][:id]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Retrieves the platform's incarnation
|
26
|
+
#
|
27
|
+
# @return [String] `"1443740471"`
|
28
|
+
def incarnation
|
29
|
+
@status.current[:monit][:server][:incarnation]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Retrieves the platform's monit version number
|
33
|
+
#
|
34
|
+
# @return [String] `"5.14"`
|
35
|
+
def monit_version
|
36
|
+
@status.current[:monit][:server][:version]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Retrieves the platform's uptime
|
40
|
+
#
|
41
|
+
# @return [String] `"14536"`
|
42
|
+
def uptime
|
43
|
+
@status.current[:monit][:server][:uptime]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Retrieves the platform's polling rate
|
47
|
+
#
|
48
|
+
# @return [String] `"30"`
|
49
|
+
def poll
|
50
|
+
@status.current[:monit][:server][:poll]
|
51
|
+
end
|
52
|
+
|
53
|
+
# Retrieves the platform's start delay time
|
54
|
+
#
|
55
|
+
# @return [String] `"0"`
|
56
|
+
def start_delay
|
57
|
+
@status.current[:monit][:server][:startdelay]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Retrieves the platform's hostname
|
61
|
+
#
|
62
|
+
# @return [String] `"JohnDoe-Laptop.com"`
|
63
|
+
def hostname
|
64
|
+
@status.current[:monit][:server][:localhostname]
|
65
|
+
end
|
66
|
+
|
67
|
+
# Retrieves the platform's control file path
|
68
|
+
#
|
69
|
+
# @return [String] `"/Users/jdoe/.monitrc"`
|
70
|
+
def control_file
|
71
|
+
@status.current[:monit][:server][:controlfile]
|
72
|
+
end
|
73
|
+
|
74
|
+
# Retrieves the platform's httpd instance object
|
75
|
+
#
|
76
|
+
# @return [Hash] `{:address=>"localhost", :port=>"2812", :ssl=>"0"}`
|
77
|
+
def httpd
|
78
|
+
@status.current[:monit][:server][:httpd]
|
79
|
+
end
|
80
|
+
|
81
|
+
# Retrieves the platform's httpd instance address / hostname
|
82
|
+
#
|
83
|
+
# @return [String] `"localhost"`
|
84
|
+
def httpd_address
|
85
|
+
@status.current[:monit][:server][:httpd][:address]
|
86
|
+
end
|
87
|
+
|
88
|
+
# Retrieves the platform's httpd instance port number
|
89
|
+
#
|
90
|
+
# @return [String] `"2812"`
|
91
|
+
def httpd_port
|
92
|
+
@status.current[:monit][:server][:httpd][:port]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Retrieves the platform's httpd instance SSL boolean (binary)
|
96
|
+
#
|
97
|
+
# @return [String] `"0"`
|
98
|
+
def httpd_ssl
|
99
|
+
@status.current[:monit][:server][:httpd][:ssl]
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
# Validates whether we successfully retrieved the response or if we got an unknown / unexpected
|
105
|
+
# error.
|
106
|
+
#
|
107
|
+
# @return [Hash]
|
108
|
+
def validate(response)
|
109
|
+
if response.status_type == :success
|
110
|
+
document = Hash.from_xml(response.body)
|
111
|
+
else
|
112
|
+
fail StandardError, 'An unknown error occurred.'
|
113
|
+
end
|
114
|
+
document
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/bark/service.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Bark is a client for interacting with the Monit client.
|
2
|
+
module Bark
|
3
|
+
# The Service class hits the Status Monit API endpoint
|
4
|
+
class Service
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
@status = Bark::Status.new client
|
8
|
+
end
|
9
|
+
|
10
|
+
# Retrieves the services which Monit has running / is monitoring
|
11
|
+
#
|
12
|
+
# @return [Array]
|
13
|
+
def each
|
14
|
+
response = @status.current[:monit][:service]
|
15
|
+
if response.is_a? Array
|
16
|
+
@services = response.map do |service|
|
17
|
+
service
|
18
|
+
end
|
19
|
+
else
|
20
|
+
@services = [@hash["monit"]["service"]]
|
21
|
+
end
|
22
|
+
@services
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def validate(response)
|
28
|
+
if response.status_type == :success
|
29
|
+
document = Hash.from_xml(response.body)
|
30
|
+
else
|
31
|
+
fail StandardError, 'An unknown error occurred.'
|
32
|
+
end
|
33
|
+
document
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/bark/status.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Bark is a client for interacting with the Monit client.
|
2
|
+
module Bark
|
3
|
+
# The Status class hits the Status Monit API endpoint
|
4
|
+
class Status
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
# Retrieves the current status of Monit. **Note:** This is the top level API object
|
10
|
+
#
|
11
|
+
# @return [String] `"localhost"`
|
12
|
+
def current
|
13
|
+
response = @client.get('_status', format: 'xml')
|
14
|
+
validate response
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def validate(response)
|
20
|
+
if response.status_type == :success
|
21
|
+
document = Hash.from_xml(response.body)
|
22
|
+
else
|
23
|
+
fail StandardError, 'An unknown error occurred.'
|
24
|
+
end
|
25
|
+
document
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Hash
|
2
|
+
class << self
|
3
|
+
def from_xml(xml_io)
|
4
|
+
begin
|
5
|
+
result = Nokogiri::XML(xml_io)
|
6
|
+
return { result.root.name.to_sym => xml_node_to_hash(result.root) }
|
7
|
+
rescue StandardError => e
|
8
|
+
puts e
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def xml_node_to_hash(node)
|
13
|
+
# If we are at the root of the document, start the hash
|
14
|
+
if node.element?
|
15
|
+
result_hash = {}
|
16
|
+
if node.attributes != {}
|
17
|
+
attributes = {}
|
18
|
+
node.attributes.keys.each do |key|
|
19
|
+
attributes[node.attributes[key].name.to_sym] = node.attributes[key].value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
if node.children.size > 0
|
23
|
+
node.children.each do |child|
|
24
|
+
result = xml_node_to_hash(child)
|
25
|
+
|
26
|
+
if child.name == 'text'
|
27
|
+
unless child.next_sibling || child.previous_sibling
|
28
|
+
return result unless attributes
|
29
|
+
result_hash[child.name.to_sym] = result
|
30
|
+
end
|
31
|
+
elsif result_hash[child.name.to_sym]
|
32
|
+
|
33
|
+
if result_hash[child.name.to_sym].is_a?(Object::Array)
|
34
|
+
result_hash[child.name.to_sym] << result
|
35
|
+
else
|
36
|
+
result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << result
|
37
|
+
end
|
38
|
+
else
|
39
|
+
result_hash[child.name.to_sym] = result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
if attributes
|
43
|
+
#add code to remove non-data attributes e.g. xml schema, namespace here
|
44
|
+
#if there is a collision then node content supersets attributes
|
45
|
+
result_hash = attributes.merge(result_hash)
|
46
|
+
end
|
47
|
+
return result_hash
|
48
|
+
else
|
49
|
+
return attributes
|
50
|
+
end
|
51
|
+
else
|
52
|
+
return node.content.to_s
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/bark/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: barking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Kirsche
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hurley
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: redcarpet
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: github-markup
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.6'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.6'
|
139
|
+
description: 'Bark: A Gem For Use By Individuals Looking to Retrieve Data From a Monit
|
140
|
+
Server'
|
141
|
+
email:
|
142
|
+
- kev.kirsche@gmail.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".codeclimate.yml"
|
148
|
+
- ".gitignore"
|
149
|
+
- ".travis.yml"
|
150
|
+
- ".yardopts"
|
151
|
+
- Gemfile
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- bark.gemspec
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- lib/bark.rb
|
158
|
+
- lib/bark/client.rb
|
159
|
+
- lib/bark/platform.rb
|
160
|
+
- lib/bark/server.rb
|
161
|
+
- lib/bark/service.rb
|
162
|
+
- lib/bark/status.rb
|
163
|
+
- lib/bark/utils/hash_helpers.rb
|
164
|
+
- lib/bark/utils/string_helpers.rb
|
165
|
+
- lib/bark/version.rb
|
166
|
+
homepage: https://github.com/kkirsche/Bark
|
167
|
+
licenses:
|
168
|
+
- Apache-2.0)
|
169
|
+
metadata: {}
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
requirements: []
|
185
|
+
rubyforge_project:
|
186
|
+
rubygems_version: 2.4.5.1
|
187
|
+
signing_key:
|
188
|
+
specification_version: 4
|
189
|
+
summary: Monit monitoring made easy!
|
190
|
+
test_files: []
|
191
|
+
has_rdoc:
|