Class: NagiosOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/nagios_output.rb,
lib/nagios_output/version.rb

Overview

——————————————————————————– # Description # ——————————————————————————– # Display elapsed time in a more human readable way. # ——————————————————————————– #

Constant Summary collapse

VERSION =
'1.0.0'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config = { 'colour' => true }) ⇒ NagiosOutput

Returns a new instance of NagiosOutput.



63
64
65
# File 'lib/nagios_output.rb', line 63

def initialize(config = { 'colour' => true })
    @colour = config['colour']
end

Instance Method Details

#critical(message = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/nagios_output.rb', line 89

def critical(message = nil)
    exit 2 if message.nil? || message.empty?

    if @colour
        puts "CRITICAL - #{message}".red
    else
        puts "CRITICAL - #{message}"
    end
    exit 2
end

#ok(message = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/nagios_output.rb', line 67

def ok(message = nil)
    exit 0 if message.nil? || message.empty?

    if @colour
        puts "OK - #{message}".green
    else
        puts "OK - #{message}"
    end
    exit 0
end

#unknown(message = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
# File 'lib/nagios_output.rb', line 100

def unknown(message = nil)
    exit 3 if message.nil? || message.empty?

    if @colour
        puts "UNKNOWN - #{message}".blue
    else
        puts "UNKNOWN - #{message}"
    end
    exit 3
end

#warning(message = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/nagios_output.rb', line 78

def warning(message = nil)
    exit 1 if message.nil? || message.empty?

    if @colour
        puts "WARNING - #{message}".yellow
    else
        puts "WARNING - #{message}"
    end
    exit 1
end