code: def duplicate(self, host):
          duplicates = []
          prop = self.duplicate_foreach.strip().upper()
          if prop not in host.customs:
              return duplicates
          entry = host.customs[prop]
          not_entry = host.customs.get('_' + '!' + prop[1:], '').split(',')
          not_keys = strip_and_uniq(not_entry)
          default_value = getattr(self, 'default_value', '')
          try:
              key_values = tuple(generate_key_value_sequences(entry, default_value))
          except KeyValueSyntaxError as exc:
              fmt_dict = {
                  'prop': self.duplicate_foreach,
                  'host': host.get_name(),
                  'svc': self.service_description,
                  'entry': entry,
                  'exc': exc,
              }
              err = (
                  "The custom property %(prop)r of the "
                  "host %(host)r is not a valid entry for a service generator: %(exc)s, "
                  "with entry=%(entry)r") % fmt_dict
              logger.warning(err)
              host.add_error(err)
              return duplicates
          for key_value in key_values:
              key = key_value['KEY']
              if key in not_keys:
                  continue
              new_s = self.copy()
              new_s.host_name = host.get_name()
              if self.is_tpl():
                  new_s.register = 1
              for key in key_value:
                  if key == 'KEY':
                      if hasattr(self, 'service_description'):
                          safe_key_value = re.sub(r'[' + "`~!$%^&*\"|'<>?,()=" + ']+', '_',
                                                  key_value[key])
                          new_s.service_description = self.service_description.replace(
                              '$' + key + '$', safe_key_value
                          )
                  _the_expandables = ['check_command', 'aggregation', 'event_handler']
                  for prop in _the_expandables:
                      if hasattr(self, prop):
                          setattr(new_s, prop, getattr(new_s, prop).replace('$' + key + '$',
                                                                            key_value[key]))
                  if hasattr(self, 'service_dependencies'):
                      for i, servicedep in enumerate(new_s.service_dependencies):
                          new_s.service_dependencies[i] = servicedep.replace(
                              '$' + key + '$', key_value[key]
                          )
              duplicates.append(new_s)
          return duplicates