Module: Naplug::InstanceMethods
- Defined in:
- lib/naplug.rb
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#args ⇒ Hash
Returns the arguments of the plugin.
-
#args!(args) ⇒ Object
Sets and propagates plugin arguments.
- #eject!(payload = nil) ⇒ Object
- #eval(tag = default_plugin.tag) ⇒ Object
- #eval!(tag = default_plugin.tag) ⇒ Object
-
#exec(t = default_plugin.tag) ⇒ Object
Execute the plugin.
-
#exec!(tag = default_plugin.tag) ⇒ Object
Execute, evaluate and exit the plugin according to the plugin status, outputting the plugin’s text output (and performance data, if applicable).
- #initialize(args = {}) ⇒ Object
-
#perfdata(tag = default_plugin.tag) ⇒ Array<PerformanceData>
A list of performance data objects.
- #to_str(tag = default_plugin.tag) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
202 203 204 205 206 207 208 209 210 |
# File 'lib/naplug.rb', line 202 def method_missing(method, *args, &block) = "undefined instance variable or method #{method}" case @_runinng when nil? begin; raise Naplug::Error, ; rescue => e; eject! e ; end else raise Naplug::Error, end end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
71 72 73 |
# File 'lib/naplug.rb', line 71 def plugins @plugins end |
Instance Method Details
#args ⇒ Hash
Returns the arguments of the plugin
83 84 85 |
# File 'lib/naplug.rb', line 83 def args @_args end |
#args!(args) ⇒ Object
Sets and propagates plugin arguments
89 90 91 92 93 94 95 96 |
# File 'lib/naplug.rb', line 89 def args!(args) @_args.merge! args @plugins.each do |tag,plugin| plugin_args = args.key?(tag) ? args[tag] : {} shared_args = args.select { |t,a| not @plugins.keys.include? t } plugin.args! shared_args.merge! plugin_args end end |
#eject!(payload = nil) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/naplug.rb', line 141 def eject!(payload = nil) o = case payload when String then payload when Exception then "#{payload.backtrace[1][/.+:\d+/]}: #{payload.message}" else nil caller[0][/.+:\d+/] end print "UNKNOWN: plugin eject! in %s\n" % [o] Kernel::exit 3 end |
#eval(tag = default_plugin.tag) ⇒ Object
132 133 134 |
# File 'lib/naplug.rb', line 132 def eval(tag = default_plugin.tag) @plugins[tag].eval end |
#eval!(tag = default_plugin.tag) ⇒ Object
136 137 138 139 |
# File 'lib/naplug.rb', line 136 def eval!(tag = default_plugin.tag) @plugins[tag].eval exit tag end |
#exec(t = default_plugin.tag) ⇒ Object
Execute the plugin
123 124 125 126 127 128 129 130 |
# File 'lib/naplug.rb', line 123 def exec(t = default_plugin.tag) plugin = target_plugin t if plugin.has_plugins? plugin.plugins.each_value { |p| exec p } else plexec plugin end end |
#exec!(tag = default_plugin.tag) ⇒ Object
Execute, evaluate and exit the plugin according to the plugin status, outputting the plugin’s text output (and performance data, if applicable)
112 113 114 115 116 117 118 119 |
# File 'lib/naplug.rb', line 112 def exec!(tag = default_plugin.tag) t = Benchmark.realtime do exec tag eval tag end # @plugins[tag].perfdata! "monitoring.#{File.basename($0)}.#{tag}", t if @plugins[tag].meta.benchmark exit tag end |
#initialize(args = {}) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/naplug.rb', line 73 def initialize(args = {}) @plugins = Hash.new plugins! @_args = Hash.new args! args end |
#perfdata(tag = default_plugin.tag) ⇒ Array<PerformanceData>
Returns a list of performance data objects.
153 154 155 |
# File 'lib/naplug.rb', line 153 def perfdata(tag = default_plugin.tag) @plugins[tag].perfdata(:deep).flatten.select { |pd| pd} end |
#to_str(tag = default_plugin.tag) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/naplug.rb', line 98 def to_str(tag = default_plugin.tag) pd = perfdata(tag) if pd.empty? s_format = '%s: %s' s_array = [@plugins[tag].status,@plugins[tag].output] else s_format = '%s: %s | %s' s_array = [@plugins[tag].status,@plugins[tag].output,pd.join(' ').strip] end s_format % s_array end |