many cleanups and new docs

This commit is contained in:
Johannes Findeisen 2013-05-27 03:54:04 +02:00
commit 88d023937f
10 changed files with 37 additions and 59 deletions

View file

@ -34,4 +34,4 @@ class Config:
self.services,
log)
#self.layouts = LayoutList(self.dict['layouts'], self.hostgroups)
#self.layouts = LayoutList(self.dict['layouts'], self.hostgroups)

View file

@ -14,4 +14,4 @@ class Filter:
def parseFilterList(filters):
return [Filter(name, **values) for name, values in filters.items()]
return [Filter(name, **values) for name, values in filters.items()]

View file

@ -10,9 +10,9 @@ class Host:
self.comment = comment
def __str__(self):
ret = "Host('Name: " + self.name + "', 'access: " + self.host + "', "
ret = "Host('Name: " + self.name + "', 'Access: " + self.host + "', "
if self.parent != "":
ret += "'parent: " + self.parent + "', "
ret += "'Parent: " + self.parent + "', "
ret += "'HostServices: {"
for s in self.services:
ret += str(s) + "\n"

View file

@ -18,8 +18,8 @@ class Member:
class MemberFilter:
def __init__(self, filt, Value):
self.filt = filt
def __init__(self, filter, Value):
self.filter = filter
self.value = Value
def __str__(self):

View file

@ -1,6 +1,3 @@
from apscheduler.scheduler import Scheduler
class Period(object):
def __init__(self, name):
self.name = name
@ -13,8 +10,7 @@ class Period(object):
class IntervalPeriod(Period):
def __init__(self, name="", weeks=0,days=0, hours=0, minutes=0, seconds=0, start_date=None,
comment=None):
def __init__(self, name="", weeks=0, days=0, hours=0, minutes=0, seconds=0, start_date=None, comment=None):
super(IntervalPeriod, self).__init__(name)
self.days = days # number of days to wait
@ -26,18 +22,17 @@ class IntervalPeriod(Period):
self.comment = comment # comment
def createJob(self, scheduler, jobInfo, func):
return scheduler.add_interval_job(func, weeks=self.weeks, hours=self.hours, minutes=self.minutes, seconds=self.seconds, start_date=self.start_date, args=[jobInfo])
return scheduler.add_interval_job(func, weeks=self.weeks, hours=self.hours, minutes=self.minutes,
seconds=self.seconds, start_date=self.start_date, args=[jobInfo])
def __str__(self):
ret = "IntervalPeriod(Name: " + self.name + ")"
return ret
class CronPeriod(Period):
def __init__(self, name="", year="*", month="*", day="*", week="*",
day_of_week="*", hour="*", minute="*", second="0", start_date=None,
comment=None):
def __init__(self, name="", year="*", month="*", day="*", week="*", day_of_week="*", hour="*", minute="*",
second="0", start_date=None, comment=None):
super(CronPeriod, self).__init__(name)
self.year = year # 4-digit year number
self.month = month # month number (1-12)
@ -50,13 +45,14 @@ class CronPeriod(Period):
self.start_date = start_date
self.comment = comment
def __str__(self):
ret = "CronPeriod(Name: " + self.name + ")"
return ret
def createJob(self, scheduler, jobInfo, func):
return scheduler.add_cron_job(func, year=self.year, month=self.month, day=self.day, week=self.week, day_of_week=self.day_of_week, hour=self.hour, minute=self.minute, second=self.second,start_date=self.start_date, args=[jobInfo])
return scheduler.add_cron_job(func, year=self.year, month=self.month, day=self.day, week=self.week,
day_of_week=self.day_of_week, hour=self.hour, minute=self.minute,
second=self.second, start_date=self.start_date, args=[jobInfo])
class DatePeriod(Period):
@ -66,25 +62,22 @@ class DatePeriod(Period):
self.comment = comment
def __str__(self):
ret = "DatePeriod(Name: " + self.name + ","+ str(self.date) + ")"
ret = "DatePeriod(Name: " + self.name + ", " + str(self.date) + ")"
return ret
def createJob(self, scheduler, jobInfo, func):
return scheduler.add_date_job(func, self.date, [jobInfo])
def parsePeriodList(periodlist,log):
periods=[]
def parsePeriodList(periodlist, log):
periods = []
log.i(periodlist)
for name, values in periodlist.items():
if "date" in values:
periods.append(DatePeriod(name, **values))
continue
for i in [ "weeks","days", "hours", "minutes", "seconds", "start_date"]:
for i in ["weeks", "days", "hours", "minutes", "seconds", "start_date"]:
if i in values:
periods.append(IntervalPeriod(name, **values))
break
@ -94,9 +87,7 @@ def parsePeriodList(periodlist,log):
periods.append(CronPeriod(name, **values))
break
log.w("ignoring Period: " +str(name))
log.w("ignoring Period: " + str(name))
log.w("reason: could not determine PeriodType: " + str(values))
return periods
return periods

View file

@ -8,7 +8,7 @@ class Command:
self.error = ""
def __str__(self):
return command
return self.command
def hasProcessed(self):
return self.output != "" and self.error != ""
@ -25,4 +25,4 @@ class Command:
def getError(self):
if not self.hasProcessed():
self.doProcess()
return self.error
return self.error

View file

@ -20,8 +20,4 @@ class JobInfo:
self.log = log
def handleCall(self):
pass
pass

View file

@ -56,6 +56,4 @@ class Logger():
self.log.critical(message)
def close(self):
logging.shutdown()
logging.shutdown()

View file

@ -1,11 +1,10 @@
#!/usr/bin/python2.7 -tt
VERSION = "0.1.1/TETRIS"
VERSION = "0.2/TETRIS"
import argparse
from lib.core.job import JobInfo
from lib.core.logger import Logger
from lib.config.config import Config
from lib.config.periods import Period
from apscheduler.scheduler import Scheduler
import time
import logging
@ -45,6 +44,7 @@ def handleJob(jobInfo):
jobInfo.handleCall()
print str(jobInfo)
def main():
args = parseArgs()
log = Logger(args.logfile, args.loglevel)
@ -75,17 +75,10 @@ def main():
try:
time.sleep(10)
for job in jobs:
log.d(str(job))
log.d(str(job))
except:
print "error"
elif args.action == "stop":
log.i("stopping linspector is currently unsupported")
elif args.action == "restart":
@ -99,4 +92,4 @@ def main():
if __name__ == "__main__":
main()
main()

View file

@ -148,19 +148,19 @@
"hour": "*",
"minute": "*/1",
"second": "0",
"comment": "Cron Job"
"comment": "Cron Job / Every minute"
},
"do_every_x_times" : {
"days": 0,
"weeks": 0,
"hours": 0,
"minutes": 5,
"seconds": 0,
"comment": "Interval Job"
"minutes": 0,
"seconds": 10,
"comment": "Interval Job / Every 10 seconds"
},
"next_christmas" : {
"date": "2013-12-24 20:00:00",
"comment": "Date Job"
"comment": "Date Job / Just one day"
}
},
"hosts":
@ -214,8 +214,8 @@
"services":
{
"load": ["twentyfourseven"],
"discusage":["do_every_x_times"],
"ping": ["twentyfourseven"]
"discusage":["twentyfourseven"],
"ping": ["do_every_x_times"]
}
}
},