Skip to main content

Posts

Showing posts with the label Scripting

Creating your own Speedtest utility in Python

It is easy to create your own speedtest utility in Python. You will require Speedtest-CLI module to build your utility. To install Speedtest-cli, run “ pip install speedtest-cli ” command Once speedtest-cli is installed, import it into your Python file. import speedtest result = speedtest . Speedtest ()   Following code will help you to find the best Speedtest server depending on your location best_server = result . get_best_server () print ( f "Checking speedtest using server located in { best_server [ 'country' ] } " )   Now, run the speed test for Download, Upload and ping result. # Running the download speed print ( "Running download speedtest..." ) dw_result = result . download () # Running the upload spped print ( "Running upload speedtest..." ) up_result = result . upload () # Running a ping test ping_result = result . results . ping   Using below code, you can covert the result in to Mbps and truncate the value to 2 decima

Python script to list all AWS CloudWatch logs with their retention time

The following Python script will help you to export list of any all the CloudWatch logs with their retention time and size of the log group an AWS account. The script also helps you to save the output within CSV file. #!/usr/bin/env python3.8 #This script will save the list of CloudWatch log group names, their retention time and # size (in MBs) in to CSV file import boto3 import time import csv # Setting up AWS profile and region profile = "default" region = "us-east-1" session = boto3 . Session ( profile_name = profile , region_name = region ) #getting current date and time date_time = time . strftime ( " %d %m%Y_%H%M" ) # setting up file name fname = "CloudWatch-Logs_" ftime = date_time fext = ".csv" filename = fname + ftime + fext # open file to write output with open ( filename , 'w' ) as f :     print ( 'Profile, Region,Log Group Name, Retention Time (in days), Size (in MB)' , file = f )   cw_logs =