def linkify_es_by_s(self, services): """Add each escalation object into service.escalation attribute :param services: service list, used to look for a specific service :type services: alignak.objects.service.Services :return: None """ for escal in self: # If no host, no hope of having a service if not (hasattr(escal, 'host_name') and hasattr(escal, 'service_description')): continue es_hname, sdesc = escal.host_name, escal.service_description if '' in (es_hname.strip(), sdesc.strip()): continue for hname in strip_and_uniq(es_hname.split(',')): if sdesc.strip() == '*': slist = services.find_srvs_by_hostname(hname) if slist is not None: for serv in slist: serv.escalations.append(escal) else: for sname in strip_and_uniq(sdesc.split(',')): serv = services.find_srv_by_name_and_hostname(hname, sname) if serv is not None: # print "Linking service", s.get_name(), 'with me', es.get_name() serv.escalations.append(escal)
def linkify_es_by_s(self, services): """Add each escalation object into service.escalation attribute :param services: service list, used to look for a specific service :type services: alignak.objects.service.Services :return: None """ for escal in self: # If no host, no hope of having a service if not (hasattr(escal, 'host_name') and hasattr(escal, 'service_description')): continue es_hname, sdesc = escal.host_name, escal.service_description if '' in (es_hname.strip(), sdesc.strip()): continue for hname in strip_and_uniq(es_hname.split(',')): if sdesc.strip() == '*': slist = services.find_srvs_by_hostname(hname) if slist is not None: for serv in slist: serv.escalations.append(escal) else: for sname in strip_and_uniq(sdesc.split(',')): serv = services.find_srv_by_name_and_hostname( hname, sname) if serv is not None: # print "Linking service", s.get_name(), 'with me', es.get_name() serv.escalations.append(escal)
def linkify_es_by_s(self, services): """Add each escalation object into service.escalation attribute :param services: service list, used to look for a specific service :type services: alignak.objects.service.Services :return: None """ for escalation in self: # If no host, no hope of having a service if not hasattr(escalation, 'host_name'): continue es_hname, sdesc = escalation.host_name, escalation.service_description if not es_hname.strip() or not sdesc.strip(): continue for hname in strip_and_uniq(es_hname.split(',')): if sdesc.strip() == '*': slist = services.find_srvs_by_hostname(hname) if slist is not None: slist = [services[serv] for serv in slist] for serv in slist: serv.escalations.append(escalation.uuid) else: for sname in strip_and_uniq(sdesc.split(',')): serv = services.find_srv_by_name_and_hostname(hname, sname) if serv is not None: serv.escalations.append(escalation.uuid)
def linkify_s_by_plug(self): """ Link modules :return: None """ for module in self: new_modules = [] mods = strip_and_uniq(module.modules) for plug_name in mods: plug_name = plug_name.strip() # don't read void names if plug_name == '': continue # We are the modules, we search them :) plug = self.find_by_name(plug_name) if plug is not None: new_modules.append(plug) else: err = "[module] unknown %s module from %s" % ( plug_name, module.get_name()) logger.error(err) module.configuration_errors.append(err) module.modules = new_modules
def linkify_s_by_plug(self): """ Link modules :return: None """ for module in self: new_modules = [] mods = strip_and_uniq(module.modules) for plug_name in mods: plug_name = plug_name.strip() # don't read void names if plug_name == '': continue # We are the modules, we search them :) plug = self.find_by_name(plug_name) if plug is not None: new_modules.append(plug) else: err = "[module] unknown %s module from %s" % (plug_name, module.get_name()) logger.error(err) module.configuration_errors.append(err) module.modules = new_modules
def linkify_with_notificationways(self, notificationways): """Link hosts with realms :param notificationways: notificationways object to link with :type notificationways: alignak.objects.notificationway.Notificationways :return: None """ for i in self: if not hasattr(i, 'notificationways'): continue new_notificationways = [] for nw_name in strip_and_uniq(i.notificationways): notifway = notificationways.find_by_name(nw_name) if notifway is not None: new_notificationways.append(notifway.uuid) else: err = "The 'notificationways' of the %s '%s' named '%s' is unknown!" %\ (i.__class__.my_type, i.get_name(), nw_name) i.add_error(err) # Get the list, but first make elements unique i.notificationways = list(set(new_notificationways)) # Update the contact host/service notification commands properties i.get_notification_commands(notificationways, 'host', command_name=True) i.get_notification_commands(notificationways, 'service', command_name=True)
def find_object(self, pattern): """Get a list of host corresponding to the pattern regarding the context :param pattern: pattern to find :type pattern: str :return: Host list matching pattern (hostgroup name, template, all) :rtype: list[alignak.objects.host.Host] """ obj = None error = None pattern = pattern.strip() if pattern == '*': obj = [ h.host_name for h in list(self.all_elements.items.values()) if getattr(h, 'host_name', '') != '' and not h.is_tpl() ] return obj, error # Ok a more classic way if self.ctx == 'hostgroups': # Ok try to find this hostgroup hgr = self.grps.find_by_name(pattern) # Maybe it's an known one? if not hgr: error = "Error : cannot find the %s of the expression '%s'" % ( self.ctx, pattern) return hgr, error # Ok the group is found, get the elements! elts = hgr.get_hosts() elts = strip_and_uniq(elts) # Maybe the hostgroup memebrs is '*', if so expand with all hosts if '*' in elts: elts.extend([ h.host_name for h in list(self.all_elements.items.values()) if getattr(h, 'host_name', '') != '' and not h.is_tpl() ]) # And remove this strange hostname too :) elts.remove('*') return elts, error obj = self.grps.find_hosts_that_use_template(pattern) return obj, error
def linkify_es_by_h(self, hosts): """Add each escalation object into host.escalation attribute :param hosts: host list, used to look for a specific host :type hosts: alignak.objects.host.Hosts :return: None """ for escal in self: # If no host, no hope of having a service if (not hasattr(escal, 'host_name') or escal.host_name.strip() == '' or (hasattr(escal, 'service_description') and escal.service_description.strip() != '')): continue # I must be NOT a escalation on for service for hname in strip_and_uniq(escal.host_name.split(',')): host = hosts.find_by_name(hname) if host is not None: host.escalations.append(escal.uuid)
def find_object(self, pattern): """Get a list of host corresponding to the pattern regarding the context :param pattern: pattern to find :type pattern: str :return: Host list matching pattern (hostgroup name, template, all) :rtype: list[alignak.objects.host.Host] """ obj = None error = None pattern = pattern.strip() if pattern == '*': obj = [h.host_name for h in self.all_elements.items.values() if getattr(h, 'host_name', '') != '' and not h.is_tpl()] return obj, error # Ok a more classic way # print "GRPS", self.grps if self.ctx == 'hostgroups': # Ok try to find this hostgroup hgr = self.grps.find_by_name(pattern) # Maybe it's an known one? if not hgr: error = "Error : cannot find the %s of the expression '%s'" % (self.ctx, pattern) return hgr, error # Ok the group is found, get the elements! elts = hgr.get_hosts() elts = strip_and_uniq(elts) # Maybe the hostgroup memebrs is '*', if so expand with all hosts if '*' in elts: elts.extend([h.host_name for h in self.all_elements.items.values() if getattr(h, 'host_name', '') != '' and not h.is_tpl()]) # And remove this strange hostname too :) elts.remove('*') return elts, error else: # templates obj = self.grps.find_hosts_that_use_template(pattern) return obj, error
def linkify_with_notificationways(self, notificationways): """Link hosts with realms :param notificationways: notificationways object to link with :type notificationways: alignak.objects.notificationway.Notificationways :return: None """ for i in self: if not hasattr(i, 'notificationways'): continue new_notificationways = [] for nw_name in strip_and_uniq(i.notificationways): notifway = notificationways.find_by_name(nw_name) if notifway is not None: new_notificationways.append(notifway) else: err = "The 'notificationways' of the %s '%s' named '%s' is unknown!" %\ (i.__class__.my_type, i.get_name(), nw_name) i.configuration_errors.append(err) # Get the list, but first make elements uniq i.notificationways = list(set(new_notificationways))
def linkify_command_list_with_commands(self, commands, prop): """ Link a command list (commands with , between) in real CommandCalls :param commands: commands object :type commands: alignak.objects.command.Commands :param prop: property name :type prop: str :return: None """ for i in self: if not hasattr(i, prop): continue commands_list = strip_and_uniq(getattr(i, prop, '')) cmds_list = [] for command in commands_list: if not command: continue cmds_list.append(self.create_commandcall(i, commands, command)) setattr(i, prop, cmds_list)
def linkify_command_list_with_commands(self, commands, prop): """ Link a command list (commands with , between) in real CommandCalls :param commands: commands object :type commands: alignak.objects.command.Commands :param prop: property name :type prop: str :return: None """ for i in self: if hasattr(i, prop): coms = strip_and_uniq(getattr(i, prop)) com_list = [] for com in coms: if com != '': cmdcall = self.create_commandcall(i, commands, com) # TODO: catch None? com_list.append(cmdcall) else: # TODO: catch? pass setattr(i, prop, com_list)