<jupyter_start><jupyter_text><jupyter_code>#!/usr/bin/env python3
import shutil
import psutil
def check_disk_usage(disk):
    """Verifies that there's enough free space on disk"""
    du = shutil.disk_usage(disk)
    free = du.free / du.total * 100
    return free > 20
def check_cpu_usage():
    """Verifies that there's enough unused CPU"""
    usage = psutil.cpu_percent(1)
    return usage > 75
# If there's not enough disk, or not enough CPU, print an error
if not check_disk_usage('/') or not check_cpu_usage():
    print("ERROR!")
else:
    print("Everything ok")
  -'<jupyter_output><empty_output><jupyter_text>Check whether cpu and disk usage are above certain level or not<jupyter_code>#!/usr/bin/env python3
from network import *
import shutil
import psutil
def check_disk_usage(disk):
    """Verifies that there's enough free space on disk"""
    du = shutil.disk_usage(disk)
    free = du.free / du.total * 100
    return free > 20

def check_cpu_usage():
    """Verifies that there's enough unused CPU"""
    usage = psutil.cpu_percent(1)
    return usage < 75

# If there's not enough disk, or not enough CPU, print an error
if not check_disk_usage('/') or not check_cpu_usage():
    print("ERROR!")
elif check_localhost("localhost") and check_connectivity("http://www.google.com"):
    print("Everything Ok")
else:
    print("Network checks failed")<jupyter_output><empty_output><jupyter_text>Use of request to module to connect with website and other localhost etc<jupyter_code>#!/usr/bin/env python3

import requests
import socket

def check_localhost(localhost):
    localhost = socket.gethostbyname('localhost')
    return localhost == '127.0.0.1'

print(check_localhost('localhost'))

def check_connectivity(website):
    request = requests.get("http://www.google.com")
    return request.status_code == 200

print(check_connectivity("http://www.google.com"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11512990320937341, 'fraction_numerical': 0.014263881813550688, 'mean_word_length': 4.048843187660668, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '653381', 'license': 'Apache-2.0', 'n_tokens_mistral': 668, 'n_tokens_neox': 614, 'n_words': 174, 'path': 'Interactingwithoperatingsystemweek1.ipynb', 'repo_name': 'nksharma063/it-cert-automation-practice', 'size': '1963'}