# GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with Shinken. If not, see <http://www.gnu.org/licenses/>. """ Test Mongodb retention. """ from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modules import mongodb_retention from shinken.modules.mongodb_retention import get_instance modconf = Module() modconf.module_name = "MongodbRetention" modconf.uri = 'mongodb://127.0.0.1:27017' modconf.database = 'test' modconf.module_type = mongodb_retention.properties['type'] modconf.properties = mongodb_retention.properties.copy() class TestMongodbRetention(ShinkenTest): # setUp is inherited from ShinkenTest def test_mongodb_retention(self): # get our modules sl = mongodb_retention.Mongodb_retention_scheduler( modconf, 'localhost', 'test') # sl = get_instance(mod)
# import os, sys, string, time from multiprocessing import Queue from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modules.npcdmod import module as npcdmod_broker from shinken.modules.npcdmod.module import Npcd_broker sys.setcheckinterval(10000) modconf = Module() modconf.module_name = "ncpd" modconf.module_type = npcdmod_broker.properties['type'] modconf.modules = [] modconf.properties = npcdmod_broker.properties.copy() class TestNpcd(ShinkenTest): def add(self, b): self.broks[b.id] = b def fake_check(self, ref, exit_status, output="OK"): print "fake", ref now = time.time() ref.schedule() check = ref.actions.pop()
# Special Livestatus module opening since the module rename #from shinken.modules.livestatus import module as livestatus_broker livestatus_broker = modulesctx.get_module('livestatus') LiveStatus_broker = livestatus_broker.LiveStatus_broker LiveStatus = livestatus_broker.LiveStatus LiveStatusRegenerator = livestatus_broker.LiveStatusRegenerator LiveStatusQueryCache = livestatus_broker.LiveStatusQueryCache Logline = livestatus_broker.Logline LiveStatusLogStoreMongoDB = modulesctx.get_module('logstore-mongodb').LiveStatusLogStoreMongoDB LiveStatusLogStoreSqlite = modulesctx.get_module('logstore-sqlite').LiveStatusLogStoreSqlite livestatus_modconf = Module() livestatus_modconf.module_name = "livestatus" livestatus_modconf.module_type = livestatus_broker.properties['type'] livestatus_modconf.properties = livestatus_broker.properties.copy() class ShinkenModulesTest(ShinkenTest): def do_load_modules(self): self.modules_manager.load_and_init() self.log.log("I correctly loaded the modules: [%s]" % (','.join([inst.get_name() for inst in self.modules_manager.instances]))) def update_broker(self, dodeepcopy=False): # The brok should be manage in the good order
# # You should have received a copy of the GNU Affero General Public License # along with Shinken. If not, see <http://www.gnu.org/licenses/>. """ Test memcache retention. """ from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modulesctx import modulesctx memcache_retention_scheduler = modulesctx.get_module('retention_memcache') get_instance = memcache_retention_scheduler.get_instance modconf = Module() modconf.module_name = "MemcacheRetention" modconf.module_type = memcache_retention_scheduler.properties['type'] modconf.properties = memcache_retention_scheduler.properties.copy() try: import memcache except ImportError: memcache = None class TestMemcacheRetention(ShinkenTest): # setUp is inherited from ShinkenTest def test_memcache_retention(self): if not memcache: print "WARNING: cannot test the memcache module. Please install the python-memcache module first"
import os, sys, string, time from multiprocessing import Queue from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modulesctx import modulesctx npcdmod_broker = modulesctx.get_module('npcdmod') Npcd_broker = npcdmod_broker.Npcd_broker sys.setcheckinterval(10000) modconf = Module() modconf.module_name = "ncpd" modconf.module_type = npcdmod_broker.properties['type'] modconf.modules = [] modconf.properties = npcdmod_broker.properties.copy() class TestNpcd(ShinkenTest): def add(self, b): self.broks[b.id] = b def fake_check(self, ref, exit_status, output="OK"): print "fake", ref now = time.time() ref.schedule() check = ref.actions.pop()
if not sys.version_info > (2, 5): if SkipTest: raise SkipTest("bah, i am 2.4.x") else: raise SystemExit(0) from shinken.objects.module import Module from shinken.modules import passwd_ui from shinken.modules.passwd_ui import get_instance from shinken.log import logger if sys.version_info > (2, 5): modconf = Module() modconf.module_name = "PasswdUI" modconf.module_type = passwd_ui.properties['type'] modconf.properties = passwd_ui.properties.copy() class TestPasswdUI(ShinkenTest): # setUp is inherited from ShinkenTest def test_check_auth(self): # get our modules modconf.passwd = 'libexec/htpasswd.users' mod = passwd_ui.get_instance(modconf) sl = get_instance(mod) # Hack here :( sl.properties = {}
""" Test Nagios retention """ from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modulesctx import modulesctx nagios_retention_file_scheduler = modulesctx.get_module('retention_nagios') get_instance = nagios_retention_file_scheduler.get_instance modconf = Module() modconf.module_name = "NagiosRetention" modconf.module_type = nagios_retention_file_scheduler.properties['type'] modconf.properties = nagios_retention_file_scheduler.properties.copy() class TestNagiosRetention(ShinkenTest): # setUp is inherited from ShinkenTest def test_pickle_retention(self): # get our modules mod = nagios_retention_file_scheduler.Nagios_retention_scheduler( modconf, 'etc/module_nagios_retention/retention.dat') sl = get_instance(mod) # Hack here :( sl.properties = {}
from shinken.brok import Brok from shinken.daemons.schedulerdaemon import Shinken from shinken.daemons.brokerdaemon import Broker from shinken.daemons.arbiterdaemon import Arbiter # Special Livestatus module opening since the module rename from shinken.modules.livestatus import module as livestatus_broker from shinken.modules.livestatus.module import LiveStatus_broker from shinken.modules.livestatus.livestatus import LiveStatus from shinken.modules.livestatus.livestatus_regenerator import LiveStatusRegenerator from shinken.modules.livestatus.livestatus_query_cache import LiveStatusQueryCache from shinken.misc.datamanager import datamgr livestatus_modconf = Module() livestatus_modconf.module_name = "livestatus" livestatus_modconf.module_type = livestatus_broker.properties['type'] livestatus_modconf.properties = livestatus_broker.properties.copy() # We overwrite the functions time() and sleep() # This way we can modify sleep() so that it immediately returns although # for a following time() it looks like thee was actually a delay. # This massively speeds up the tests. time.my_offset = 0 time.my_starttime = time.time() time.my_oldtime = time.time def my_time_time(): now = time.my_oldtime() + time.my_offset
# # This file is used to test reading and processing of config files # import os from shinken_test import unittest, ShinkenTest from shinken.log import logger from shinken.objects.module import Module from shinken.modules import redis_retention_scheduler from shinken.modules.redis_retention_scheduler import get_instance modconf = Module() modconf.module_name = "RedisRetention" modconf.module_type = redis_retention_scheduler.properties['type'] modconf.properties = redis_retention_scheduler.properties.copy() class TestConfig(ShinkenTest): #setUp is in shinken_test #Change ME :) def test_redis_retention(self): print self.conf.modules #get our modules mod = redis_retention_scheduler.Redis_retention_scheduler(modconf, 'localhost') sl = get_instance(mod) print "Instance", sl
import os, time from shinken_test import unittest, ShinkenTest, original_time_time, original_time_sleep # Need to use the real time-functions as we are reading timestamps # from the filesystem. time.time = original_time_time time.sleep = original_time_sleep from shinken.objects.module import Module from shinken.modules.hot_dependencies import module as hot_dependencies_arbiter from shinken.modules.hot_dependencies.module import Hot_dependencies_arbiter, get_instance modconf = Module() modconf.module_name = "PickleRetention" modconf.module_type = hot_dependencies_arbiter.properties['type'] modconf.modules = [] modconf.properties = hot_dependencies_arbiter.properties.copy() try: import json except ImportError: # For old Python version, load # simple json (it can be hard json?! It's 2 functions guy!) try: import simplejson as json except ImportError: print "Error: you need the json or simplejson module for this script" raise SystemExit(0)
# along with Shinken. If not, see <http://www.gnu.org/licenses/>. """ Test Mongodb retention. """ from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modulesctx import modulesctx mongodb_retention = modulesctx.get_module('retention_mongodb') get_instance = mongodb_retention.get_instance modconf = Module() modconf.module_name = "MongodbRetention" modconf.uri = 'mongodb://127.0.0.1:27017' modconf.database = 'test' modconf.module_type = mongodb_retention.properties['type'] modconf.properties = mongodb_retention.properties.copy() class TestMongodbRetention(ShinkenTest): # setUp is inherited from ShinkenTest def test_mongodb_retention(self): # get our modules sl = mongodb_retention.Mongodb_retention_scheduler(modconf, 'localhost', 'test', '') # sl = get_instance(mod) # Hack here :(
# You should have received a copy of the GNU Affero General Public License # along with Shinken. If not, see <http://www.gnu.org/licenses/>. """ Test Nagios retention """ from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modulesctx import modulesctx nagios_retention_file_scheduler = modulesctx.get_module('retention_nagios') get_instance = nagios_retention_file_scheduler.get_instance modconf = Module() modconf.module_name = "NagiosRetention" modconf.module_type = nagios_retention_file_scheduler.properties['type'] modconf.properties = nagios_retention_file_scheduler.properties.copy() class TestNagiosRetention(ShinkenTest): # setUp is inherited from ShinkenTest def test_pickle_retention(self): # get our modules mod = nagios_retention_file_scheduler.Nagios_retention_scheduler( modconf, 'etc/module_nagios_retention/retention.dat') sl = get_instance(mod) # Hack here :( sl.properties = {}
if SkipTest: raise SkipTest("bah, i am 2.4.x") else: raise SystemExit(0) from shinken.objects.module import Module from shinken.modulesctx import modulesctx passwd_ui = modulesctx.get_module('auth_htpasswd') get_instance = passwd_ui.get_instance from shinken.log import logger if sys.version_info > (2, 5): modconf = Module() modconf.module_name = "PasswdUI" modconf.module_type = passwd_ui.properties['type'] modconf.properties = passwd_ui.properties.copy() class TestPasswdUI(ShinkenTest): # setUp is inherited from ShinkenTest def test_check_auth(self): # get our modules modconf.passwd = 'libexec/htpasswd.users' mod = passwd_ui.get_instance(modconf) sl = get_instance(mod) # Hack here :( sl.properties = {}
# This file is used to test reading and processing of config files # import os, sys, time from shinken_test import unittest, ShinkenTest from shinken.log import logger from shinken.objects.module import Module from shinken.modules import named_pipe from shinken.modules.named_pipe import Named_Pipe_arbiter, get_instance modconf = Module() modconf.module_name = "NamedPipe" modconf.module_type = named_pipe.properties['type'] modconf.properties = named_pipe.properties.copy() class TestModuleNamedPipe(ShinkenTest): #setUp is in shinken_test #def setUp(self): # self.setup_with_file('etc/nagios_module_hot_dependencies_arbiter.cfg') # Change ME :) def test_read_named_pipe(self): # Ok, windows do not have named pipe, we know... if os.name == 'nt': return
# This file is used to test reading and processing of config files # import os from Queue import Empty from multiprocessing import Queue, Manager, active_children from shinken_test import * from shinken.log import logger from shinken.objects.module import Module from shinken.modules.booster_nrpe import module as nrpe_poller from shinken.modules.booster_nrpe.module import get_instance from shinken.message import Message modconf = Module() modconf.module_name = "NrpePoller" modconf.module_type = nrpe_poller.properties['type'] modconf.properties = nrpe_poller.properties.copy() class TestNrpePoller(ShinkenTest): # Uncomment this is you want to use a specific configuration # for your test #def setUp(self): # self.setup_with_file('etc/nagios_module_hack_cmd_poller_tag.cfg') def test_nrpe_poller(self): if os.name == 'nt': return
# This file is used to test reading and processing of config files # import os import time from shinken_test import unittest, ShinkenTest from shinken.log import logger from shinken.objects.module import Module from shinken.modules import pickle_retention_file_scheduler from shinken.modules.pickle_retention_file_scheduler import get_instance modconf = Module() modconf.module_name = "PickleRetention" modconf.module_type = pickle_retention_file_scheduler.properties['type'] modconf.modules = [] modconf.properties = pickle_retention_file_scheduler.properties.copy() class TestConfig(ShinkenTest): #setUp is in shinken_test #Change ME :) def test_pickle_retention(self): print self.conf.modules now = time.time() #get our modules mod = pickle_retention_file_scheduler.Pickle_retention_scheduler(modconf, 'tmp/retention-test.dat') try :
""" import os, time, platform from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modulesctx import modulesctx named_pipe = modulesctx.get_module('named_pipe') Named_Pipe_arbiter = named_pipe.Named_Pipe_arbiter get_instance = named_pipe.get_instance modconf = Module() modconf.module_name = "NamedPipe" modconf.module_type = named_pipe.properties['type'] modconf.properties = named_pipe.properties.copy() class TestModuleNamedPipe(ShinkenTest): # setUp is inherited from ShinkenTest def test_read_named_pipe(self): # Ok, windows do not have named pipe, we know... # cygwin cannot write from two sides at the same time if os.name == 'nt' or platform.system().startswith('CYGWIN'): return now = int(time.time())
# # This file is used to test reading and processing of config files # import os from shinken_test import unittest, ShinkenTest from shinken.log import logger from shinken.objects.module import Module from shinken.modules import memcache_retention_scheduler from shinken.modules.memcache_retention_scheduler import get_instance modconf = Module() modconf.module_name = "MemcacheRetention" modconf.module_type = memcache_retention_scheduler.properties['type'] modconf.properties = memcache_retention_scheduler.properties.copy() class TestConfig(ShinkenTest): # setUp is inherited from ShinkenTest def test_memcache_retention(self): print self.conf.modules # get our modules modconf.server = 'localhost' modconf.port = '11211' mod = memcache_retention_scheduler.Memcache_retention_scheduler(modconf) sl = get_instance(mod)
""" import os import copy from shinken_test import unittest, ShinkenTest from shinken.daemons.arbiterdaemon import Arbiter from shinken.objects.module import Module from shinken.modulesctx import modulesctx pickle_retention_file_generic = modulesctx.get_module('pickle_retention_file_generic') get_instance = pickle_retention_file_generic.get_instance modconf = Module() modconf.module_name = "PickleRetentionGeneric" modconf.module_type = pickle_retention_file_generic.properties['type'] modconf.properties = pickle_retention_file_generic.properties.copy() class TestPickleRetentionArbiter(ShinkenTest): # setUp is inherited from ShinkenTest def test_pickle_retention(self): # get our modules mod = pickle_retention_file_generic.Pickle_retention_generic( modconf, 'tmp/retention-test.dat') try: os.unlink(mod.path) except: pass
""" Test pickle retention broker. """ import os import copy from shinken_test import unittest, ShinkenTest from shinken.daemons.brokerdaemon import Broker from shinken.objects.module import Module from shinken.modules import pickle_retention_file_generic from shinken.modules.pickle_retention_file_generic import get_instance modconf = Module() modconf.module_name = "PickleRetentionGeneric" modconf.module_type = pickle_retention_file_generic.properties['type'] modconf.properties = pickle_retention_file_generic.properties.copy() class TestPickleRetentionBroker(ShinkenTest): # setUp is inherited from ShinkenTest def test_pickle_retention(self): # get our modules mod = pickle_retention_file_generic.Pickle_retention_generic( modconf, 'tmp/retention-test.dat') try: os.unlink(mod.path) except: pass
# # You should have received a copy of the GNU Affero General Public License # along with Shinken. If not, see <http://www.gnu.org/licenses/>. """ Test Redis retention. """ from shinken_test import unittest, ShinkenTest from shinken.objects.module import Module from shinken.modules import redis_retention_scheduler from shinken.modules.redis_retention_scheduler import get_instance modconf = Module() modconf.module_name = "RedisRetention" modconf.module_type = redis_retention_scheduler.properties['type'] modconf.properties = redis_retention_scheduler.properties.copy() class TestRedis(ShinkenTest): # setUp is inherited from ShinkenTest def test_redis_retention(self): # get our modules mod = redis_retention_scheduler.Redis_retention_scheduler( modconf, 'localhost') sl = get_instance(mod) # Hack here :( sl.properties = {}