OPS445 Assignment 1 Part 1: Difference between revisions

From Littlesvr Wiki
Jump to navigation Jump to search
(Created page with "= Assignment 1 - Parsing a log file = = Part 1 - Menu = '''Weight''': 10% of the overall grade. '''Due Date''': Ask your professor for exact date. '''Late penalty''': 10% per day, and note the assignment must be completed satisfactorily in order to pass the course no matter what grade you get. == Overview == Often, system administrators need to analyze log files. This can be done using a paginator such as <code>less</code> when your system has just been set up and/...")
 
Line 43: Line 43:
If there are no arguments - you should print an error and exit.
If there are no arguments - you should print an error and exit.


If there are other arguments - assume that they are names of files containing apache logs. If there is more than one file - append their contents to each other with the first one at the top and the last one at the bottom. Read the file contents in that order into your own data structures.
If there are other arguments - assume that they are names of files containing apache logs. You don't need to read the files for this part of the assignment, but you do need to create a list with all the filenames and call a function <code>load_logs()</code>, passing it that list as an argument.
 
For this part of the assignment <code>load_logs()</code> should simply print each filename it would open and read. Only call this function once, when your program starts.


=== Main Menu ===
=== Main Menu ===
Line 71: Line 73:
1) How many total requests (Code 200)
1) How many total requests (Code 200)
2) How many requests from Seneca (IPs starting with 142.204)
2) How many requests from Seneca (IPs starting with 142.204)
3) How many requests for isomaster-1.3.13.tar.bz2
3) How many requests for OPS435_Lab
q) Return to Main Menu
q) Return to Main Menu
What would you like to do?  
What would you like to do?  
Line 84: Line 86:
Apache Log Analyser - Failed Requests Menu
Apache Log Analyser - Failed Requests Menu
==========================================
==========================================
1) How many total failed requests (Codes 404, 400, 500, 403, 405, 408, 416)
1) How many total "Not Found" requests (Code 404)
2) How many failed requests for wp-login.php
2) How many 404 requests contained "hidebots" in the URL
3) List the filenames for failed requests for files in /apng/assembler/data
3) Print all IP addresses that caused a 404 response
q) Return to Main Menu
q) Return to Main Menu
</pre>
</pre>
Line 98: Line 100:


== Rubric ==
== Rubric ==
 
{| class="wikitable"
 
|+
 
!Item
!Marks
|-
|Submitted correctly
|/2
|-
|Correct filename
|/2
|-
|Contains header comment with shebang line and name
|/2
|-
|Comments throughout code explain well enough
|/2
|-
|Runs without errors
|/2
|-
|Detailed print statement for usage and problems (usage: ....)
|/2
|-
|Arguments -d and --default show correct output
|/2
|-
|Handles multiple filename arguments correctly
|/2
|-
|Menu navigation
|/4
|-
|Late deduction
|
|-
|Total
|/20
|}
[[Category:OPS445]]
[[Category:OPS445]]

Revision as of 08:16, 9 February 2025

Assignment 1 - Parsing a log file

Part 1 - Menu

Weight: 10% of the overall grade.

Due Date: Ask your professor for exact date.

Late penalty: 10% per day, and note the assignment must be completed satisfactorily in order to pass the course no matter what grade you get.

Overview

Often, system administrators need to analyze log files. This can be done using a paginator such as less when your system has just been set up and/or you're the only user. On a production system it is not unusual to have thousands of legitimate users per month accessing the server's services, plus thousands more bots looking for unpatched vulnerabilities, brute-forcing username/password pairs, or just downloading every available file on your web server.

In this assignment you will create a program that will help you as a Apache server administrator to answer questions about the status, load, and security of your web server. You will not need to set up a web server for this assignment, though you're welcome to use a real web server if you have one.

In this first part of the assignment you will implement the menu navigation.

Requirements

  • You may use any coding style you choose - but make sure it is consistent throughout the program. Coding style is important - not least because I have to read it. "Style" includes adding a comment at the top of every function explaining what it does. You won't lose marks for too many comments, you will lose marks for too few.
  • If your assignemnt doesn't work or has major problems - you will be asked to resubmit it, which will likely cost you more than a late penalty.

Header

Your program must be a single source file named check_apache_log_yourmysenecaid.py, and at the top of that file it will contain the following comment:

# OPS435 Assignment 1
# check_apache_log_yourmysenecaid.py
# Author: Your Name

Name and Parameters

Your Python3 program will be named check_apache_log_yourmysenecaid.py and it will accept the following parameters:

  • --default or -d as an optional first argument, followed by:
  • filename, or:
  • filename1 filename2 filename3 etc... - any number of filenames from 1 to as many as the command-line supports.

If the first argument is --default or -d, then you should not print a menu and instead execute the "How many total requests (Code 200)".

If there are no arguments - you should print an error and exit.

If there are other arguments - assume that they are names of files containing apache logs. You don't need to read the files for this part of the assignment, but you do need to create a list with all the filenames and call a function load_logs(), passing it that list as an argument.

For this part of the assignment load_logs() should simply print each filename it would open and read. Only call this function once, when your program starts.

Main Menu

Your program will be primarily menu-based instead of parameter-driven. That means the user will ask the program to do something after the program is already running, which is different from a typical command-line tool. When the program starts, it will present the user will the following menu:

Apache Log Analyser - Main Menu
===============================
1) Successful Requests
2) Failed Requests
q) Quit
What would you like to do? 

Make sure the line of equal signs is not hard-coded. You must be able to quickly change the title and not have to update a string with some number of extra or fewer equal signs. You might want to make a function to display this line, and use that function for the other menus as well.

Both option 1 and 2 will display a new menu.

the q option is self-explanatory.

Successful requests menu

Apache Log Analyser - Successful Requests Menu
==============================================
1) How many total requests (Code 200)
2) How many requests from Seneca (IPs starting with 142.204)
3) How many requests for OPS435_Lab
q) Return to Main Menu
What would you like to do? 
  • For options 1, 2, and 3: you should call an appropriately named function. For this part of the assignment the function can just print "Not implemented yet".
  • For option q: the program will return to the main menu, and continue appropriately.

Failed requests menu

Apache Log Analyser - Failed Requests Menu
==========================================
1) How many total "Not Found" requests (Code 404)
2) How many 404 requests contained "hidebots" in the URL
3) Print all IP addresses that caused a 404 response
q) Return to Main Menu
  • For options 1, 2, and 3: you should call an appropriately named function. For this part of the assignment the function can just print "Not implemented yet".
  • For option q: the program will return to the main menu, and continue appropriately.

Submission

After testing your program - submit the check_apache_log_yourmysenecaid.py file via Blackboard. Don't submit another document, nor a screenshot, nor an archive.

Rubric

Item Marks
Submitted correctly /2
Correct filename /2
Contains header comment with shebang line and name /2
Comments throughout code explain well enough /2
Runs without errors /2
Detailed print statement for usage and problems (usage: ....) /2
Arguments -d and --default show correct output /2
Handles multiple filename arguments correctly /2
Menu navigation /4
Late deduction
Total /20