예제 #1
0
        subject = 'Error - Available disk space is less than 20%'
        return subject
    elif not check_cpu_usage(1):
        subject = 'Error - CPU usage is over 80%'
        return subject
    elif not check_memory_usage():
        subject = 'Error - Available memory is less than 500MB'
        return subject
    elif not resolve_hostname():
        subject = 'Error - localhost cannot be resolved to 127.0.0.1'
        return subject
    # Here we are returning none, so that we can use it later to compare it in email subject
    else:
        return None


if __name__ == "__main__":
    # To ge the username from environment variable
    USER = os.getenv('USER')
    # Running the check error function to fetch subject line
    new_subject = check_error()
    # If we found None as return value do nothing, otherwise send email
    if new_subject is not None:
        # body line give in assignment for email
        new_body = 'Please check your system and resolve the issue as soon as possible.'
        # structuring email and attaching the file. Then sending the email, using the custom module.
        msg = email_generate("*****@*****.**",
                             "{}@example.com".format(USER), new_subject,
                             new_body, "")
        email_send(msg)
        return subject
    elif not check_cpu_usage(1):
        subject = 'Error - CPU usage is over 80%'
        return subject
    elif not check_memory_usage():
        subject = 'Error - Available memory is less than 500MB'
        return subject
    elif not resolve_hostname():
        subject = 'Error - localhost cannot be resolved to 127.0.0.1'
        return subject
    # Here we are returning none, so that we can use it later to compare it in email subject
    else:
        return None


if __name__ == "__main__":
    # To ge the username from environment variable
    USER = os.getenv('USER')
    # Running the check error function to fetch subject line
    new_subject = check_error()
    # If we found None as return value do nothing, otherwise send email
    if new_subject is not None:
        # body line give in assignment for email
        new_body = 'Please check your system and resolve the issue as soon as possible.'
        # structuring email and attaching the file. Then sending the email, using the custom module.
        msg = email_generate(
            "*****@*****.**",
            "*****@*****.**".format(USER), new_subject,
            new_body, "")
        email_send(msg)

if __name__ == "__main__":
    # To get the username from environment variable
    USER = os.getenv('USER')
    # To set encoding to avoid ascii errors
    locale.setlocale(locale.LC_ALL, 'en_US.UTF8')
    # The directory which contains all the files with data in it.
    description_directory = '/home/{}/supplier-data/descriptions/'.format(USER)
    # Listing all the files in description directory
    description_files = os.listdir(description_directory)
    # The directory which contains all the images.
    image_directory = '/home/{}/supplier-data/images/'.format(USER)
    # URL to push the data to the website
    url = "http://localhost/fruits/"
    # Creating data in format "May 5, 2020"
    current_date = datetime.date.today().strftime("%B %d, %Y")
    # Title for the PDF file with the created date
    title = 'Processed Update on ' + str(current_date)
    # subject line give in assignment for email
    new_subject = 'Upload Completed - Online Fruit Store'
    # body line give in assignment for email
    new_body = 'All fruits are uploaded to our website successfully. A detailed list is attached to this email.'
    # calling the report function from custom module
    report('/tmp/processed.pdf', title, summary('pdf'))
    # structuring email and attaching the file. Then sending the email, using the custom module.
    email = email_generate("*****@*****.**",
                           "{}@example.com".format(USER), new_subject,
                           new_body, "/tmp/processed.pdf")
    email_send(email)