Raise HOST ALERT entry
        Format is : "HOST ALERT: *get_name()*;*state*;*state_type*;*attempt*;*output*"
        Example : "HOST ALERT: server;DOWN;HARD;1;I don't know what to say..."

        :return: None
176457
def raise_alert_log_entry(self):
        
        if self.__class__.log_alerts:
            log_level = 'info'
            if self.state == 'DOWN':
                log_level = 'error'
            if self.state == 'UNREACHABLE':
                log_level = 'warning'
            brok = make_monitoring_log(
                log_level, 'HOST ALERT: %s;%s;%s;%d;%s' % (
                    self.get_name(), self.state, self.state_type, self.attempt, self.output
                )
            )
            self.broks.append(brok)

        if 'ALIGNAK_LOG_ALERTS' in os.environ:
            if os.environ['ALIGNAK_LOG_ALERTS'] == 'WARNING':
                logger.warning('HOST ALERT: %s;%s;%s;%d;%s', self.get_name(), self.state,
                               self.state_type, self.attempt, self.output)
            else:
                logger.info('HOST ALERT: %s;%s;%s;%d;%s', self.get_name(), self.state,
                            self.state_type, self.attempt, self.output)
267647
def _update_pretty_hostname(new_val: str):
    
    try:
        with open('/etc/machine-info') as emi:
            contents = emi.read()
    except OSError:
        LOG.exception("Couldn't read /etc/machine-info")
        contents = ''
    new_contents = ''
    for line in contents.split('\n'):
        if not line.startswith('PRETTY_HOSTNAME'):
            new_contents += f'{line}\n'
    new_contents += f'PRETTY_HOSTNAME={new_val}\n'
    with open('/etc/machine-info', 'w') as emi:
        emi.write(new_contents)
414423
def from_hostname(cls, hostname):
        """"""
        result = cls.list({'hostname': str(hostname)})
        if result:
            return result[0]['id']
795597
def raise_check_result(self):
        
        if not self.__class__.log_active_checks:
            return

        log_level = 'info'
        if self.state in [u'WARNING', u'UNREACHABLE']:
            log_level = 'warning'
        elif self.state == u'CRITICAL':
            log_level = 'error'
        brok = make_monitoring_log(
            log_level, 'ACTIVE SERVICE CHECK: %s;%s;%s;%d;%s' % (self.host_name, self.get_name(),
                                                                 self.state, self.attempt,
                                                                 self.output)
        )
        self.broks.append(brok)
1336991
def _FormatHostname(self, event):
    
    hostname = self._output_mediator.GetHostname(event)
    return self._SanitizeField(hostname)
1086535
def is_correct(self):
        
        state = True

        # _internal_host_check is for having an host check result
        # without running a check plugin
        if self.command_name.startswith('_internal_host_check'):
            # Command line may contain: [state_id][;output]
            parameters = self.command_line.split(';')
            if len(parameters) < 2:
                self.command_name = "_internal_host_check;0;Host assumed to be UP"
                self.add_warning("[%s::%s] has no defined state nor output. Changed to %s"
                                 % (self.my_type, self.command_name, self.command_name))
            elif len(parameters) < 3:
                state = 3
                try:
                    state = int(parameters[1])
                except ValueError:
                    self.add_warning("[%s::%s] required a non integer state: %s. Using 3."
                                     % (self.my_type, self.command_name, parameters[1]))

                if state > 4:
                    self.add_warning("[%s::%s] required an impossible state: %d. Using 3."
                                     % (self.my_type, self.command_name, state))

                output = {0: "UP", 1: "DOWN", 2: "DOWN", 3: "UNKNOWN", 4: "UNREACHABLE", }[state]
                self.command_name = "_internal_host_check;Host assumed to be %s" % output

                self.add_warning("[%s::%s] has no defined output. Changed to %s"
                                 % (self.my_type, self.command_name, self.command_name))
            elif len(parameters) > 3:
                self.command_name = "%s;%s;%s" % (parameters[0], parameters[1], parameters[2])

                self.add_warning("[%s::%s] has too many parameters. Changed to %s"
                                 % (self.my_type, self.command_name, self.command_name))

        return super(Command, self).is_correct() and state
501698
def cmd_dns_lookup_forward(hostname, verbose):
    
    if verbose:
        logging.basicConfig(level=logging.INFO, format='%(message)s')
        print("Looking up %s..." % hostname, file=sys.stderr)

    answer = lookup_forward(hostname)

    print(json.dumps(answer, indent=4))

    return True
327419
def _get_interface_name_from_hosting_port(self, port):
        
        try:
            vlan = port['hosting_info']['segmentation_id']
            int_prefix = port['hosting_info']['physical_interface']
            return '%s.%s' % (int_prefix, vlan)
        except KeyError as e:
            params = {'key': e}
            raise cfg_exc.DriverExpectedKeyNotSetException(**params)
650627
def get_host_system_failfast(
            self,
            name,
            verbose=False,
            host_system_term='HS'
    ):
        
        if verbose:
            print("Finding HostSystem named %s..." % name)

        hs = self.get_host_system(name)

        if hs is None:
            print("Error: %s '%s' does not exist" % (host_system_term, name))
            sys.exit(1)

        if verbose:
            print("Found HostSystem: {0} Name: {1}" % (hs, hs.name))

        return hs
1280405
def get_alert(self, alert):
        
        if alert > self.alerts_count() or self.alerts_count() is None:
            return None
        else:
            return self.get()[alert-1]
209998
async def helo(
        self, hostname: str = None, timeout: DefaultNumType = _default
    ) -> SMTPResponse:
        
        if hostname is None:
            hostname = self.source_address
        async with self._command_lock:
            response = await self.execute_command(
                b"HELO", hostname.encode("ascii"), timeout=timeout
            )
        self.last_helo_response = response

        if response.code != SMTPStatus.completed:
            raise SMTPHeloError(response.code, response.message)

        return response
1120378
def validate_host(cert, name):
    
    cn = None
    for t, v in cert.get_subject().get_components():
        if t == b'CN':
            cn = v
            break

    if cn == name:
        return True

    # checking SAN
    s_name = name.decode('ascii')
    for i in range(cert.get_extension_count()):
        ext = cert.get_extension(i)
        if ext.get_short_name() == b'subjectAltName':
            s = str(ext)
            # SANs are usually have form like: DNS:hostname
            if s.startswith('DNS:') and s[4:] == s_name:
                return True

    # TODO handle wildcards
    return False
576751
async def ehlo(
        self, hostname: str = None, timeout: DefaultNumType = _default
    ) -> SMTPResponse:
        
        if hostname is None:
            hostname = self.source_address

        async with self._command_lock:
            response = await self.execute_command(
                b"EHLO", hostname.encode("ascii"), timeout=timeout
            )
        self.last_ehlo_response = response

        if response.code != SMTPStatus.completed:
            raise SMTPHeloError(response.code, response.message)

        return response
106525
def _get_host_details(self):
        """"""
        # Assuming only one system present as part of collection,
        # as we are dealing with iLO's here.
        status, headers, system = self._rest_get('/rest/v1/Systems/1')
        if status < 300:
            stype = self._get_type(system)
            if stype not in ['ComputerSystem.0', 'ComputerSystem.1']:
                msg = "%s is not a valid system type " % stype
                raise exception.IloError(msg)
        else:
            msg = self._get_extended_error(system)
            raise exception.IloError(msg)

        return system
145536
def _format_info(self):
		
		info = 'GNTP/%s %s' % (
			self.info.get('version'),
			self.info.get('messagetype'),
		)
		if self.info.get('encryptionAlgorithmID', None):
			info += ' %s:%s' % (
				self.info.get('encryptionAlgorithmID'),
				self.info.get('ivValue'),
			)
		else:
			info += ' NONE'

		if self.info.get('keyHashAlgorithmID', None):
			info += ' %s:%s.%s' % (
				self.info.get('keyHashAlgorithmID'),
				self.info.get('keyHash'),
				self.info.get('salt')
			)

		return info
669216
def hostname(self):
    """"""
    hostname_artifact = self._hostnames.get(self.CURRENT_SESSION, None)
    if not hostname_artifact:
      return ''

    return hostname_artifact.name or ''
832229
def server_hostname(self):
        
        result = c_char_p(
            self.lib.iperf_get_test_server_hostname(self._test)
        ).value
        if result:
            self._server_hostname = result.decode('utf-8')
        else:
            self._server_hostname = None
        return self._server_hostname