Retrieves the hostname related to the event.

    Args:
      event (EventObject): event.
      default_hostname (Optional[str]): default hostname.

    Returns:
      str: hostname.
425264
def GetHostname(self, event, default_hostname='-'):
    
    hostname = getattr(event, 'hostname', None)
    if hostname:
      return hostname

    session_identifier = event.GetSessionIdentifier()
    if session_identifier is None:
      return default_hostname

    hostname = self._knowledge_base.GetHostname(
        session_identifier=session_identifier)
    return hostname or default_hostname
386636
def _get_hostname(self, hostname, metric):
        
        if hostname is None and self.label_to_hostname is not None:
            for label in metric.label:
                if label.name == self.label_to_hostname:
                    return label.value + self.label_to_hostname_suffix

        return hostname
983304
def get_name(self, host_name):
        
        if wildcard_match(self._pattern, host_name):
            return host_name
        else:
            return self._fallback
1091862
def get_hostname(config, method=None):
    
    method = method or config.get('hostname_method', 'smart')

    # case insensitive method
    method = method.lower()

    if 'hostname' in config and method != 'shell':
        return config['hostname']

    if method in get_hostname.cached_results:
        return get_hostname.cached_results[method]

    if method == 'shell':
        if 'hostname' not in config:
            raise DiamondException(
                "hostname must be set to a shell command for"
                " hostname_method=shell")
        else:
            proc = subprocess.Popen(config['hostname'],
                                    shell=True,
                                    stdout=subprocess.PIPE)
            hostname = proc.communicate()[0].strip()
            if proc.returncode != 0:
                raise subprocess.CalledProcessError(proc.returncode,
                                                    config['hostname'])
            get_hostname.cached_results[method] = hostname
            return hostname

    if method == 'smart':
        hostname = get_hostname(config, 'fqdn_short')
        if hostname != 'localhost':
            get_hostname.cached_results[method] = hostname
            return hostname
        hostname = get_hostname(config, 'hostname_short')
        get_hostname.cached_results[method] = hostname
        return hostname

    if method == 'fqdn_short':
        hostname = socket.getfqdn().split('.')[0]
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'fqdn':
        hostname = socket.getfqdn().replace('.', '_')
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'fqdn_rev':
        hostname = socket.getfqdn().split('.')
        hostname.reverse()
        hostname = '.'.join(hostname)
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'uname_short':
        hostname = os.uname()[1].split('.')[0]
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'uname_rev':
        hostname = os.uname()[1].split('.')
        hostname.reverse()
        hostname = '.'.join(hostname)
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'hostname':
        hostname = socket.gethostname()
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'hostname_short':
        hostname = socket.gethostname().split('.')[0]
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'hostname_rev':
        hostname = socket.gethostname().split('.')
        hostname.reverse()
        hostname = '.'.join(hostname)
        get_hostname.cached_results[method] = hostname
        if hostname == '':
            raise DiamondException('Hostname is empty?!')
        return hostname

    if method == 'none':
        get_hostname.cached_results[method] = None
        return None

    raise NotImplementedError(config['hostname_method'])
150303
def registry_hostname(registry):
    
    if registry.startswith('http:') or registry.startswith('https:'):
        return urlparse(registry).netloc
    else:
        return registry
1025797
private static String getHostName() {
    String hostName = null;
    try {
      hostName = InetAddress.getLocalHost().getHostName();
    } 
    catch (UnknownHostException ex) {
      LOG.info("Unable to obtain hostName", ex);
      hostName = "unknown";
    }
    return hostName;
  }
1201082
def _structlog_default_keys_processor(logger_class, log_method, event):
    '''  '''
    global HOSTNAME

    if 'id' not in event:
        event['id'] = '%s_%s' % (
            datetime.utcnow().strftime('%Y%m%dT%H%M%S'),
            uuid.uuid1().hex
        )

    if 'type' not in event:
        event['type'] = 'log'

    event['host'] = HOSTNAME

    return event
934606
public function get_hostname() {
		$retval = null;
		if(isset($this->connectParams['host'])) {
			$retval = $this->connectParams['host'];
		}
		else {
			throw new \Exception(__METHOD__ .": HOST parameter missing");
		}
		return($this->connectParams['host']);
	}
202597
def determine_hostname(display_name=None):
    
    if display_name:
        # if display_name is provided, just return the given name
        return display_name
    else:
        socket_gethostname = socket.gethostname()
        socket_fqdn = socket.getfqdn()

        try:
            socket_ex = socket.gethostbyname_ex(socket_gethostname)[0]
        except (LookupError, socket.gaierror):
            socket_ex = ''

        gethostname_len = len(socket_gethostname)
        fqdn_len = len(socket_fqdn)
        ex_len = len(socket_ex)

        if fqdn_len > gethostname_len or ex_len > gethostname_len:
            if "localhost" not in socket_ex and len(socket_ex):
                return socket_ex
            if "localhost" not in socket_fqdn:
                return socket_fqdn

        return socket_gethostname
1123679
def file_name(self, event):
        
        name = os.path.basename(event.src_path)
        name = name.replace(".yaml", "")
        name = name.replace(".yml", "")

        return name
615005
def enable_host_event_handler(self, host):
        
        if not host.event_handler_enabled:
            host.modified_attributes |= \
                DICT_MODATTR["MODATTR_EVENT_HANDLER_ENABLED"].value
            host.event_handler_enabled = True
            self.send_an_element(host.get_update_status_brok())
421822
def get_scheduler_from_hostname(self, host_name):
        
        scheduler_uuid = self.hosts_schedulers.get(host_name, None)
        return self.schedulers.get(scheduler_uuid, None)
784846
def _GetLinkedPath(self, event):
    
    if hasattr(event, 'local_path'):
      return event.local_path

    if hasattr(event, 'network_path'):
      return event.network_path

    if hasattr(event, 'relative_path'):
      paths = []
      if hasattr(event, 'working_directory'):
        paths.append(event.working_directory)
      paths.append(event.relative_path)

      return '\\'.join(paths)

    return 'Unknown'
1336991
def _FormatHostname(self, event):
    
    hostname = self._output_mediator.GetHostname(event)
    return self._SanitizeField(hostname)
208881
def host_events(self, host):
        '''
        
        '''
        all_host_events = filter(lambda x: 'event_data' in x and 'host' in x['event_data'] and x['event_data']['host'] == host,
                                 self.events)
        return all_host_events
414423
def from_hostname(cls, hostname):
        """"""
        result = cls.list({'hostname': str(hostname)})
        if result:
            return result[0]['id']
1046716
@Override
  public  String getIndexName(Event event) {
    String realIndexPrefix = BucketPath.escapeString(event.getIndexPrefix() != null ? event.getIndexPrefix() : indexPrefix, event.getHeaders());
    if(event.getIndexTimestamp() != null){

      String indexName = new StringBuilder(realIndexPrefix).append('-')
              .append(event.getIndexTimestamp()).toString();
      if(logger.isDebugEnabled())
        logger.debug("Index Name = " + indexName);
      return indexName;
    }
    else {
      TimestampedEvent timestampedEvent = new TimestampedEvent(event);
      long timestamp = timestampedEvent.getTimestamp();
      String indexName = new StringBuilder(realIndexPrefix).append('-')
              .append(fastDateFormat.format(timestamp)).toString();
      if(logger.isDebugEnabled())
        logger.debug("Index Name = " + indexName);
      return indexName;
    }
  }