fixed key-lookup in periods, slightly changed minimal.json
This commit is contained in:
parent
6908704587
commit
e052708205
2 changed files with 34 additions and 8 deletions
|
|
@ -2,26 +2,44 @@
|
||||||
"members":{
|
"members":{
|
||||||
"root":{
|
"root":{
|
||||||
"_name": "root",
|
"_name": "root",
|
||||||
|
"parent": "admin",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"class": "storage/logger",
|
"class": "storage/logger",
|
||||||
"type": [ "ok", "warning", "error" ],
|
"type": [ "ok" ],
|
||||||
"args": { "directory": "/tmp/", "file": "data.log" }
|
"args": { "directory": "/tmp/", "file": "data.log" }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"admin":{
|
||||||
|
"_name": "admin",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"class": "alert/mail",
|
||||||
|
"type": [ "ok", "warning", "error" ],
|
||||||
|
"args": { "host": "localhost",
|
||||||
|
"port": 25,
|
||||||
|
"sender": "linspector@linspector.org",
|
||||||
|
"username": "",
|
||||||
|
"password": "",
|
||||||
|
"rcpt": "hanez@linspector.org"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"periods": {
|
"periods": {
|
||||||
"fast": { "seconds": 15 },
|
"fast": { "seconds": 15 },
|
||||||
"medium": { "seconds": 120 },
|
"medium": { "seconds": 60 },
|
||||||
"slow": { "seconds": 480 }
|
"slow": { "seconds": 480 },
|
||||||
|
"now": {"date": "2013-12-29 00:09:00"}
|
||||||
},
|
},
|
||||||
"hostgroups":{
|
"hostgroups":{
|
||||||
"a":{
|
"a":{
|
||||||
"members": ["root"],
|
"members": ["root"],
|
||||||
"hosts": [ "a"],
|
"hosts": [ "151.217.0.0/16"],
|
||||||
"services":[
|
"services":[
|
||||||
{ "class": "etc/dummy", "args": { "sleep": 1, "fail": true }, "periods": ["fast"], "threshold": 1 }
|
{ "class": "net/tcpconnect", "args":{ "port": 80 }, "periods": ["now"], "threshold": 1 }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
from apscheduler.util import convert_to_datetime
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -48,7 +49,7 @@ class IntervalPeriod(Period):
|
||||||
|
|
||||||
def createJob(self, scheduler, jobInfo, func, **kwargs):
|
def createJob(self, scheduler, jobInfo, func, **kwargs):
|
||||||
start_date = self.start_date
|
start_date = self.start_date
|
||||||
if kwargs["start_date"]:
|
if "start_date" in kwargs:
|
||||||
start_date = kwargs["start_date"]
|
start_date = kwargs["start_date"]
|
||||||
|
|
||||||
return scheduler.add_interval_job(func, weeks=self.weeks, hours=self.hours, minutes=self.minutes,
|
return scheduler.add_interval_job(func, weeks=self.weeks, hours=self.hours, minutes=self.minutes,
|
||||||
|
|
@ -80,7 +81,8 @@ class CronPeriod(Period):
|
||||||
|
|
||||||
def createJob(self, scheduler, jobInfo, func, **kwargs):
|
def createJob(self, scheduler, jobInfo, func, **kwargs):
|
||||||
start_date = self.start_date
|
start_date = self.start_date
|
||||||
if kwargs["start_date"]:
|
|
||||||
|
if "start_date" in kwargs:
|
||||||
start_date = kwargs["start_date"]
|
start_date = kwargs["start_date"]
|
||||||
|
|
||||||
return scheduler.add_cron_job(func, year=self.year, month=self.month, day=self.day, week=self.week,
|
return scheduler.add_cron_job(func, year=self.year, month=self.month, day=self.day, week=self.week,
|
||||||
|
|
@ -100,6 +102,12 @@ class DatePeriod(Period):
|
||||||
|
|
||||||
def createJob(self, scheduler, jobInfo, func, **kwargs):
|
def createJob(self, scheduler, jobInfo, func, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
if "start_date" in kwargs:
|
||||||
|
earliest = kwargs["start_date"]
|
||||||
|
date = convert_to_datetime(self.date)
|
||||||
|
if date < earliest:
|
||||||
|
self.date = earliest
|
||||||
|
|
||||||
return scheduler.add_date_job(func=func, date=self.date, args=[jobInfo])
|
return scheduler.add_date_job(func=func, date=self.date, args=[jobInfo])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
return None
|
logger.error("exception while creating job out of DatePeriod!\n%s" % e)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue