class Naplug::Plugin
Attributes
block[R]
plugins[R]
tag[R]
Public Class Methods
new(tag, block, meta)
click to toggle source
# File lib/naplug/plugin.rb, line 17 def initialize(tag, block, meta) @tag = tag @block = block @plugins = Hash.new @_args = Hash.new @_data = OpenStruct.new :status => Status.new, :output => Output.new, :payload => nil, :perfdata => nil @_meta = Meta.new meta begin instance_eval &block rescue ArgumentError => e raise rescue nil end end
Public Instance Methods
[](k)
click to toggle source
# File lib/naplug/plugin.rb, line 116 def [](k) @_args[k] end
[]=(k,v)
click to toggle source
# File lib/naplug/plugin.rb, line 120 def []=(k,v) @_args[k] = v end
args()
click to toggle source
# File lib/naplug/plugin.rb, line 103 def args @_args end
args!(args)
click to toggle source
# File lib/naplug/plugin.rb, line 107 def args!(args) @_args.merge! args @plugins.each do |tag,plug| plug_args = args.key?(tag) ? args[tag] : {} shared_args = args.select { |t,a| not @plugins.keys.include? t } plug.args! shared_args.merge! plug_args end end
description()
click to toggle source
# File lib/naplug/plugin.rb, line 44 def description @_meta.description end
eval()
click to toggle source
# File lib/naplug/plugin.rb, line 128 def eval unless @plugins.empty? wcu_plugins = @plugins.values.select { |plug| plug.status.not_ok? } plugins = wcu_plugins.empty? ? @plugins.values : wcu_plugins output! plugins.map { |plug| "[#{plug.status.to_y}#{plug.tag} #{plug.output}]" }.join(' ') @_data.status = plugins.map { |plug| plug.status }.max end end
has_plugins?()
click to toggle source
true when a plugin contains plugs
# File lib/naplug/plugin.rb, line 49 def has_plugins? @plugins.empty? ? false : true end
Also aliased as: has_plugs?
long_output()
click to toggle source
# File lib/naplug/plugin.rb, line 72 def long_output @_data.output.long_output end
long_output!(long_output)
click to toggle source
# File lib/naplug/plugin.rb, line 76 def long_output!(long_output) @_data.output.push long_output end
meta()
click to toggle source
# File lib/naplug/plugin.rb, line 36 def meta @_meta end
output()
click to toggle source
Gets plugin text output @return [String] plugin text output
# File lib/naplug/plugin.rb, line 61 def output @_data.output end
output!(text_output)
click to toggle source
Sets plugin text output @param text_output [String] plugin text output @return [String] new plugin text output
# File lib/naplug/plugin.rb, line 68 def output!(text_output) @_data.output.text_output = text_output end
parent()
click to toggle source
# File lib/naplug/plugin.rb, line 40 def parent @_meta.parent end
payload()
click to toggle source
# File lib/naplug/plugin.rb, line 95 def payload @_data.payload end
payload!(p)
click to toggle source
# File lib/naplug/plugin.rb, line 99 def payload!(p) @_data.payload = p end
perfdata(mode = nil)
click to toggle source
returns the performance data of the plugin as a PerformanceData
object
# File lib/naplug/plugin.rb, line 81 def perfdata(mode = nil) case mode when :deep plugins.values.map { |p| p.perfdata :deep }.push @_data.perfdata else @_data.perfdata end end
perfdata!(label,value,f = {})
click to toggle source
# File lib/naplug/plugin.rb, line 90 def perfdata!(label,value,f = {}) @_data.perfdata ||= PerformanceData.new self @_data.perfdata[label] = value, f end
status()
click to toggle source
@return [Status] plugin status
# File lib/naplug/plugin.rb, line 55 def status @_data.status end
to_str()
click to toggle source
# File lib/naplug/plugin.rb, line 124 def to_str '%s: %s' % [status,output] end
Private Instance Methods
debug?()
click to toggle source
# File lib/naplug/plugin.rb, line 148 def debug? @_meta.debug end
plugin(*tagmeta, &block)
click to toggle source
# File lib/naplug/plugin.rb, line 139 def plugin(*tagmeta, &block) tag,meta = tagmeta_grok(tagmeta) raise Naplug::Error, "duplicate definition of #{tag}" if @plugins.key? tag @plugins[tag] = Plugin.new tag, block, meta.merge({ :parent => self }) self.define_singleton_method tag do @plugins[tag] end end