nagios_output 1.0.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
+ SHA256:
3
+ metadata.gz: 56ebd9834f69026b161b769f7fbd32fac374017bd88673aa2549807a49962b76
4
+ data.tar.gz: 3ad6ac12234a3c829bd8dad2868d38e4c3593b364c71579e837bfc11c053ab9c
5
+ SHA512:
6
+ metadata.gz: '09021e4e4f59cace6ed07ac74bc99f35c5a9c72bd173a14849b42109a889ef20538951ae6c6cec2419ffd5cbddda06341ff798c64dd5016bc3eb071440d48a77'
7
+ data.tar.gz: 86f2c2265967cc491110397a90cb729edd486cf719fb488d8ae838ec6571b517366f7c65e487034ec30c7c5972945d02da0ee8784063db39b921e96004d49e64
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+
11
+ *.gem
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ Layout/IndentationWidth:
2
+ Width: 4
3
+
4
+ Metrics/AbcSize:
5
+ Max: 50
6
+
7
+ Metrics/LineLength:
8
+ Max: 180
9
+
10
+ Metrics/BlockLength:
11
+ Max: 40
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Max: 20
15
+
16
+ Metrics/MethodLength:
17
+ Max: 60
18
+
19
+ Metrics/PerceivedComplexity:
20
+ Max: 20
21
+
22
+ Style/GlobalVars:
23
+ Enabled: false
24
+
25
+ Style/RaiseArgs:
26
+ EnforcedStyle: compact
27
+
28
+ Style/WordArray:
29
+ EnforcedStyle: brackets
30
+
data/.travis.yml ADDED
@@ -0,0 +1,36 @@
1
+ sudo: required
2
+ matrix:
3
+ include:
4
+ - language: ruby
5
+ rvm: 2.2
6
+ before_install:
7
+ - gem install bundler -v 1.16.1
8
+ - language: ruby
9
+ rvm: 2.4.4
10
+ before_install:
11
+ - gem install bundler -v 1.17.3
12
+ - language: ruby
13
+ env: SKIP_INTERPRETER=true
14
+
15
+ rvm: 2.4.4
16
+ before_install:
17
+ - git clone https://github.com/TravisToolbox/rubocop-travis.git
18
+ install:
19
+ - ./rubocop-travis/install.sh
20
+ script:
21
+ - ./rubocop-travis/scan.sh
22
+ - language: ruby
23
+ rvm: 2.2
24
+ before_install:
25
+ - mkdir travis
26
+ - git clone https://github.com/TravisToolbox/awesomebot-travis.git travis/awesomebot
27
+ install:
28
+ - ./travis/awesomebot/install.sh
29
+ script:
30
+ - ./travis/awesomebot/scan.sh
31
+ notifications:
32
+ email: false
33
+ slack:
34
+ notifications:
35
+ slack:
36
+ secure: N7+MOIX567Z2E2eyKaLngafy8QeJ4uvgWkWhp7nEWTbw989namVeymljYrNLSuykVgX6rn0Wq95LUPm0uUuRawULzMgzFv0wIMcbbbX+4ZAuEUvWxHWCGo8qfins15Px9EgkT/UrYYblywYlwelQHOu++MkxyQ9mHwypKS4z5IyzW/mwFoZ+HKQCOqYw8TrR7aHGSpe9PUVK9Lj2XXmK1QaaBW7GabW6ugmHMbL46xhxMdBBpJfotRbwdHnyKXPfrhSbj95+tZxY1NY33ZOBdgiQDuOYpkA51GObBUZ4TKwhQS3OX0pp490QvJBR0Jf84waF7sMBx1E03haPgFwNiLayvtA8YkpJBJTOaVhCc6i504r9Sf3ZBBdjVULLG0W1hGZuhXZrsrTE6IyTomIjifmA1L795CRgLAPyecqAVf2Z2JQlN48Pt7TbGEUWXxUlCSlen45B4XBZaNoqX02AzugcztqEdqdAAe6mga0bHwjrzErkAxUXP4u9GyTKCy8FV8KEg6k//g0TLkQzaFM1p521TBMI9AsGwO4OvE0mXq3sRK5wJ1ojQCleINP6ijAg0F186DzD4l8Uj22K44IidSa4P9rxRM2drMttNscNGfFddBbcG8isLTVoldsZHvzMa90lVe86xtiGo2/Kjt7g490pvMRXOf2XzEG3yy3nec8=
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 1.0.0 (January 18, 2019)
2
+
3
+ * Initial Release ([@TGWolf][])
4
+
5
+ [@TGWolf]: https://github.com/TGWolf
data/CODEOWNERS ADDED
@@ -0,0 +1,7 @@
1
+ # The codeowners file:
2
+ #
3
+ # For more information please read: https://help.github.com/articles/about-codeowners/
4
+
5
+ # These owners will be the default owners for everything in
6
+ # the repo. Unless a later match takes precedence,
7
+ * @AntiPhotonltd/reviewers
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at wolf@tgwolf.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nagios_output.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tim Gurney aka Wolf
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,89 @@
1
+ [![Build Status](https://img.shields.io/travis/AntiPhotonltd/nagios_output/master.svg)](https://travis-ci.org/AntiPhotonltd/nagios_output)
2
+ [![Software License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)
3
+ [![Release](https://img.shields.io/github/release/AntiPhotonltd/nagios_output.svg)](https://github.com/AntiPhotonltd/nagios_output/releases/latest)
4
+ [![Gem Version](https://badge.fury.io/rb/nagios_output.svg)](https://badge.fury.io/rb/nagios_output)
5
+ [![Github commits (since latest release)](https://img.shields.io/github/commits-since/AntiPhotonltd/nagios_output/latest.svg)](https://github.com/AntiPhotonltd/nagios_output/commits)
6
+ [![GitHub repo size in bytes](https://img.shields.io/github/repo-size/AntiPhotonltd/nagios_output.svg)](https://github.com/AntiPhotonltd/nagios_output)
7
+ [![GitHub contributors](https://img.shields.io/github/contributors/AntiPhotonltd/nagios_output.svg)](https://github.com/AntiPhotonltd/nagios_output)
8
+
9
+ # Nagios Output
10
+
11
+ A simple wrapper for creating nagios consumable output - including exit codes.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'nagios_output'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install nagios_output
28
+
29
+ ## Usage
30
+
31
+ There are 3 different ways to access the 4 nagios output methods. Those methods are ok, warning, critical and unknown, they have the following spective exit codes 0, 1, 2 and 3.
32
+
33
+ ### Class Method
34
+
35
+ ```ruby
36
+ require 'nagios_output'
37
+
38
+ n = NagiosOutput.new
39
+ n.ok('Everything is ok (Class))')
40
+ n.warning('Everything is ok-ish (Class)')
41
+ n.critical('Everything is cirtial (Class)')
42
+ n.unknown('Everything is erm - I don\'t know (Class)')
43
+ ```
44
+
45
+ ### Static Method
46
+
47
+ ```ruby
48
+ require 'nagios_output'
49
+
50
+ NagiosOutputStatic.ok('Everything is ok (Static)')
51
+ NagiosOutputStatic.warning('Everything is ok-ish (Static)')
52
+ NagiosOutputStatic.critical('Everything is cirtial (Static)')
53
+ NagiosOutputStatic.unknown('Everything is erm - I don\'t know (Static)')
54
+ ```
55
+
56
+ ### Direct Method
57
+
58
+ ```ruby
59
+ require 'nagios_output'
60
+
61
+ ok('Everything is ok (Direct)')
62
+ warning('Everything is ok-ish (Direct)')
63
+ critical('Everything is cirtial (Direct)')
64
+ unknown('Everything is erm - I don\'t know (Direct)')
65
+ ```
66
+
67
+ It is worth noting that the above examples will not function as you might first expect if you cut and paste them and run them. They will all show the ok() message then stop. Remember each function also makes a call to exit().
68
+
69
+ ## Development
70
+
71
+ 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.
72
+
73
+ 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).
74
+
75
+ ## Testing
76
+
77
+ For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/AntiPhotonltd/nagios_output. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
86
+
87
+ ## Code of Conduct
88
+
89
+ Everyone interacting in the NagiosOutput project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/AntiPhotonltd/nagios_output/blob/master/CODE_OF_CONDUCT.md).
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 "nagios_output"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------------- #
4
+ # Description #
5
+ # -------------------------------------------------------------------------------- #
6
+ # A simple script to demonstrate how to use the nagios output gem. #
7
+ # #
8
+ # Please NOTE: We are only using begin/rescue/end so that the script do not exit #
9
+ # on the first demo. #
10
+ # #
11
+ # You could simply use ok(), warning() without the begin/rescue/end. #
12
+ # -------------------------------------------------------------------------------- #
13
+
14
+ require 'nagios_output'
15
+
16
+ n = NagiosOutput.new
17
+
18
+ begin
19
+ n.ok('Everything is ok (Class))')
20
+ rescue SystemExit => e
21
+ _actual = e
22
+ end
23
+
24
+ begin
25
+ n.warning('Everything is ok-ish (Class)')
26
+ rescue SystemExit => e
27
+ _actual = e
28
+ end
29
+
30
+ begin
31
+ n.critical('Everything is cirtial (Class)')
32
+ rescue SystemExit => e
33
+ _actual = e
34
+ end
35
+
36
+ begin
37
+ n.unknown('Everything is erm - I don\'t know (Class)')
38
+ rescue SystemExit => e
39
+ _actual = e
40
+ end
41
+
42
+ begin
43
+ NagiosOutputStatic.ok('Everything is ok (Static)')
44
+ rescue SystemExit => e
45
+ _actual = e
46
+ end
47
+
48
+ begin
49
+ NagiosOutputStatic.warning('Everything is ok-ish (Static)')
50
+ rescue SystemExit => e
51
+ _actual = e
52
+ end
53
+
54
+ begin
55
+ NagiosOutputStatic.critical('Everything is cirtial (Static)')
56
+ rescue SystemExit => e
57
+ _actual = e
58
+ end
59
+
60
+ begin
61
+ NagiosOutputStatic.unknown('Everything is erm - I don\'t know (Static)')
62
+ rescue SystemExit => e
63
+ _actual = e
64
+ end
65
+
66
+ begin
67
+ ok('Everything is ok (Direct)')
68
+ rescue SystemExit => e
69
+ _actual = e
70
+ end
71
+
72
+ begin
73
+ warning('Everything is ok-ish (Direct)')
74
+ rescue SystemExit => e
75
+ _actual = e
76
+ end
77
+
78
+ begin
79
+ critical('Everything is cirtial (Direct)')
80
+ rescue SystemExit => e
81
+ _actual = e
82
+ end
83
+
84
+ begin
85
+ unknown('Everything is erm - I don\'t know (Direct)')
86
+ rescue SystemExit => e
87
+ _actual = e
88
+ end
@@ -0,0 +1,3 @@
1
+ class NagiosOutput
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,110 @@
1
+ require 'colorize'
2
+ require 'nagios_output/version'
3
+
4
+ # -------------------------------------------------------------------------------- #
5
+ # Description #
6
+ # -------------------------------------------------------------------------------- #
7
+ # Display elapsed time in a more human readable way. #
8
+ # -------------------------------------------------------------------------------- #
9
+
10
+ def ok(message = nil, config = { 'colour' => true })
11
+ n = NagiosOutput.new(config)
12
+ n.ok(message)
13
+ end
14
+
15
+ def warning(message = nil, config = { 'colour' => true })
16
+ n = NagiosOutput.new(config)
17
+ n.warning(message)
18
+ end
19
+
20
+ def critical(message = nil, config = { 'colour' => true })
21
+ n = NagiosOutput.new(config)
22
+ n.critical(message)
23
+ end
24
+
25
+ def unknown(message = nil, config = { 'colour' => true })
26
+ n = NagiosOutput.new(config)
27
+ n.unknown(message)
28
+ end
29
+
30
+ # -------------------------------------------------------------------------------- #
31
+ # Description #
32
+ # -------------------------------------------------------------------------------- #
33
+ # This is a static access wrapper to the main HumanDuration class below. #
34
+ # -------------------------------------------------------------------------------- #
35
+ class NagiosOutputStatic
36
+ def self.ok(message = nil, config = { 'colour' => true })
37
+ n = NagiosOutput.new(config)
38
+ n.ok(message)
39
+ end
40
+
41
+ def self.warning(message = nil, config = { 'colour' => true })
42
+ n = NagiosOutput.new(config)
43
+ n.warning(message)
44
+ end
45
+
46
+ def self.critical(message = nil, config = { 'colour' => true })
47
+ n = NagiosOutput.new(config)
48
+ n.critical(message)
49
+ end
50
+
51
+ def self.unknown(message = nil, config = { 'colour' => true })
52
+ n = NagiosOutput.new(config)
53
+ n.unknown(message)
54
+ end
55
+ end
56
+
57
+ # -------------------------------------------------------------------------------- #
58
+ # Description #
59
+ # -------------------------------------------------------------------------------- #
60
+ # Display elapsed time in a more human readable way. #
61
+ # -------------------------------------------------------------------------------- #
62
+ class NagiosOutput
63
+ def initialize(config = { 'colour' => true })
64
+ @colour = config['colour']
65
+ end
66
+
67
+ def ok(message = nil)
68
+ exit 0 if message.nil? || message.empty?
69
+
70
+ if @colour
71
+ puts "OK - #{message}".green
72
+ else
73
+ puts "OK - #{message}"
74
+ end
75
+ exit 0
76
+ end
77
+
78
+ def warning(message = nil)
79
+ exit 1 if message.nil? || message.empty?
80
+
81
+ if @colour
82
+ puts "WARNING - #{message}".yellow
83
+ else
84
+ puts "WARNING - #{message}"
85
+ end
86
+ exit 1
87
+ end
88
+
89
+ def critical(message = nil)
90
+ exit 2 if message.nil? || message.empty?
91
+
92
+ if @colour
93
+ puts "CRITICAL - #{message}".red
94
+ else
95
+ puts "CRITICAL - #{message}"
96
+ end
97
+ exit 2
98
+ end
99
+
100
+ def unknown(message = nil)
101
+ exit 3 if message.nil? || message.empty?
102
+
103
+ if @colour
104
+ puts "UNKNOWN - #{message}".blue
105
+ else
106
+ puts "UNKNOWN - #{message}"
107
+ end
108
+ exit 3
109
+ end
110
+ end
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nagios_output/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nagios_output"
8
+ spec.version = NagiosOutput::VERSION
9
+ spec.authors = ["Tim Gurney aka Wolf"]
10
+ spec.email = ["wolf@tgwolf.com"]
11
+
12
+ spec.summary = %q{A simple gem for creating output for a nagios check script.}
13
+ spec.description = %q{A simple gem for creating output for a nagios check script.}
14
+ spec.homepage = "https://github.com/AntiPhotonltd/nagios_output"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ #spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ # `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ #end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "colorize", "~> 0.8.1"
32
+ end
@@ -0,0 +1,507 @@
1
+ # rubocop:disable Metrics/BlockLength
2
+
3
+ require 'nagios_output'
4
+
5
+ RSpec.describe NagiosOutput do
6
+ it 'has a version number' do
7
+ expect(NagiosOutput::VERSION).not_to be nil
8
+ end
9
+
10
+ context 'Test ok()' do
11
+ context 'Class method access' do
12
+ before(:each) do
13
+ @n = NagiosOutput.new
14
+ end
15
+
16
+ context 'With a message' do
17
+ it 'says OK - test 1 2 3' do
18
+ begin
19
+ expect(@n.ok('test 1 2 3')).to eql('OK - test 1 2 3')
20
+ rescue SystemExit => e
21
+ _actual = e.status
22
+ end
23
+ end
24
+
25
+ it 'the exit value should be 0' do
26
+ begin
27
+ @n.ok('test 1 2 3')
28
+ rescue SystemExit => e
29
+ expect(e.status).to eq(0)
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'Without a message' do
35
+ it 'says nothing at all' do
36
+ begin
37
+ expect(@n.ok).to eql
38
+ rescue SystemExit => e
39
+ _actual = e.status
40
+ end
41
+ end
42
+
43
+ it 'the exit value should be 0' do
44
+ begin
45
+ @n.ok
46
+ rescue SystemExit => e
47
+ expect(e.status).to eq(0)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'Static method access' do
54
+ before(:each) do
55
+ @n = NagiosOutputStatic
56
+ end
57
+
58
+ context 'With a message' do
59
+ it 'says OK - test 1 2 3' do
60
+ begin
61
+ expect(@n.ok('test 1 2 3')).to eql('OK - test 1 2 3')
62
+ rescue SystemExit => e
63
+ _actual = e.status
64
+ end
65
+ end
66
+
67
+ it 'the exit value should be 0' do
68
+ begin
69
+ @n.ok('test 1 2 3')
70
+ rescue SystemExit => e
71
+ expect(e.status).to eq(0)
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'Without a message' do
77
+ it 'says nothing at all' do
78
+ begin
79
+ expect(@n.ok).to eql
80
+ rescue SystemExit => e
81
+ _actual = e.status
82
+ end
83
+ end
84
+
85
+ it 'the exit value should be 0' do
86
+ begin
87
+ @n.ok
88
+ rescue SystemExit => e
89
+ expect(e.status).to eq(0)
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'Direct method access' do
96
+ context 'With a message' do
97
+ it 'says OK - test 1 2 3' do
98
+ begin
99
+ expect(ok('test 1 2 3')).to eql('OK - test 1 2 3')
100
+ rescue SystemExit => e
101
+ _actual = e.status
102
+ end
103
+ end
104
+
105
+ it 'the exit value should be 0' do
106
+ begin
107
+ ok('test 1 2 3')
108
+ rescue SystemExit => e
109
+ expect(e.status).to eq(0)
110
+ end
111
+ end
112
+ end
113
+
114
+ context 'Without a message' do
115
+ it 'says nothing at all' do
116
+ begin
117
+ expect(ok).to eql
118
+ rescue SystemExit => e
119
+ _actual = e.status
120
+ end
121
+ end
122
+
123
+ it 'the exit value should be 0' do
124
+ begin
125
+ ok
126
+ rescue SystemExit => e
127
+ expect(e.status).to eq(0)
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ context 'Test warning()' do
135
+ context 'Class method access' do
136
+ before(:each) do
137
+ @n = NagiosOutput.new
138
+ end
139
+
140
+ context 'With a message' do
141
+ it 'says WARNING - test 1 2 3' do
142
+ begin
143
+ expect(@n.warning('test 1 2 3')).to eql('WARNING - test 1 2 3')
144
+ rescue SystemExit => e
145
+ _actual = e.status
146
+ end
147
+ end
148
+
149
+ it 'the exit value should be 1' do
150
+ begin
151
+ @n.warning('test 1 2 3')
152
+ rescue SystemExit => e
153
+ expect(e.status).to eq(1)
154
+ end
155
+ end
156
+ end
157
+
158
+ context 'Without a message' do
159
+ it 'says nothing at all' do
160
+ begin
161
+ expect(@n.warning).to eql
162
+ rescue SystemExit => e
163
+ _actual = e.status
164
+ end
165
+ end
166
+
167
+ it 'the exit value should be 1' do
168
+ begin
169
+ @n.warning
170
+ rescue SystemExit => e
171
+ expect(e.status).to eq(1)
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ context 'Static method access' do
178
+ before(:each) do
179
+ @n = NagiosOutputStatic
180
+ end
181
+
182
+ context 'With a message' do
183
+ it 'says Warning - test 1 2 3' do
184
+ begin
185
+ expect(@n.warning('test 1 2 3')).to eql('WARNING - test 1 2 3')
186
+ rescue SystemExit => e
187
+ _actual = e.status
188
+ end
189
+ end
190
+
191
+ it 'the exit value should be 1' do
192
+ begin
193
+ @n.warning('test 1 2 3')
194
+ rescue SystemExit => e
195
+ expect(e.status).to eq(1)
196
+ end
197
+ end
198
+ end
199
+
200
+ context 'Without a message' do
201
+ it 'says nothing at all' do
202
+ begin
203
+ expect(@n.warning).to eql
204
+ rescue SystemExit => e
205
+ _actual = e.status
206
+ end
207
+ end
208
+
209
+ it 'the exit value should be 0' do
210
+ begin
211
+ @n.warning
212
+ rescue SystemExit => e
213
+ expect(e.status).to eq(1)
214
+ end
215
+ end
216
+ end
217
+ end
218
+
219
+ context 'Direct method access' do
220
+ context 'With a message' do
221
+ it 'says WARNING - test 1 2 3' do
222
+ begin
223
+ expect(warning('test 1 2 3')).to eql('WARNING - test 1 2 3')
224
+ rescue SystemExit => e
225
+ _actual = e.status
226
+ end
227
+ end
228
+
229
+ it 'the exit value should be 1' do
230
+ begin
231
+ warning('test 1 2 3')
232
+ rescue SystemExit => e
233
+ expect(e.status).to eq(1)
234
+ end
235
+ end
236
+ end
237
+
238
+ context 'Without a message' do
239
+ it 'says nothing at all' do
240
+ begin
241
+ expect(warning).to eql
242
+ rescue SystemExit => e
243
+ _actual = e.status
244
+ end
245
+ end
246
+
247
+ it 'the exit value should be 1' do
248
+ begin
249
+ warning
250
+ rescue SystemExit => e
251
+ expect(e.status).to eq(1)
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end
257
+
258
+ context 'Test critical()' do
259
+ context 'Class method access' do
260
+ before(:each) do
261
+ @n = NagiosOutput.new
262
+ end
263
+
264
+ context 'With a message' do
265
+ it 'says CRITICAL - test 1 2 3' do
266
+ begin
267
+ expect(@n.critical('test 1 2 3')).to eql('CRITICAL - test 1 2 3')
268
+ rescue SystemExit => e
269
+ _actual = e.status
270
+ end
271
+ end
272
+
273
+ it 'the exit value should be 2' do
274
+ begin
275
+ @n.critical('test 1 2 3')
276
+ rescue SystemExit => e
277
+ expect(e.status).to eq(2)
278
+ end
279
+ end
280
+ end
281
+
282
+ context 'Without a message' do
283
+ it 'says nothing at all' do
284
+ begin
285
+ expect(@n.critical).to eql
286
+ rescue SystemExit => e
287
+ _actual = e.status
288
+ end
289
+ end
290
+
291
+ it 'the exit value should be 2' do
292
+ begin
293
+ @n.critical
294
+ rescue SystemExit => e
295
+ expect(e.status).to eq(2)
296
+ end
297
+ end
298
+ end
299
+ end
300
+
301
+ context 'Static method access' do
302
+ before(:each) do
303
+ @n = NagiosOutputStatic
304
+ end
305
+
306
+ context 'With a message' do
307
+ it 'says CRITICAL - test 1 2 3' do
308
+ begin
309
+ expect(@n.critical('test 1 2 3')).to eql('CRITICAL - test 1 2 3')
310
+ rescue SystemExit => e
311
+ _actual = e.status
312
+ end
313
+ end
314
+
315
+ it 'the exit value should be 2' do
316
+ begin
317
+ @n.critical('test 1 2 3')
318
+ rescue SystemExit => e
319
+ expect(e.status).to eq(2)
320
+ end
321
+ end
322
+ end
323
+
324
+ context 'Without a message' do
325
+ it 'says nothing at all' do
326
+ begin
327
+ expect(@n.critical).to eql
328
+ rescue SystemExit => e
329
+ _actual = e.status
330
+ end
331
+ end
332
+
333
+ it 'the exit value should be 2' do
334
+ begin
335
+ @n.critical
336
+ rescue SystemExit => e
337
+ expect(e.status).to eq(2)
338
+ end
339
+ end
340
+ end
341
+ end
342
+
343
+ context 'Direct method access' do
344
+ context 'With a message' do
345
+ it 'says CRITICAL - test 1 2 3' do
346
+ begin
347
+ expect(critical('test 1 2 3')).to eql('CRITICAL - test 1 2 3')
348
+ rescue SystemExit => e
349
+ _actual = e.status
350
+ end
351
+ end
352
+
353
+ it 'the exit value should be 2' do
354
+ begin
355
+ critical('test 1 2 3')
356
+ rescue SystemExit => e
357
+ expect(e.status).to eq(2)
358
+ end
359
+ end
360
+ end
361
+
362
+ context 'Without a message' do
363
+ it 'says nothing at all' do
364
+ begin
365
+ expect(critical).to eql
366
+ rescue SystemExit => e
367
+ _actual = e.status
368
+ end
369
+ end
370
+
371
+ it 'the exit value should be 2' do
372
+ begin
373
+ critical
374
+ rescue SystemExit => e
375
+ expect(e.status).to eq(2)
376
+ end
377
+ end
378
+ end
379
+ end
380
+ end
381
+
382
+ context 'Test unknown()' do
383
+ context 'Class method access' do
384
+ before(:each) do
385
+ @n = NagiosOutput.new
386
+ end
387
+
388
+ context 'With a message' do
389
+ it 'says UNKNOWN - test 1 2 3' do
390
+ begin
391
+ expect(@n.unknown('test 1 2 3')).to eql('UNKNOWN - test 1 2 3')
392
+ rescue SystemExit => e
393
+ _actual = e.status
394
+ end
395
+ end
396
+
397
+ it 'the exit value should be 3' do
398
+ begin
399
+ @n.unknown('test 1 2 3')
400
+ rescue SystemExit => e
401
+ expect(e.status).to eq(3)
402
+ end
403
+ end
404
+ end
405
+
406
+ context 'Without a message' do
407
+ it 'says nothing at all' do
408
+ begin
409
+ expect(@n.unknown).to eql
410
+ rescue SystemExit => e
411
+ _actual = e.status
412
+ end
413
+ end
414
+
415
+ it 'the exit value should be 3' do
416
+ begin
417
+ @n.unknown
418
+ rescue SystemExit => e
419
+ expect(e.status).to eq(3)
420
+ end
421
+ end
422
+ end
423
+ end
424
+
425
+ context 'Static method access' do
426
+ before(:each) do
427
+ @n = NagiosOutputStatic
428
+ end
429
+
430
+ context 'With a message' do
431
+ it 'says WARNING - test 1 2 3' do
432
+ begin
433
+ expect(@n.unknown('test 1 2 3')).to eql('WARNING - test 1 2 3')
434
+ rescue SystemExit => e
435
+ _actual = e.status
436
+ end
437
+ end
438
+
439
+ it 'the exit value should be 3' do
440
+ begin
441
+ @n.unknown('test 1 2 3')
442
+ rescue SystemExit => e
443
+ expect(e.status).to eq(3)
444
+ end
445
+ end
446
+ end
447
+
448
+ context 'Without a message' do
449
+ it 'says nothing at all' do
450
+ begin
451
+ expect(@n.unknown).to eql
452
+ rescue SystemExit => e
453
+ _actual = e.status
454
+ end
455
+ end
456
+
457
+ it 'the exit value should be 3' do
458
+ begin
459
+ @n.unknown
460
+ rescue SystemExit => e
461
+ expect(e.status).to eq(3)
462
+ end
463
+ end
464
+ end
465
+ end
466
+
467
+ context 'Direct method access' do
468
+ context 'With a message' do
469
+ it 'says UNKNOWN - test 1 2 3' do
470
+ begin
471
+ expect(unknown('test 1 2 3')).to eql('UNKNOWN - test 1 2 3')
472
+ rescue SystemExit => e
473
+ _actual = e.status
474
+ end
475
+ end
476
+
477
+ it 'the exit value should be 3' do
478
+ begin
479
+ unknown('test 1 2 3')
480
+ rescue SystemExit => e
481
+ expect(e.status).to eq(3)
482
+ end
483
+ end
484
+ end
485
+
486
+ context 'Without a message' do
487
+ it 'says nothing at all' do
488
+ begin
489
+ expect(unknown).to eql
490
+ rescue SystemExit => e
491
+ _actual = e.status
492
+ end
493
+ end
494
+
495
+ it 'the exit value should be 3' do
496
+ begin
497
+ unknown
498
+ rescue SystemExit => e
499
+ expect(e.status).to eq(3)
500
+ end
501
+ end
502
+ end
503
+ end
504
+ end
505
+ end
506
+
507
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,26 @@
1
+ require 'bundler/setup'
2
+ require 'nagios_output'
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = '.rspec_status'
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+
15
+ original_stderr = $stderr
16
+ original_stdout = $stdout
17
+ config.before(:all) do
18
+ # Redirect stderr and stdout
19
+ $stderr = File.open(File::NULL, 'w')
20
+ $stdout = File.open(File::NULL, 'w')
21
+ end
22
+ config.after(:all) do
23
+ $stderr = original_stderr
24
+ $stdout = original_stdout
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nagios_output
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Gurney aka Wolf
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-18 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ description: A simple gem for creating output for a nagios check script.
70
+ email:
71
+ - wolf@tgwolf.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
81
+ - CODEOWNERS
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - example/example.rb
90
+ - lib/nagios_output.rb
91
+ - lib/nagios_output/version.rb
92
+ - nagios_output.gemspec
93
+ - spec/nagios_output_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: https://github.com/AntiPhotonltd/nagios_output
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A simple gem for creating output for a nagios check script.
118
+ test_files: []