From 3476c3431bdeb8ef33579fe6099cd10fafeb0a6e Mon Sep 17 00:00:00 2001 From: kshitij Date: Wed, 21 Jan 2026 16:57:24 +0530 Subject: [PATCH 1/6] Python Script Added Task 1 Completed --- day-01/system_health.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 day-01/system_health.py diff --git a/day-01/system_health.py b/day-01/system_health.py new file mode 100644 index 0000000..3be515b --- /dev/null +++ b/day-01/system_health.py @@ -0,0 +1,25 @@ +#pyscipt to Check CPU Usages + +import psutil + +def check_cpu_usages(name,usages,limit): + if usages > limit: + print("CPU alert email Send High Use...") + else: + print("Usages is Ok") + +cpu_limit = int(input("Enter CPU Threshold")) +memory_limit = int(input("Enter Memory Threshold")) +disk_limit = int(input("Enter Disk Threshhold")) + +print("\n Checking Systems Usages...") + +cpu_usage = psutil.cpu_percent(1) +memory_usage = psutil.virtual_memory().percent +disk_usage = psutil.disk_usage('/').percent + +check_cpu_usages("CPU", cpu_usage, cpu_limit) + +check_cpu_usages("Memory", memory_usage, memory_limit) + +check_cpu_usages("Disk", disk_usage, disk_limit) \ No newline at end of file From ebdb6a8f9f2cf1991590ce8de53846a2603858d3 Mon Sep 17 00:00:00 2001 From: kshitij Date: Fri, 23 Jan 2026 15:40:11 +0530 Subject: [PATCH 2/6] Day 2 Task Completed --- day-01/system_health.py | 9 +++--- day-02/api_data_fetcher.py | 56 ++++++++++++++++++++++++++++++++++++++ day-02/output.json | 6 ++++ 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 day-02/api_data_fetcher.py create mode 100644 day-02/output.json diff --git a/day-01/system_health.py b/day-01/system_health.py index 3be515b..265236b 100644 --- a/day-01/system_health.py +++ b/day-01/system_health.py @@ -8,10 +8,11 @@ def check_cpu_usages(name,usages,limit): else: print("Usages is Ok") -cpu_limit = int(input("Enter CPU Threshold")) -memory_limit = int(input("Enter Memory Threshold")) -disk_limit = int(input("Enter Disk Threshhold")) - +for i in range(5): + cpu_limit = int(input("Enter CPU Threshold")) + memory_limit = int(input("Enter Memory Threshold")) + disk_limit = int(input("Enter Disk Threshhold")) + break print("\n Checking Systems Usages...") cpu_usage = psutil.cpu_percent(1) diff --git a/day-02/api_data_fetcher.py b/day-02/api_data_fetcher.py new file mode 100644 index 0000000..e48db89 --- /dev/null +++ b/day-02/api_data_fetcher.py @@ -0,0 +1,56 @@ +import requests +import json + +BASE_URL = "https://pokeapi.co/api/v2/pokemon/" + +def get_Pokemon(pokemon_name): + url = BASE_URL + pokemon_name.lower() + headers = { + "Accept": "application/json" + } + + try: + response = requests.get(url, headers=headers, timeout=10) + response.raise_for_status() + data = response.json() + + print("API is working... \n") + + selected_data = { + "name": data["name"], + "id": data["id"], + "height": data["height"], + "weight": data["weight"], + } + print(json.dumps(selected_data, indent=4)) + + with open("output.json", "w", encoding="utf-8") as f: + json.dump(selected_data, f, indent=4) + + print("Saving data to output.json ") + + return selected_data + + except requests.exceptions.RequestException as e: + print("API request failed ❌") + print("Error:", e) + + + except requests.exceptions.HTTPError: + print(f"❌ Pokémon '{pokemon_name}' not found!") + + except ValueError: + print("Invalid JSON response ❌") + + +# pokemon_data = get_Pokemon() +def main(): + pokemon_name = input("Enter Pokemon Name...Eg.Pikachu,ditto").strip() + # print("Eg.Pikachu,ditto") + + if not pokemon_name: + print("Pokemon cannot be empty") + + get_Pokemon(pokemon_name) + +main() \ No newline at end of file diff --git a/day-02/output.json b/day-02/output.json new file mode 100644 index 0000000..428945d --- /dev/null +++ b/day-02/output.json @@ -0,0 +1,6 @@ +{ + "name": "ditto", + "id": 132, + "height": 3, + "weight": 40 +} \ No newline at end of file From 2cbcc76f4d2ae9f8080666834795f21f77459198 Mon Sep 17 00:00:00 2001 From: kshitij Date: Mon, 26 Jan 2026 14:36:06 +0530 Subject: [PATCH 3/6] Day 03 Task Completed --- day-03/system_health.py | 81 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 day-03/system_health.py diff --git a/day-03/system_health.py b/day-03/system_health.py new file mode 100644 index 0000000..9449b12 --- /dev/null +++ b/day-03/system_health.py @@ -0,0 +1,81 @@ +#pyscipt to Check CPU Usages Updated with Listed Changes +import psutil +from typing import Optional + + +def get_threshold(prompt: str) -> Optional[int]: + try: + value = int(input(prompt)) + if not 0 <= value <= 100: + raise ValueError("Threshold must be between 0 and 100.") + return value + except ValueError as error: + print(f"[INPUT ERROR] {error}") + return None + + +def check_resource_usage(resource_name: str, usage: float, limit: int) -> None: + try: + if usage > limit: + print( + f"[ALERT] {resource_name} usage HIGH: " + f"{usage}% (limit: {limit}%)" + ) + else: + print(f"[OK] {resource_name} usage normal: {usage}%") + except Exception as error: + print(f"[ERROR] Unable to check {resource_name}: {error}") + + +def get_system_usage() -> dict: + try: + return { + "CPU": psutil.cpu_percent(interval=1), + "Memory": psutil.virtual_memory().percent, + "Disk": psutil.disk_usage("/").percent, + } + except Exception as error: + print(f"[SYSTEM ERROR] Failed to fetch system usage: {error}") + return {} + + +def run_monitoring() -> None: + cpu_limit = get_threshold("Enter CPU threshold : ") + memory_limit = get_threshold("Enter Memory threshold : ") + disk_limit = get_threshold("Enter Disk threshold : ") + + if None in (cpu_limit, memory_limit, disk_limit): + print("Invalid input detected. Returning to menu.\n") + return + + print("\nChecking system usage...\n") + + usage_data = get_system_usage() + if not usage_data: + print("No system data available. Returning to menu.\n") + return + + check_resource_usage("CPU", usage_data["CPU"], cpu_limit) + check_resource_usage("Memory", usage_data["Memory"], memory_limit) + check_resource_usage("Disk", usage_data["Disk"], disk_limit) + print() + + +def main() -> None: + while True: + print("1. Enter thresholds") + print("2. Exit") + + choice = input("Select an option (1 or 2): ").strip() + + if choice == "1": + run_monitoring() + elif choice == "2": + print("Exiting program") + break + else: + print("[ERROR] Invalid choice. Please select 1 or 2.\n") + + +if __name__ == "__main__": + main() From 722734473d8069211cdaf5045bf55499d188bb96 Mon Sep 17 00:00:00 2001 From: kshitij Date: Mon, 26 Jan 2026 15:14:08 +0530 Subject: [PATCH 4/6] Day-04 Task Completed --- day-04/app.log | 30 ++++----- day-04/log_analyzer.py | 86 ++++++++++++++++++++++++++ day-04/log_summary_20260126_150959.txt | 5 ++ 3 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 day-04/log_analyzer.py create mode 100644 day-04/log_summary_20260126_150959.txt diff --git a/day-04/app.log b/day-04/app.log index 056314a..c4ca144 100644 --- a/day-04/app.log +++ b/day-04/app.log @@ -1,21 +1,21 @@ -2025-01-10 09:00:01 INFO Application started successfully -2025-01-10 09:00:05 INFO Connecting to database -2025-01-10 09:00:07 INFO Database connection established +2026-01-26 10:00:01 INFO Application started successfully +2026-01-26 10:01:15 INFO Connecting to database +2026-01-26 10:02:30 INFO Database connection established -2025-01-10 09:05:12 WARNING High memory usage detected -2025-01-10 09:05:15 INFO Memory usage back to normal +2026-01-26 10:03:12 WARNING High memory usage detected +2026-01-10 09:05:15 INFO Memory usage back to normal -2025-01-10 09:10:22 ERROR Failed to fetch user data -2025-01-10 09:10:25 ERROR Database timeout occurred +2026-01-26 10:04:05 ERROR Failed to fetch user data +2026-01-26 10:05:20 ERROR Database timeout occurred -2025-01-10 09:15:30 INFO Retrying database connection -2025-01-10 09:15:32 INFO Database connection successful +2026-01-26 10:06:05 INFO Retrying database connection +2026-01-26 10:07:20 INFO Database connection successful -2025-01-10 09:20:45 WARNING Disk usage above 75% -2025-01-10 09:20:50 INFO Disk cleanup initiated +2026-01-26 10:08:05 WARNING Disk usage above 75% +2026-01-26 10:09:20 INFO Disk cleanup initiated -2025-01-10 09:25:10 ERROR Unable to write logs to disk -2025-01-10 09:25:15 INFO Log rotation completed +2026-01-26 10:10:05 ERROR Unable to write logs to disk +2026-01-26 10:11:20 INFO Log rotation completed -2025-01-10 09:30:00 INFO Application shutdown initiated -2025-01-10 09:30:05 INFO Application stopped +2026-01-26 10:12:05 INFO Application shutdown initiated +2026-01-26 10:13:20 INFO Application stopped diff --git a/day-04/log_analyzer.py b/day-04/log_analyzer.py new file mode 100644 index 0000000..983ef4e --- /dev/null +++ b/day-04/log_analyzer.py @@ -0,0 +1,86 @@ +#pyscipt to analyze logs using python +import json +from datetime import datetime +from typing import Dict, List + + +def read_log_file(file_path: str) -> List[str]: + try: + with open(file_path, "r") as f: + return f.readlines() + except FileNotFoundError: + print(f"[ERROR] File '{file_path}' not found.") + return [] + except Exception as e: + print(f"[ERROR] Could not read file: {e}") + return [] + + +def analyze_logs(lines: List[str]) -> Dict[str, int]: + """Count INFO, WARNING, and ERROR messages.""" + counts = {"INFO": 0, "WARNING": 0, "ERROR": 0} + for line in lines: + line = line.strip() + for level in counts: + if f" {level} " in line: + counts[level] += 1 + break + return counts + + +def save_summary_txt(counts: Dict[str, int], file_path: str) -> None: + """Save log summary to a TXT file.""" + try: + with open(file_path, "w") as f: + f.write("=== Log Summary ===\n") + for level, count in counts.items(): + f.write(f"{level}: {count}\n") + f.write("==================\n") + print(f"[INFO] Summary saved to '{file_path}'") + except Exception as e: + print(f"[ERROR] Could not write TXT summary: {e}") + + + +def display_summary(counts: Dict[str, int], lines: List[str], show_errors: int = 5) -> None: + print("\n=== Log Summary ===") + for level, count in counts.items(): + print(f"{level}: {count}") + error_lines = [line for line in lines if " ERROR " in line] + if error_lines: + print(f"\nFirst {min(show_errors, len(error_lines))} ERROR messages:") + for line in error_lines[:show_errors]: + print(f"- {line.strip()}") + print("==================\n") + + +def main() -> None: + while True: + print("1. Analyze log file") + print("2. Exit") + choice = input("Select an option (1 or 2): ").strip() + + if choice == "1": + file_path = input("Enter path to log file: ").strip() + lines = read_log_file(file_path) + if not lines: + continue + counts = analyze_logs(lines) + display_summary(counts, lines) + + # Save output files with timestamp + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + txt_file = f"log_summary_{timestamp}.txt" + json_file = f"log_summary_{timestamp}.json" + save_summary_txt(counts, txt_file) + # save_summary_json(counts, json_file) + + elif choice == "2": + print("Exiting log analysis program.") + break + else: + print("[ERROR] Invalid choice. Please select 1 or 2.\n") + + +if __name__ == "__main__": + main() diff --git a/day-04/log_summary_20260126_150959.txt b/day-04/log_summary_20260126_150959.txt new file mode 100644 index 0000000..e01ad70 --- /dev/null +++ b/day-04/log_summary_20260126_150959.txt @@ -0,0 +1,5 @@ +=== Log Summary === +INFO: 10 +WARNING: 2 +ERROR: 3 +================== From 9bcfd7a4427e7f4abdb12255417dd4d39068ffa7 Mon Sep 17 00:00:00 2001 From: kshitij Date: Mon, 26 Jan 2026 15:38:06 +0530 Subject: [PATCH 5/6] Day-05 Task Completed --- day-05/app.log | 30 ++++----- day-05/log_analyzer_oop.py | 84 ++++++++++++++++++++++++++ day-05/log_summary_20260126_153423.txt | 5 ++ 3 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 day-05/log_analyzer_oop.py create mode 100644 day-05/log_summary_20260126_153423.txt diff --git a/day-05/app.log b/day-05/app.log index 056314a..c4ca144 100644 --- a/day-05/app.log +++ b/day-05/app.log @@ -1,21 +1,21 @@ -2025-01-10 09:00:01 INFO Application started successfully -2025-01-10 09:00:05 INFO Connecting to database -2025-01-10 09:00:07 INFO Database connection established +2026-01-26 10:00:01 INFO Application started successfully +2026-01-26 10:01:15 INFO Connecting to database +2026-01-26 10:02:30 INFO Database connection established -2025-01-10 09:05:12 WARNING High memory usage detected -2025-01-10 09:05:15 INFO Memory usage back to normal +2026-01-26 10:03:12 WARNING High memory usage detected +2026-01-10 09:05:15 INFO Memory usage back to normal -2025-01-10 09:10:22 ERROR Failed to fetch user data -2025-01-10 09:10:25 ERROR Database timeout occurred +2026-01-26 10:04:05 ERROR Failed to fetch user data +2026-01-26 10:05:20 ERROR Database timeout occurred -2025-01-10 09:15:30 INFO Retrying database connection -2025-01-10 09:15:32 INFO Database connection successful +2026-01-26 10:06:05 INFO Retrying database connection +2026-01-26 10:07:20 INFO Database connection successful -2025-01-10 09:20:45 WARNING Disk usage above 75% -2025-01-10 09:20:50 INFO Disk cleanup initiated +2026-01-26 10:08:05 WARNING Disk usage above 75% +2026-01-26 10:09:20 INFO Disk cleanup initiated -2025-01-10 09:25:10 ERROR Unable to write logs to disk -2025-01-10 09:25:15 INFO Log rotation completed +2026-01-26 10:10:05 ERROR Unable to write logs to disk +2026-01-26 10:11:20 INFO Log rotation completed -2025-01-10 09:30:00 INFO Application shutdown initiated -2025-01-10 09:30:05 INFO Application stopped +2026-01-26 10:12:05 INFO Application shutdown initiated +2026-01-26 10:13:20 INFO Application stopped diff --git a/day-05/log_analyzer_oop.py b/day-05/log_analyzer_oop.py new file mode 100644 index 0000000..4a49beb --- /dev/null +++ b/day-05/log_analyzer_oop.py @@ -0,0 +1,84 @@ +#pyscript A updated LogScript using a class-based[oop] approach +import json +from datetime import datetime +from typing import List, Dict + +class LogAnalyzer: + def __init__(self, file_path: str): + self.file_path = file_path + self.lines: List[str] = [] + self.counts: Dict[str, int] = {"INFO": 0, "WARNING": 0, "ERROR": 0} + + def read_file(self) -> bool: + try: + with open(self.file_path, "r") as f: + self.lines = f.readlines() + return True + except FileNotFoundError: + print(f"[ERROR] File '{self.file_path}' not found.") + return False + except Exception as e: + print(f"[ERROR] Could not read file: {e}") + return False + + def analyze_logs(self): + self.counts = {"INFO": 0, "WARNING": 0, "ERROR": 0} + for line in self.lines: + line = line.strip() + for level in self.counts: + if f" {level} " in line: + self.counts[level] += 1 + break + + def display_summary(self, show_errors: int = 5): + print("\n=== Log Summary ===") + for level, count in self.counts.items(): + print(f"{level}: {count}") + + error_lines = [line for line in self.lines if " ERROR " in line] + if error_lines: + print(f"\nFirst {min(show_errors, len(error_lines))} ERROR messages:") + for line in error_lines[:show_errors]: + print(f"- {line.strip()}") + print("==================\n") + + def save_summary_txt(self): + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + file_name = f"log_summary_{timestamp}.txt" + try: + with open(file_name, "w") as f: + f.write("=== Log Summary ===\n") + for level, count in self.counts.items(): + f.write(f"{level}: {count}\n") + f.write("==================\n") + print(f"[INFO] Summary saved to '{file_name}'") + except Exception as e: + print(f"[ERROR] Could not write TXT summary: {e}") + +class LogAnalyzerApp: + + def run(self): + while True: + print("1. Analyze log file") + print("2. Exit") + choice = input("Select an option (1 or 2): ").strip() + + if choice == "1": + file_path = input("Enter path to log file: ").strip() + analyzer = LogAnalyzer(file_path) + if not analyzer.read_file(): + continue + analyzer.analyze_logs() + analyzer.display_summary() + analyzer.save_summary_txt() + + elif choice == "2": + print("Exiting program.") + break + else: + print("[ERROR] Invalid choice. Please select 1 or 2.\n") + + +if __name__ == "__main__": + app = LogAnalyzerApp() + app.run() diff --git a/day-05/log_summary_20260126_153423.txt b/day-05/log_summary_20260126_153423.txt new file mode 100644 index 0000000..e01ad70 --- /dev/null +++ b/day-05/log_summary_20260126_153423.txt @@ -0,0 +1,5 @@ +=== Log Summary === +INFO: 10 +WARNING: 2 +ERROR: 3 +================== From 1c947c636c109fb45cff985cb5ad0e6095e2e925 Mon Sep 17 00:00:00 2001 From: kshitij Date: Mon, 26 Jan 2026 17:02:25 +0530 Subject: [PATCH 6/6] Day-06 Task Completed --- day-06/app.log | 21 +++++++++++ day-06/log_analyzer_cli.py | 76 ++++++++++++++++++++++++++++++++++++++ day-06/notes.txt | 4 ++ day-06/summary.txt | 3 ++ 4 files changed, 104 insertions(+) create mode 100644 day-06/app.log create mode 100644 day-06/log_analyzer_cli.py create mode 100644 day-06/notes.txt create mode 100644 day-06/summary.txt diff --git a/day-06/app.log b/day-06/app.log new file mode 100644 index 0000000..c4ca144 --- /dev/null +++ b/day-06/app.log @@ -0,0 +1,21 @@ +2026-01-26 10:00:01 INFO Application started successfully +2026-01-26 10:01:15 INFO Connecting to database +2026-01-26 10:02:30 INFO Database connection established + +2026-01-26 10:03:12 WARNING High memory usage detected +2026-01-10 09:05:15 INFO Memory usage back to normal + +2026-01-26 10:04:05 ERROR Failed to fetch user data +2026-01-26 10:05:20 ERROR Database timeout occurred + +2026-01-26 10:06:05 INFO Retrying database connection +2026-01-26 10:07:20 INFO Database connection successful + +2026-01-26 10:08:05 WARNING Disk usage above 75% +2026-01-26 10:09:20 INFO Disk cleanup initiated + +2026-01-26 10:10:05 ERROR Unable to write logs to disk +2026-01-26 10:11:20 INFO Log rotation completed + +2026-01-26 10:12:05 INFO Application shutdown initiated +2026-01-26 10:13:20 INFO Application stopped diff --git a/day-06/log_analyzer_cli.py b/day-06/log_analyzer_cli.py new file mode 100644 index 0000000..f7ec219 --- /dev/null +++ b/day-06/log_analyzer_cli.py @@ -0,0 +1,76 @@ +#pyscript Python script into a CLI (Command Line Interface) tool using argparse +import argparse +from datetime import datetime +from typing import List, Dict + +class LogAnalyzer: + def __init__(self, file_path: str): + self.file_path = file_path + self.lines: List[str] = [] + self.counts: Dict[str, int] = {"INFO": 0, "WARNING": 0, "ERROR": 0} + + def read_file(self) -> bool: + try: + with open(self.file_path, "r") as f: + self.lines = f.readlines() + return True + except FileNotFoundError: + print(f"[ERROR] File '{self.file_path}' not found.") + return False + except Exception as e: + print(f"[ERROR] Could not read file: {e}") + return False + + def analyze_logs(self, level_filter: str = None): + self.counts = {"INFO": 0, "WARNING": 0, "ERROR": 0} + for line in self.lines: + line = line.strip() + for level in self.counts: + if f" {level} " in line: + if level_filter is None or level == level_filter: + self.counts[level] += 1 + break + + def display_summary(self, level_filter: str = None, show_errors: int = 5): + print("\n=== Log Summary ===") + for level, count in self.counts.items(): + if level_filter is None or level == level_filter: + print(f"{level}: {count}") + + error_lines = [line for line in self.lines if " ERROR " in line] + if (level_filter is None or level_filter == "ERROR") and error_lines: + print(f"\nFirst {min(show_errors, len(error_lines))} ERROR messages:") + for line in error_lines[:show_errors]: + print(f"- {line.strip()}") + print("==================\n") + + def save_summary_txt(self, out_path: str, level_filter: str = None): + try: + with open(out_path, "w") as f: + f.write("=== Log Summary ===\n") + for level, count in self.counts.items(): + if level_filter is None or level == level_filter: + f.write(f"{level}: {count}\n") + f.write("==================\n") + print(f"[INFO] Summary saved to '{out_path}'") + except Exception as e: + print(f"[ERROR] Could not write summary: {e}") + +def main(): + parser = argparse.ArgumentParser(description="Analyze log files and generate summary") + parser.add_argument('--file', required=True, help="Path to input log file") + parser.add_argument('--out', required=True, help="Path to output summary file") + parser.add_argument('--level', help="Optional log level filter (INFO, WARNING, ERROR)") + + args = parser.parse_args() + + analyzer = LogAnalyzer(args.file) + if not analyzer.read_file(): + return + + analyzer.analyze_logs(args.level) + analyzer.display_summary(args.level) + analyzer.save_summary_txt(args.out, args.level) + +if __name__ == "__main__": + main() diff --git a/day-06/notes.txt b/day-06/notes.txt new file mode 100644 index 0000000..fe2b592 --- /dev/null +++ b/day-06/notes.txt @@ -0,0 +1,4 @@ +To Python script into a CLI (Command Line Interface) tool. + +This Command used to run the file using CLI tool +F:\Python Jan 2026\Day6> py log_analyzer_cli.py --file "F:\Python Jan 2026\Day6\app.log" --out "F:\Python Jan 2026\Day6\summary.txt" --level ERROR diff --git a/day-06/summary.txt b/day-06/summary.txt new file mode 100644 index 0000000..c908e40 --- /dev/null +++ b/day-06/summary.txt @@ -0,0 +1,3 @@ +=== Log Summary === +ERROR: 3 +==================