just some housekeeping... :) i like!

This commit is contained in:
Johannes Findeisen 2013-09-21 04:44:01 +02:00
commit 4b2513bfca
4 changed files with 45 additions and 64 deletions

View file

@ -13,16 +13,16 @@ from lib.processors.processor import Processor
from lib.parsers.parser import Parser from lib.parsers.parser import Parser
from lib.tasks.task import Task from lib.tasks.task import Task
MOD_SERVICES = "services" MOD_SERVICES = "services"
MOD_PROCESSORS = "processors" MOD_PROCESSORS = "processors"
MOD_PARSERS = "parsers" MOD_PARSERS = "parsers"
MOD_TASKS = "tasks" MOD_TASKS = "tasks"
KEY_LAYOUTS = "layouts" KEY_LAYOUTS = "layouts"
KEY_HOSTGROUPS = "hostgroups" KEY_HOSTGROUPS = "hostgroups"
KEY_MEMBERS = "members" KEY_MEMBERS = "members"
KEY_PERIODS = "periods" KEY_PERIODS = "periods"
KEY_CORE = "core" KEY_CORE = "core"
class ConfigurationException(Exception): class ConfigurationException(Exception):
@ -135,10 +135,10 @@ class ConfigParser:
if class_check(item): if class_check(item):
repl.append(item) repl.append(item)
else: else:
self.log.w(" ignoring class " + clazzItem["class"] + "! It does not pass the class check!") self.log.w("Ignoring class " + clazzItem["class"] + "! It does not pass the class check!")
except ImportError, err: except ImportError, err:
self.log.w("could not import " + clazz + ": " + str(clazzItem) + "! reason") self.log.w("Could not import " + clazz + ": " + str(clazzItem) + "! reason")
self.log.w(str(err)) self.log.w(str(err))
except KeyError, k: except KeyError, k:
self.log.w("Key " + str(k) + " not in classItem " + str(clazzItem)) self.log.w("Key " + str(k) + " not in classItem " + str(clazzItem))
@ -202,8 +202,6 @@ class FullConfigParser(ConfigParser):
""" """
self.jsonDict = self._read_json_config(configFilename) self.jsonDict = self._read_json_config(configFilename)
# first step # first step
creator = lambda name, values: Layout(name,**values) creator = lambda name, values: Layout(name,**values)
layouts = self._create_raw_Object(self.jsonDict[KEY_LAYOUTS], "Layout", creator) layouts = self._create_raw_Object(self.jsonDict[KEY_LAYOUTS], "Layout", creator)

View file

@ -10,7 +10,7 @@ import os
from shlex import split as shsplit from shlex import split as shsplit
from cmd import Cmd from cmd import Cmd
VERSION = "0.1" __version__ = "0.1"
class LishFrontend(Frontend): class LishFrontend(Frontend):
@ -23,7 +23,7 @@ class LishFrontend(Frontend):
run = True run = True
while run: while run:
try: try:
commander.cmdloop("LISH - Linspector interactive shell") commander.cmdloop("Lish - Linspector interactive shell (" + __version__ + ")")
except KeyboardInterrupt, ki: except KeyboardInterrupt, ki:
run = False run = False
except Exception, err: except Exception, err:
@ -80,7 +80,7 @@ class ShellCommander(CommandBase, object):
os.system(text) os.system(text)
def help_shell(self): def help_shell(self):
print("execute any shell command. Can also be achieved by a '!' postfix") print("execute any shell command. Can also be achieved by a '!' prefix")
def complete_shell(self, text, line, begidx, endidx): def complete_shell(self, text, line, begidx, endidx):
try: try:
@ -158,9 +158,6 @@ class LishCommander(Exit, ShellCommander, LogCommander):
executes python using 'exec'. executes python using 'exec'.
''' '''
def help_hostgroup(self): def help_hostgroup(self):
print ''' print '''
usage: usage:
@ -172,4 +169,4 @@ class LishCommander(Exit, ShellCommander, LogCommander):
def complete_hostgroup(self, text, line, begidx, endidx): def complete_hostgroup(self, text, line, begidx, endidx):
if begidx == 10: if begidx == 10:
return [x for x in self._hostgroupArgs if x.startswith(text)] if len(text) > 0 else self._hostgroupArgs return [x for x in self._hostgroupArgs if x.startswith(text)] if len(text) > 0 else self._hostgroupArgs

View file

@ -24,6 +24,7 @@ class MailTask(Task):
message['Subject'] = msg message['Subject'] = msg
now = datetime.datetime.now() now = datetime.datetime.now()
message['Date'] = now.strftime("%a, %d %b %Y %H:%M:%S") message['Date'] = now.strftime("%a, %d %b %Y %H:%M:%S")
#TODO: totally unstable just to use values from core. make checks before...!
message['From'] = core["tasks"]["mail"]["from"] message['From'] = core["tasks"]["mail"]["from"]
message['To'] = self.recipient message['To'] = self.recipient
s = smtplib.SMTP(core["tasks"]["mail"]["host"], core["tasks"]["mail"]["port"]) s = smtplib.SMTP(core["tasks"]["mail"]["host"], core["tasks"]["mail"]["port"])

View file

@ -1,12 +1,10 @@
#!/usr/bin/python2.7 -tt #!/usr/bin/python2.7 -tt
__version__ = "0.5/TEKKEN" __version__ = "0.6/TCPCONNECT"
__default_config__ = "./examples/minimal.json" __default_config__ = "./examples/minimal.json"
import argparse import argparse
import time
import logging import logging
import subprocess as sp
from lib.core.logger import Logger from lib.core.logger import Logger
from lib.frontends.lish import LishFrontend from lib.frontends.lish import LishFrontend
from lib.config.parser import FullConfigParser from lib.config.parser import FullConfigParser
@ -17,18 +15,15 @@ from lib.core.job import Job
def parseArgs(): def parseArgs():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Linspector is for monitoring the vital information of hosts, services and devices in a network.", description="Linspector is for monitoring the vital information of hosts, services and devices in a network.",
epilog="linspector is not some program expecting computers to run!", epilog="linspector is not some program expecting computers to run! Visit http://linspector.org for more "
"information.",
prog="linspector") prog="linspector")
parser.add_argument("action", choices=["start", "stop", "restart", "attach"],
help="defines if linspector should beeing attached, started, stopped or restarted.")
parser.add_argument("--version", action="version", version="%(prog)s " + str(__version__)) parser.add_argument("--version", action="version", version="%(prog)s " + str(__version__))
parser.add_argument("-c", "--config", default=__default_config__, parser.add_argument("-c", "--config", default=__default_config__,
help="select configfile to use") help="select configfile to use")
parser.add_argument("-l", "--logfile", default="./log/linspector.log", metavar="FILE", parser.add_argument("-l", "--logfile", default="./log/linspector.log", metavar="FILE",
help="set logfile to use") help="set logfile to use")
parser.add_argument("-p", "--pidfile", default="./tmp/linspector.pid", metavar="FILE",
help="set the pidfile to use (default: /tmp/linspector.pid)")
output = parser.add_mutually_exclusive_group() output = parser.add_mutually_exclusive_group()
output.add_argument("-q", "--quiet", action="store_const", dest="loglevel", const=logging.ERROR, output.add_argument("-q", "--quiet", action="store_const", dest="loglevel", const=logging.ERROR,
@ -36,9 +31,9 @@ def parseArgs():
output.add_argument("-w", "--warning", action="store_const", dest="loglevel", const=logging.WARNING, output.add_argument("-w", "--warning", action="store_const", dest="loglevel", const=logging.WARNING,
help="output warnings") help="output warnings")
output.add_argument("-v", "--verbose", action="store_const", dest="loglevel", const=logging.INFO, output.add_argument("-v", "--verbose", action="store_const", dest="loglevel", const=logging.INFO,
help="output infos") help="output info messages")
output.add_argument("-d", "--debug", action="store_const", dest="loglevel", const=logging.DEBUG, output.add_argument("-d", "--debug", action="store_const", dest="loglevel", const=logging.DEBUG,
help="output debug infos") help="output debug messages")
output.set_defaults(loglevel=logging.INFO) output.set_defaults(loglevel=logging.INFO)
return parser.parse_args() return parser.parse_args()
@ -53,40 +48,30 @@ def main():
log.i("parsed arguments") log.i("parsed arguments")
if args.action == "start": configParser = FullConfigParser(log)
configParser = FullConfigParser(log) linConf, core = configParser.parse_config(args.config)
linConf, core = configParser.parse_config(args.config)
scheduler = Scheduler() scheduler = Scheduler()
scheduler.start() scheduler.start()
jobs = [] jobs = []
for layout in linConf.get_enabled_layouts(): for layout in linConf.get_enabled_layouts():
for hostgroup in layout.get_hostgroups(): for hostgroup in layout.get_hostgroups():
for service in hostgroup.get_services(): for service in hostgroup.get_services():
for host in hostgroup.get_hosts(): for host in hostgroup.get_hosts():
for period in service.get_periods(): for period in service.get_periods():
job = Job(service, host, hostgroup.get_members(), hostgroup.get_processors(), core) job = Job(service, host, hostgroup.get_members(), hostgroup.get_processors(), core)
schedulerJob = period.createJob(scheduler, job, handleJob) schedulerJob = period.createJob(scheduler, job, handleJob)
if schedulerJob is not None: if schedulerJob is not None:
job.set_job(schedulerJob) job.set_job(schedulerJob)
job.set_logger(log) job.set_logger(log)
jobs.append(job) jobs.append(job)
frontend = LishFrontend(jobs=jobs, scheduler=scheduler, linspectorConfig=linConf) frontend = LishFrontend(jobs=jobs, scheduler=scheduler, linspectorConfig=linConf)
log.d("shutting down scheduler") log.d("shutting down scheduler")
scheduler.shutdown(wait=False) scheduler.shutdown(wait=False)
elif args.action == "stop":
log.i("stopping linspector is currently unsupported")
elif args.action == "restart":
sp.call("./linspector stop")
sp.call(
"./linspector start --config " + args.config + " --logfile " + args.logfile + " --pidfile " + args.pidfile)
elif args.action == "attach":
log.i("attaching linspector is currently unsupported")
log.close() log.close()