Class: Nagi::DSL
- Inherits:
-
Object
- Object
- Nagi::DSL
- Defined in:
- lib/nagi/dsl.rb
Instance Attribute Summary collapse
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
Instance Method Summary collapse
- #argument(name) ⇒ Object
- #check(&block) ⇒ Object
- #collect(type) ⇒ Object
- #critical(message, force = false) ⇒ Object
- #execute(command) ⇒ Object
- #fallback(status, message) ⇒ Object
-
#initialize(&block) ⇒ DSL
constructor
A new instance of DSL.
- #name(name) ⇒ Object
- #ok(message, force = false) ⇒ Object
- #prefix(prefix) ⇒ Object
- #switch(name, *args) ⇒ Object
- #unknown(message, force = false) ⇒ Object
- #version(version) ⇒ Object
- #warning(message, force = false) ⇒ Object
Constructor Details
Instance Attribute Details
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
3 4 5 |
# File 'lib/nagi/dsl.rb', line 3 def plugin @plugin end |
Instance Method Details
#argument(name) ⇒ Object
12 13 14 |
# File 'lib/nagi/dsl.rb', line 12 def argument(name) @plugin.optionparser.argument(name) end |
#check(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nagi/dsl.rb', line 16 def check(&block) # make data available to block collect = @collect collected = @collected p = class << @plugin; self; end p.send(:define_method, :check) do || status = catch(:status) { block.call() nil # to avoid returning status if not thrown } return status if status or not collect return nil if collected.empty? return collected.reverse.max if collect == :severe return collected.reverse.max.class.new( collected.map { |s| s. }.join(', ') ) if collect == :all return nil end end |
#collect(type) ⇒ Object
37 38 39 40 |
# File 'lib/nagi/dsl.rb', line 37 def collect(type) raise "Invalid collect type #{type.to_s}" unless [:all, :severe].include?(type) @collect = type end |
#critical(message, force = false) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/nagi/dsl.rb', line 42 def critical(, force=false) status = Nagi::Status::Critical.new() throw :status, status if force or not @collect @collected.push(status) return status end |
#execute(command) ⇒ Object
49 50 51 |
# File 'lib/nagi/dsl.rb', line 49 def execute(command) return Nagi::Utility.execute(command) end |
#fallback(status, message) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/nagi/dsl.rb', line 53 def fallback(status, ) @plugin.fallback = case status when :ok then Nagi::Status::OK.new() when :warning then Nagi::Status::Warning.new() when :critical then Nagi::Status::Critical.new() when :unknown then Nagi::Status::Unknown.new() else raise "Unknown fallback status #{status}" end end |
#name(name) ⇒ Object
63 64 65 |
# File 'lib/nagi/dsl.rb', line 63 def name(name) @plugin.name = name end |
#ok(message, force = false) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/nagi/dsl.rb', line 67 def ok(, force=false) status = Nagi::Status::OK.new() throw :status, status if force or not @collect @collected.push(status) return status end |
#prefix(prefix) ⇒ Object
74 75 76 |
# File 'lib/nagi/dsl.rb', line 74 def prefix(prefix) @plugin.prefix = prefix end |
#switch(name, *args) ⇒ Object
78 79 80 |
# File 'lib/nagi/dsl.rb', line 78 def switch(name, *args) @plugin.optionparser.switch(name, *args) end |
#unknown(message, force = false) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/nagi/dsl.rb', line 82 def unknown(, force=false) status = Nagi::Status::Unknown.new() throw :status, status if force or not @collect @collected.push(status) return status end |
#version(version) ⇒ Object
89 90 91 |
# File 'lib/nagi/dsl.rb', line 89 def version(version) @plugin.version = version end |