in Linux_scripts/rhui-check/rhui-check.py [0:0]
def connect_to_host(url, selection, mysection):
try:
uname = os.uname()
except:
logger.critical('Unable to identify OS version.')
exit(1)
try:
basearch = uname.machine
except AttributeError:
basearch = uname[-1]
try:
baserelease = uname.release
except AttributeError:
baserelease = uname[2]
if eus:
fd = open('/etc/yum/vars/releasever')
releasever = fd.readline().strip()
else:
releasever = re.sub(r'^.*el([0-9][0-9]*).*',r'\1',baserelease)
if releasever == '7':
releasever = '7Server'
url = url+"/repodata/repomd.xml"
url = url.replace('$releasever',releasever)
url = url.replace('$basearch',basearch)
logger.debug('baseurl for repo {} is {}'.format(mysection, url))
headers = {'content-type': 'application/json'}
s = requests.Session()
local_proxy = get_proxies(selection, mysection)
cert = ()
try:
cert=(selection.get(mysection, 'sslclientcert'), selection.get(mysection, 'sslclientkey'))
except:
logger.warning('Client certificate and/or client key attribute not found for {}, testing connectivity w/o certificates'.format(mysection))
cert=()
try:
r = s.get(url, cert=cert, headers=headers, timeout=5, proxies=local_proxy)
except requests.exceptions.Timeout:
logger.warning('TIMEOUT: Unable to reach RHUI URI {}'.format(url))
return False
except requests.exceptions.SSLError:
validate_ca_certificates()
logger.warning('PROBLEM: MITM proxy misconfiguration. Proxy cannot intercept certs for {}'.format(url))
return 1
except requests.exceptions.ProxyError:
logger.warning('PROBLEM: Unable to use the proxy gateway when connecting to RHUI server {}'.format(url))
return False
except requests.exceptions.ConnectionError as e:
logger.warning('PROBLEM: Unable to establish connectivity to RHUI server {}'.format(url))
logger.error('{}'.format(e))
return False
except OSError:
validate_ca_certificates()
raise()
except Exception as e:
logger.warning('PROBLEM: Unknown error, unable to connect to the RHUI server {}'.format(url))
raise(e)
return False
else:
if r.status_code == 200:
logger.debug('The RC for this {} link is {}'.format(url, r.status_code))
return True
elif r.status_code == 404:
logger.error("Unable to find the contents for repo {}, make sure to use the correct version lock if you're using EUS repositories".format(mysection))
logger.error("For more detailed information and valid levels consult: https://access.redhat.com/support/policy/updates/errata#RHEL8_and_9_Life_Cycle")
return False
else:
logger.warning('The RC for this {} link is {}'.format(url, r.status_code))
return False