fixed class_check behavior, added minimal.json
This commit is contained in:
parent
8e53382e70
commit
fca615e8d9
9 changed files with 60 additions and 30 deletions
|
|
@ -108,10 +108,9 @@ class ConfigParser:
|
||||||
if clazz in mods:
|
if clazz in mods:
|
||||||
return mods["class"]
|
return mods["class"]
|
||||||
else:
|
else:
|
||||||
mod = __import__(clazz)
|
#mod = __import__(clazz)
|
||||||
#path = join(getcwd(), "lib", modPart, clazz + ".py")
|
path = join("lib", modPart, clazz + ".py")
|
||||||
#self.log.w(path)
|
mod = imp.load_source(clazz, path)
|
||||||
#mod = imp.load_source(clazz, path)
|
|
||||||
mods[clazz] = mod
|
mods[clazz] = mod
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
@ -123,6 +122,7 @@ class ConfigParser:
|
||||||
:param objList: the list of objects which is iterated on
|
:param objList: the list of objects which is iterated on
|
||||||
:param modPart: the folder from the module (i.e tasks, parsers)
|
:param modPart: the folder from the module (i.e tasks, parsers)
|
||||||
:param items_func: function to get a pointer on the list of json-config-objects to replace. Takes one argument and
|
:param items_func: function to get a pointer on the list of json-config-objects to replace. Takes one argument and
|
||||||
|
should return a list of
|
||||||
:param class_check: currently unsupported
|
:param class_check: currently unsupported
|
||||||
"""
|
"""
|
||||||
for obj in objList:
|
for obj in objList:
|
||||||
|
|
@ -130,25 +130,15 @@ class ConfigParser:
|
||||||
items = items_func(obj)
|
items = items_func(obj)
|
||||||
for clazzItem in items:
|
for clazzItem in items:
|
||||||
try:
|
try:
|
||||||
if "class" not in clazzItem:
|
|
||||||
self.log.w("python says class is not in class item!")
|
|
||||||
self.log.w(modPart)
|
|
||||||
self.log.w(clazzItem)
|
|
||||||
self.log.w(clazzItem["class"])
|
|
||||||
|
|
||||||
clazz = clazzItem["class"]
|
clazz = clazzItem["class"]
|
||||||
path = "lib/" + modPart
|
|
||||||
sys.path.append(path)
|
|
||||||
mod = self._load_module(clazz, modPart)
|
mod = self._load_module(clazz, modPart)
|
||||||
item = mod.create(clazzItem)
|
item = mod.create(clazzItem)
|
||||||
|
if class_check(item):
|
||||||
repl.append(item)
|
repl.append(item)
|
||||||
#TODO: activate the crappy classcheck if answer is provided
|
else:
|
||||||
#http://stackoverflow.com/questions/17179440/
|
self.log.w(" ignoring class " + clazzItem["class"] + "! It does not pass the class check!")
|
||||||
self.log.d("warning: instance_check isn't working yet! TRUST_ALL = TRUE")
|
|
||||||
#if class_check(item):
|
|
||||||
# repl.append(item)
|
|
||||||
#else:
|
|
||||||
# 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))
|
||||||
|
|
@ -156,9 +146,7 @@ class ConfigParser:
|
||||||
self.log.w("Key " + str(k) + " not in classItem " + str(clazzItem))
|
self.log.w("Key " + str(k) + " not in classItem " + str(clazzItem))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log.w("Error while replacing class ( " + clazz + " ):" + str(e))
|
self.log.w("Error while replacing class ( " + clazz + " ):" + str(e))
|
||||||
finally:
|
|
||||||
if path in sys.path:
|
|
||||||
del sys.path[sys.path.index(path)]
|
|
||||||
del items[:]
|
del items[:]
|
||||||
items.extend(repl)
|
items.extend(repl)
|
||||||
|
|
||||||
|
|
@ -191,7 +179,7 @@ def parsePeriodList(name, values):
|
||||||
return DatePeriod(name, **values)
|
return DatePeriod(name, **values)
|
||||||
|
|
||||||
comp = ["weeks", "days", "hours", "minutes", "seconds", "start_date"]
|
comp = ["weeks", "days", "hours", "minutes", "seconds", "start_date"]
|
||||||
if len([i for i in comp if i in values]) > 0 :
|
if len([i for i in comp if i in values]) > 0:
|
||||||
return IntervalPeriod(name, **values)
|
return IntervalPeriod(name, **values)
|
||||||
|
|
||||||
comp = ["year", "month", "day", "week", "day_of_week", "hour", "minute", "second"]
|
comp = ["year", "month", "day", "week", "day_of_week", "hour", "minute", "second"]
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ to just report this code and not use a parser.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
from service import Service
|
from lib.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
class HttpService(Service):
|
class HttpService(Service):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ The ping service in pure Python.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# http://code.activestate.com/recipes/409689-icmplib-library-for-creating-and-reading-icmp-pack/
|
# http://code.activestate.com/recipes/409689-icmplib-library-for-creating-and-reading-icmp-pack/
|
||||||
from service import Service
|
from lib.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
class PingService(Service):
|
class PingService(Service):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
The shell service. This is for executing local shell commands and retrieve the output.
|
The shell service. This is for executing local shell commands and retrieve the output.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from service import Service
|
from lib.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
class ShellService(Service):
|
class ShellService(Service):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ The snmpget service in pure Python.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#from pysnmp.entity.rfc3413.oneliner import cmdgen
|
#from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||||
from service import Service
|
from lib.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
class SnmpgetService(Service):
|
class SnmpgetService(Service):
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ This service is using paramiko (http://www.lag.net/paramiko/).
|
||||||
import paramiko
|
import paramiko
|
||||||
import pprint
|
import pprint
|
||||||
import os
|
import os
|
||||||
from service import Service
|
from lib.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
class SshService(Service):
|
class SshService(Service):
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ not use a parser.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
from service import Service
|
from lib.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
class TcpconnectService(Service):
|
class TcpconnectService(Service):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python2.7 -tt
|
#!/usr/bin/python2.7 -tt
|
||||||
|
|
||||||
__version__ = "0.4/TETRIS"
|
__version__ = "0.4/TETRIS"
|
||||||
__default_config__ = "./linspector.json"
|
__default_config__ = "./minimal.json"
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
|
|
|
||||||
42
minimal.json
Normal file
42
minimal.json
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
"members":{
|
||||||
|
"homer":{
|
||||||
|
"name": "Homer Simpson",
|
||||||
|
"comment": "Security Inspector",
|
||||||
|
"tasks": [{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"periods": {
|
||||||
|
"doh": {"seconds": 10, "comment": "OMG, this means work"},
|
||||||
|
"moes_time": {"minute":"0", "hour": "12", "day_of_week": "4", "comment": "much better"},
|
||||||
|
"marges_birthday": { "date": "1965-2-24 04:00:00"}
|
||||||
|
},
|
||||||
|
"hostgroups":{
|
||||||
|
"power_plant":{
|
||||||
|
"members": ["homer"],
|
||||||
|
"hosts": ["powerplant.springfield.com"],
|
||||||
|
"processors":[
|
||||||
|
{"class": "mongodb", "args":{ "host": "mongodb.burnscorp.org", "user": "homer", "password": "useless", "database": "default" }}
|
||||||
|
],
|
||||||
|
"services":[
|
||||||
|
{
|
||||||
|
"class": "ping",
|
||||||
|
"fails": {"donut": 2000},
|
||||||
|
"periods":["doh"],
|
||||||
|
"threshold": 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"class": "tcpconnect",
|
||||||
|
"args": {"port": 23232},
|
||||||
|
"periods": ["moes_time", "marges_birthday"],
|
||||||
|
"threshold": 0,
|
||||||
|
"comment": "my personal reminder, hehe"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"layouts":{
|
||||||
|
"main":{"hostgroups": ["power_plant"], "enabled": true}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue