fixed class_check behavior, added minimal.json

This commit is contained in:
Rafael.Timmerberg 2013-06-19 23:04:13 +02:00
commit 075c954434
9 changed files with 60 additions and 30 deletions

View file

@ -108,10 +108,9 @@ class ConfigParser:
if clazz in mods:
return mods["class"]
else:
mod = __import__(clazz)
#path = join(getcwd(), "lib", modPart, clazz + ".py")
#self.log.w(path)
#mod = imp.load_source(clazz, path)
#mod = __import__(clazz)
path = join("lib", modPart, clazz + ".py")
mod = imp.load_source(clazz, path)
mods[clazz] = mod
return mod
@ -123,6 +122,7 @@ class ConfigParser:
:param objList: the list of objects which is iterated on
: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
should return a list of
:param class_check: currently unsupported
"""
for obj in objList:
@ -130,25 +130,15 @@ class ConfigParser:
items = items_func(obj)
for clazzItem in items:
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"]
path = "lib/" + modPart
sys.path.append(path)
mod = self._load_module(clazz, modPart)
item = mod.create(clazzItem)
if class_check(item):
repl.append(item)
#TODO: activate the crappy classcheck if answer is provided
#http://stackoverflow.com/questions/17179440/
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!")
else:
self.log.w(" ignoring class " + clazzItem["class"] + "! It does not pass the class check!")
except ImportError, err:
self.log.w("could not import " + clazz + ": " + str(clazzItem) + "! reason")
self.log.w(str(err))
@ -156,9 +146,7 @@ class ConfigParser:
self.log.w("Key " + str(k) + " not in classItem " + str(clazzItem))
except Exception, 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[:]
items.extend(repl)

View file

@ -9,7 +9,7 @@ to just report this code and not use a parser.
"""
import urllib
from service import Service
from lib.services.service import Service
class HttpService(Service):

View file

@ -3,7 +3,7 @@ The ping service in pure Python.
"""
# 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):

View file

@ -2,7 +2,7 @@
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):

View file

@ -3,7 +3,7 @@ The snmpget service in pure Python.
"""
#from pysnmp.entity.rfc3413.oneliner import cmdgen
from service import Service
from lib.services.service import Service
class SnmpgetService(Service):

View file

@ -7,7 +7,7 @@ This service is using paramiko (http://www.lag.net/paramiko/).
import paramiko
import pprint
import os
from service import Service
from lib.services.service import Service
class SshService(Service):

View file

@ -6,7 +6,7 @@ not use a parser.
"""
import socket
from service import Service
from lib.services.service import Service
class TcpconnectService(Service):

View file

@ -1,7 +1,7 @@
#!/usr/bin/python2.7 -tt
__version__ = "0.4/TETRIS"
__default_config__ = "./linspector.json"
__default_config__ = "./minimal.json"
import argparse
import time

42
minimal.json Normal file
View 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}
}
}