mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Command line arguments added and handled.
This commit is contained in:
parent
583d318c62
commit
7c40b520a8
@ -1,7 +1,9 @@
|
|||||||
PyPMMN
|
PyPMMN
|
||||||
======
|
======
|
||||||
|
|
||||||
PyPMMN is a pure python port of pmmn_.
|
PyPMMN is a pure python port of pmmn_. One small change. Instead of using the
|
||||||
|
current working dir as ``plugins`` folder, it will look for a *subdirectory*
|
||||||
|
called ``plugins`` in the current working folder.
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
============
|
============
|
||||||
|
@ -11,11 +11,6 @@ import sys
|
|||||||
__version__ = '1.0dev3'
|
__version__ = '1.0dev3'
|
||||||
|
|
||||||
|
|
||||||
spoolfetch_dir = ''
|
|
||||||
plugin_dir = 'plugins'
|
|
||||||
host = 'hostname'
|
|
||||||
|
|
||||||
|
|
||||||
class CmdHandler(object):
|
class CmdHandler(object):
|
||||||
|
|
||||||
def __init__(self, in_stream, out_stream, options):
|
def __init__(self, in_stream, out_stream, options):
|
||||||
@ -27,14 +22,15 @@ class CmdHandler(object):
|
|||||||
"""
|
"""
|
||||||
Prints the version of this instance.
|
Prints the version of this instance.
|
||||||
"""
|
"""
|
||||||
self.out_stream.write('pypmmn on %s version: %s' % (host,
|
self.out_stream.write('pypmmn on %s version: %s' % (
|
||||||
|
self.options.host,
|
||||||
__version__))
|
__version__))
|
||||||
|
|
||||||
def do_nodes(self, arg):
|
def do_nodes(self, arg):
|
||||||
"""
|
"""
|
||||||
Prints this hostname
|
Prints this hostname
|
||||||
"""
|
"""
|
||||||
self.out_stream.write('%s\n' % host)
|
self.out_stream.write('%s\n' % self.options.host)
|
||||||
self.out_stream.write('.')
|
self.out_stream.write('.')
|
||||||
|
|
||||||
def do_quit(self, arg):
|
def do_quit(self, arg):
|
||||||
@ -48,19 +44,19 @@ class CmdHandler(object):
|
|||||||
Print a list of plugins
|
Print a list of plugins
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
for filename in listdir(plugin_dir):
|
for filename in listdir(self.options.plugin_dir):
|
||||||
if not access(join(plugin_dir, filename), X_OK):
|
if not access(join(self.options.plugin_dir, filename), X_OK):
|
||||||
continue
|
continue
|
||||||
self.out_stream.write("%s " % filename)
|
self.out_stream.write("%s " % filename)
|
||||||
except OSError, exc:
|
except OSError, exc:
|
||||||
sys.stdout.writte("# ERROR: %s" % exc)
|
sys.stdout.write("# ERROR: %s" % exc)
|
||||||
|
|
||||||
def _caf(self, arg, cmd):
|
def _caf(self, arg, cmd):
|
||||||
"""
|
"""
|
||||||
handler for ``config``, ``alert`` and ``fetch``
|
handler for ``config``, ``alert`` and ``fetch``
|
||||||
Calls the plugin with ``cmd`` as only argument.
|
Calls the plugin with ``cmd`` as only argument.
|
||||||
"""
|
"""
|
||||||
plugin_filename = join(plugin_dir, arg)
|
plugin_filename = join(self.options.plugin_dir, arg)
|
||||||
if isdir(plugin_filename) or not access(plugin_filename, X_OK):
|
if isdir(plugin_filename) or not access(plugin_filename, X_OK):
|
||||||
self.out_stream.write("# Unknown plugin [%s] for %s" % (arg, cmd))
|
self.out_stream.write("# Unknown plugin [%s] for %s" % (arg, cmd))
|
||||||
return
|
return
|
||||||
@ -88,11 +84,13 @@ class CmdHandler(object):
|
|||||||
|
|
||||||
def do_cap(self, arg):
|
def do_cap(self, arg):
|
||||||
self.out_stream.write("cap ")
|
self.out_stream.write("cap ")
|
||||||
if spoolfetch_dir:
|
if self.options.spoolfetch_dir:
|
||||||
self.out_stream.write("spool ")
|
self.out_stream.write("spool ")
|
||||||
|
|
||||||
def do_spoolfetch(self, arg):
|
def do_spoolfetch(self, arg):
|
||||||
call(['%s/spoolfetch_%s' % (spoolfetch_dir, host), arg])
|
call(['%s/spoolfetch_%s' % (self.options.spoolfetch_dir,
|
||||||
|
self.options.host),
|
||||||
|
arg])
|
||||||
self.out_stream.write('.')
|
self.out_stream.write('.')
|
||||||
|
|
||||||
# aliases
|
# aliases
|
||||||
@ -138,14 +136,14 @@ def get_options():
|
|||||||
default=None,
|
default=None,
|
||||||
help='TCP Port to listen on. (If not specified, use stdin/stdout)')
|
help='TCP Port to listen on. (If not specified, use stdin/stdout)')
|
||||||
parser.add_option('-d', '--plugin-dir', dest='plugin_dir',
|
parser.add_option('-d', '--plugin-dir', dest='plugin_dir',
|
||||||
default='.',
|
default='plugins',
|
||||||
help=('The directory containing the munin-plugins.'
|
help=('The directory containing the munin-plugins.'
|
||||||
' Default: <current dir>'))
|
' Default: <current working dir>/plugins'))
|
||||||
parser.add_option('-h', '--host', dest='host',
|
parser.add_option('-h', '--host', dest='host',
|
||||||
help=('The hostname which will be reported in the pluging.'
|
help=('The hostname which will be reported in the plugins.'
|
||||||
' Default: %s' % gethostname()),
|
' Default: %s' % gethostname()),
|
||||||
default=gethostname())
|
default=gethostname())
|
||||||
parser.add_option('-s', '--spoolfech-dir', dest='spoolfech_dir',
|
parser.add_option('-s', '--spoolfech-dir', dest='spoolfetch_dir',
|
||||||
default=None,
|
default=None,
|
||||||
help='The spoolfetch folder. Default: disabled')
|
help='The spoolfetch folder. Default: disabled')
|
||||||
parser.add_option('--help', action='callback', callback=usage,
|
parser.add_option('--help', action='callback', callback=usage,
|
||||||
|
Loading…
Reference in New Issue
Block a user