Module: MuninManager::ActsAsMuninPlugin::ClassMethods

Defined in:
lib/munin_manager/acts_as_munin_plugin.rb

Instance Method Summary collapse

Instance Method Details

#help_text(options = {}) ⇒ Object



26
27
28
# File 'lib/munin_manager/acts_as_munin_plugin.rb', line 26

def help_text(options = {})
  # Any general info concerning the plugin. Should be overriden by included class
end

#install(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/munin_manager/acts_as_munin_plugin.rb', line 30

def install(options)
  install_as = options.install_name.split(":").last
  symlink = File.join(options.plugin_dir, install_as)
  runner = File.join(File.dirname(__FILE__), "..", "..", "bin", "runner")
  runner = File.expand_path(runner)

  if File.exists?(symlink)
    if options.force
      File.unlink(symlink)
    else
      STDERR.puts "'%s' already exists. Please specify --force option to overwrite" % symlink
      return
    end
  end

  STDOUT.puts "Installing '%s' at '%s'" % [plugin_name, symlink]
  FileUtils.ln_sf(runner, symlink)

  STDOUT.puts help_text(:symlink => install_as)

rescue Errno::EACCES
  STDERR.puts "ERROR: Permission denied while attempting to install to '%s'" % symlink
end

#plugin_nameObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/munin_manager/acts_as_munin_plugin.rb', line 15

def plugin_name
  # Name of the plugin. Must not contain spaces or special chars
  
  # Default is underscorized version of the class name
  self.name.split('::').last.
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end

#runObject



11
12
13
# File 'lib/munin_manager/acts_as_munin_plugin.rb', line 11

def run
  raise "This is the entry point of the plugin when invoked by munin. Needs implementation by included class"
end

#uninstall(options) ⇒ Object

Default uninstaller. Override in included classes if the default is not sufficient



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/munin_manager/acts_as_munin_plugin.rb', line 55

def uninstall(options)
  install_as = options.install_name.split(":").last
  symlink = File.join(options.plugin_dir, install_as)

  unless File.exists?(symlink)
    STDERR.puts "'%s' does not seem to exist. Aborting..." % symlink
    return
  end

  unless File.symlink?(symlink) || options.force
    STDERR.puts "'%s' does not appear to be a symlink. Please specify --force option to remove" % symlink
    return
  end

  STDOUT.puts "Removing '%s'..." % symlink
  File.unlink(symlink)
rescue Errno::EACCES
  STDERR.puts "ERROR: Permission denied while attempting to uninstall '%s'" % symlink
end