def setUp(self): self.generator = Generator() setup_logging() self.hosts = {} self.applications = {} coshsh.application.Application.init_classes([ os.path.join(os.path.dirname(__file__), '../recipes/default/classes'), os.path.join(os.path.dirname(__file__), 'recipes/test10/classes')]) MonitoringDetail.init_classes([ os.path.join(os.path.dirname(__file__), '../recipes/default/classes'), os.path.join(os.path.dirname(__file__), 'recipes/test10/classes')]) pass row = ['drivelsrv', '11.120.9.10', 'Server', 'Red Hat 6.0', '', 'vs', '7x24', '2nd floor', 'ps'] final_row = { } for (index, value) in enumerate(['host_name', 'address', 'type', 'os', 'hardware', 'virtual', 'notification_period', 'location', 'department']): final_row[value] = [None if row[index] == "" else row[index]][0] h = coshsh.host.Host(final_row) self.hosts[h.host_name] = h row = ['drivel', 'mysql', '', '', '', 'drivelsrv', '7x24'] final_row = { } for (index, value) in enumerate(['name', 'type', 'component', 'version', 'patchlevel', 'host_name', 'check_period']): final_row[value] = [None if row[index] == "" else row[index]][0] a = coshsh.application.Application(final_row) #a.__init__(final_row) self.applications[a.fingerprint()] = a setattr(a, "host", self.hosts[a.host_name])
def setUp(self): shutil.rmtree("./var/objects/test9", True) os.makedirs("./var/objects/test9") self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh.cfg') self.generator = coshsh.generator.Generator() setup_logging()
def setUp(self): shutil.rmtree("./var/objects/test13", True) os.makedirs("./var/objects/test13") self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh.cfg') self.generator = coshsh.generator.Generator() setup_logging(scrnloglevel=logging.DEBUG)
def setUp(self): shutil.rmtree("./var/objects/test33", True) os.makedirs("./var/objects/test33") print "neziuiu" self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh5.cfg') self.generator = coshsh.generator.Generator() setup_logging(scrnloglevel=logging.DEBUG)
def setUp(self): shutil.rmtree("./var/objects/test6", True) os.makedirs("./var/objects/test6") self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh.cfg') self.generator = coshsh.generator.Generator() setup_logging(scrnloglevel=DEBUG) self.generator.add_recipe(name='test6', **dict(self.config.items('recipe_TEST6'))) self.config.set("datasource_CSVDETAILS", "name", "test6")
def setUp(self): shutil.rmtree("./var/objects/test20", True) os.makedirs("./var/objects/test20") shutil.rmtree("./var/objects/test20se", True) os.makedirs("./var/objects/test20se") self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh3.cfg') self.generator = coshsh.generator.Generator() setup_logging()
def setUp(self): self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh4.cfg') self.generator = coshsh.generator.Generator() setup_logging() self.pp = pprint.PrettyPrinter(indent=4) if 'OMD_ROOT' in os.environ: self.log_dir = os.path.join(os.environ['OMD_ROOT'], "var", "coshsh") else: self.log_dir = gettempdir()
def setUp(self): shutil.rmtree("./var/objects/test12", True) os.makedirs("./var/objects/test12") shutil.rmtree("./var/objects/test1", True) os.makedirs("./var/objects/test1") self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh.cfg') self.generator = coshsh.generator.Generator() setup_logging() self.pp = pprint.PrettyPrinter(indent=4)
def setUp(self): shutil.rmtree("./var/objects/test1", True) os.makedirs("./var/objects/test1") shutil.rmtree("./var/log", True) os.makedirs("./var/log") self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh.cfg') self.generator = coshsh.generator.Generator() setup_logging(logfile="zishsh.log", logdir="./var/log", scrnloglevel=logging.DEBUG, txtloglevel=logging.INFO) # default, wie im coshsh-cook setup_logging(logdir="./var/log", scrnloglevel=logging.INFO)
def test_create_custom_contact(self): self.print_header() self.generator.add_recipe(name='test221', **dict(self.config.items('recipe_test221'))) self.generator.add_recipe(name='test222', **dict(self.config.items('recipe_test222'))) self.config.set("datasource_CSV22", "name", "csv22") cfg = self.config.items("datasource_CSV22") self.generator.recipes['test221'].add_datasource(**dict(cfg)) self.generator.recipes['test222'].add_datasource(**dict(cfg)) # read the datasources setup_logging(logdir=self.log_dir, scrnloglevel=DEBUG) self.generator.recipes['test221'].collect() self.generator.recipes['test221'].assemble() cwebw = self.generator.recipes['test221'].objects['contacts']['lausser+WEBREADWRITE++lausserg'] cmail = self.generator.recipes['test221'].objects['contacts']['[email protected]+lausserg'] ctick = self.generator.recipes['test221'].objects['contacts']['lausser+MYTICKETTOOL+lausser@consolq+lausserg'] ctick.custom_macros["ENVIRONMENT"] = "dev" utick = self.generator.recipes['test221'].objects['contacts']['lausser+UNKTICKETTOOL+lausser@consolq+lausserg'] utick.custom_macros["ENVIRONMENT"] = "dev" self.generator.recipes['test221'].render() #self.pp.pprint(cwebw.__dict__) #self.pp.pprint(cmail.__dict__) #self.pp.pprint(ctick.__dict__) #self.pp.pprint(utick.__dict__) print self.generator.recipes['test221'].objects['contacts'] self.assert_(cwebw.can_submit_commands == True) self.assert_(cwebw.service_notification_options == "n") self.assert_(cwebw.service_notification_commands == ["notify_by_nothing"]) self.assert_(cmail.can_submit_commands == False) self.assert_(cmail.service_notification_options == "w,c,u,r,f") self.assert_(cmail.service_notification_commands == ["service-notify-by-email"]) self.assert_(cmail.email == "*****@*****.**") self.assert_(ctick.__class__.__name__ == "ContactMyTicketTool") self.assert_(ctick.can_submit_commands == False) self.assert_(ctick.service_notification_options == "w,c") self.assert_(ctick.service_notification_commands == ["service-notify-by-msend"]) self.assert_(ctick.queue_id == "lausser@consolq") self.assert_("ENVIRONMENT" in ctick.config_files['nagios']['contact_lausserg.cfg']) self.assert_(utick.__class__.__name__ == "GenericContact") self.generator.recipes['test221'].output() self.assert_(os.path.exists("var/objects/test22/dynamic/hosts"))
def setUp(self): Application.class_factory = [] # da nutzt alles rmtree nix shutil.rmtree("./var/objects/test33", True) os.makedirs("./var/objects/test33") shutil.rmtree("./var/log/coshshlogs", True) shutil.rmtree("/tmp/coshsh_test34.log", True) shutil.rmtree("/tmp/coshsh5/coshsh.log", True) self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh5.cfg') print self.config.__dict__ self.generator = coshsh.generator.Generator() if "defaults" in self.config.sections() and "log_dir" in [c[0] for c in self.config.items("defaults")]: log_dir = dict(self.config.items("defaults"))["log_dir"] log_dir = re.sub('%.*?%', coshsh.util.substenv, log_dir) elif 'OMD_ROOT' in os.environ: log_dir = os.path.join(os.environ['OMD_ROOT'], "var", "coshsh") else: log_dir = gettempdir() setup_logging(logdir=log_dir, scrnloglevel=logging.DEBUG)
def setUp(self): shutil.rmtree("./var/objects/test1", True) os.makedirs("./var/objects/test1") shutil.rmtree("./var/tmp", True) os.makedirs("./var/tmp") recipe_configs = {} datasource_configs = {} datarecipient_configs = {} cookbook = ConfigParser.ConfigParser() cookbook.read("etc/coshsh.cfg") for ds in [section for section in cookbook.sections() if section.startswith('datarecipient_')]: datarecipient_configs[ds.replace("datarecipient_", "", 1).lower()] = cookbook.items(ds) + [('name', ds.replace("datarecipient_", "", 1).lower())] for ds in [section for section in cookbook.sections() if section.startswith('datasource_')]: datasource_configs[ds.replace("datasource_", "", 1).lower()] = cookbook.items(ds) + [('name', ds.replace("datasource_", "", 1).lower())] for recipe in [section for section in cookbook.sections() if section.startswith('recipe_')]: recipe_configs[recipe.replace("recipe_", "", 1).lower()] = cookbook.items(recipe) + [('name', recipe.replace("recipe_", "", 1).lower())] recipes = [] if False: pass #recipes = [r.lower() for r in opts.default_recipe.split(",")] else: if "defaults" in cookbook.sections() and "recipes" in [c[0] for c in cookbook.items("defaults")]: recipes = [recipe.lower() for recipe in dict(cookbook.items("defaults"))["recipes"].split(",")] else: recipes = recipe_configs.keys() if "defaults" in cookbook.sections() and "log_dir" in [c[0] for c in cookbook.items("defaults")]: log_dir = dict(cookbook.items("defaults"))["log_dir"] log_dir = re.sub('%.*?%', substenv, log_dir) else: coshsh_home = os.path.join(os.path.dirname(__file__), '..', 'coshsh') os.environ['COSHSH_HOME'] = coshsh_home log_dir = os.path.join(os.environ['COSHSH_HOME'], "..") if "defaults" in cookbook.sections() and "pid_dir" in [c[0] for c in cookbook.items("defaults")]: pid_dir = dict(cookbook.items("defaults"))["pid_dir"] pid_dir = re.sub('%.*?%', substenv, pid_dir) else: pid_dir = os.path.join(os.environ['COSHSH_HOME'], "..") self.generator = coshsh.generator.Generator() setup_logging(scrnloglevel=DEBUG) for recipe in recipes: if recipe == 'test1': recipe_configs[recipe].append(('pid_dir', pid_dir)) self.generator.add_recipe(**dict(recipe_configs[recipe]))
def setUp(self): Application.class_factory = [] # da nutzt alles rmtree nix shutil.rmtree("./var/objects/test33", True) os.makedirs("./var/objects/test33") shutil.rmtree("./var/log/coshshlogs", True) shutil.rmtree("/tmp/coshsh_test34.log", True) shutil.rmtree("/tmp/coshsh5/coshsh.log", True) self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh5.cfg') print self.config.__dict__ self.generator = coshsh.generator.Generator() if "defaults" in self.config.sections() and "log_dir" in [ c[0] for c in self.config.items("defaults") ]: log_dir = dict(self.config.items("defaults"))["log_dir"] log_dir = re.sub('%.*?%', coshsh.util.substenv, log_dir) elif 'OMD_ROOT' in os.environ: log_dir = os.path.join(os.environ['OMD_ROOT'], "var", "coshsh") else: log_dir = gettempdir() setup_logging(logdir=log_dir, scrnloglevel=logging.DEBUG)
def setUp(self): self.config = coshsh.configparser.CoshshConfigParser() self.config.read('etc/coshsh2.cfg') pp = pprint.PrettyPrinter(indent=4) pp.pprint(self.config._sections.values()) self.generator = coshsh.generator.Generator() setup_logging() recipe_configs = {} for recipe in [ section for section in self.config.sections() if section.startswith('recipe_') ]: recipe_configs[recipe.replace( "recipe_", "", 1).lower()] = self.config.items(recipe) + [ ('name', recipe.replace("recipe_", "", 1).lower()) ] print "-->", recipe recipes = filter(lambda r: not r.startswith("_"), recipe_configs.keys()) print "recipes", recipes self.assert_("_cust2" not in recipes and "cust2" not in recipes)
def setUp(self): cookbook = coshsh.configparser.CoshshConfigParser() cookbook.read('etc/coshsh7.cfg') self.pp = pprint.PrettyPrinter(indent=4) #pp.pprint(self.config._sections.values()) self.generator = coshsh.generator.Generator() setup_logging() recipe_configs = {} datasource_configs = {} for ds in [ section for section in cookbook.sections() if section.startswith('datasource_') ]: datasource_configs[ds.replace( "datasource_", "", 1).lower()] = cookbook.items(ds) + [ ('name', ds.replace("datasource_", "", 1).lower()) ] for recipe in [ section for section in cookbook.sections() if section.startswith('recipe_') ]: recipe_configs[recipe.replace( "recipe_", "", 1).lower()] = cookbook.items(recipe) + [ ('name', recipe.replace("recipe_", "", 1).lower()) ] recipes = filter(lambda r: not r.startswith("_"), recipe_configs.keys()) for recipe in recipes: if recipe in recipe_configs.keys(): self.generator.add_recipe(**dict(recipe_configs[recipe])) for ds in self.generator.recipes[recipe].datasource_names: if ds in datasource_configs.keys(): self.generator.recipes[recipe].add_datasource( **dict(datasource_configs[ds]))
def clean_generator(self): self.generator = None self.generator = coshsh.generator.Generator() setup_logging()
def setUp(self): self.config = ConfigParser.ConfigParser() self.config.read('etc/coshsh.cfg') self.generator = coshsh.generator.Generator() setup_logging()
def setUp(self): self.config = coshsh.configparser.CoshshConfigParser() self.config.read('etc/coshsh.cfg') self.generator = coshsh.generator.Generator() setup_logging()
403: "Forbidden", 500: "Internal Server Error" } status = 200 omdadmin = "omdadmin" try: os.environ["OMD_ROOT"] = os.environ["DOCUMENT_ROOT"].replace( "/var/www", "") if not os.environ["OMD_ROOT"].startswith("/omd/sites/"): result["error"] = "This script must be run in an OMD environment" status = 400 raise CGIAbort setup_logging( logdir=os.environ["OMD_ROOT"] + "/var/log", logfile="downtime-api.log", scrnloglevel=logging.CRITICAL, txtloglevel=logging.DEBUG, format="[%(asctime)s][%(process)d] - %(levelname)s - %(message)s") logger = logging.getLogger('downtime-api') params = cgi.FieldStorage() logger.debug(os.environ['REQUEST_METHOD']) logger.debug(params) logger.debug(params.getfirst("host", None)) host_name = params.getfirst("host", None) hostgroup_name = params.getfirst("hostgroup", None) service_description = params.getfirst("service", None) comment = params.getfirst("comment", None) duration = params.getfirst("duration", None) dtauthtoken = params.getfirst("dtauthtoken", None) backend = params.getfirst("backend", None)
def xtest_create_generator_by_coshsh(self): self.print_header() self.generator = coshsh.Generator() setup_logging(scrnloglevel=logging.DEBUG)