OPS435 Assignment 1 A

From CDOT Wiki
Revision as of 09:59, 15 February 2018 by Rchan (talk | contribs) (Monthly Usage Report by User)
Jump to: navigation, search

DRAFT - Under Construction

Assignment 1 - Usage Report

Weight: 20% of the overall grade

Due Date: Ask your professor for exact date

Late Penalty: 10% per school day, and note that this assignment must be completed satisfactorily in order to pass the course even if you get zero mark for this assignment.

Overview

Most system administrators would like to know the utilization of their systems by their users. On a Linux system, each user's login records are normally stored in the binary file /var/log/wtmp. The login record in this binary file can not be viewed or edited directly using normal Linux text commands like 'less', 'cat', etc. The 'last' command is often used to display the login records stored in this file in a human readable form. The following listing is a sample output the 'last' command:

$ last -F
avhuo    pts/9        10.43.222.35     Tue Feb 13 16:53:42 2018 - Tue Feb 13 16:57:02 2018  (00:03)    
clee18   pts/6        10.40.43.94      Tue Feb 13 16:51:47 2018 - Tue Feb 13 16:56:13 2018  (00:04)    
clee18   pts/6        10.40.43.94      Tue Feb 13 16:50:20 2018 - Tue Feb 13 16:51:27 2018  (00:01)    
shana    pts/2        toroon4512w-lp13 Tue Feb 13 16:47:48 2018 - Tue Feb 13 16:58:31 2018  (00:10)    
hfang171 pts/4        24.114.50.50     Tue Feb 13 16:31:38 2018 - Tue Feb 13 17:48:39 2018  (01:17)    
bigia    pts/8        10.247.6.126     Tue Feb 13 16:28:43 2018 - Tue Feb 13 17:28:31 2018  (00:59)    
ckim16   pts/2        10.40.91.236     Tue Feb 13 16:22:36 2018 - Tue Feb 13 16:45:10 2018  (00:22)    
ddchan   pts/2        10.43.115.162    Tue Feb 13 16:19:29 2018 - Tue Feb 13 16:22:00 2018  (00:02)    
tsliu2   pts/4        10.40.105.130    Tue Feb 13 16:17:21 2018 - Tue Feb 13 16:30:10 2018  (00:12)    
shana    pts/13       10.40.91.247     Tue Feb 13 16:07:52 2018 - Tue Feb 13 16:45:52 2018  (00:38)    
tchiu2   pts/11       10.40.105.130    Tue Feb 13 16:07:43 2018 - Tue Feb 13 16:17:12 2018  (00:09)    
   
...

In this assignment, your task is to create a python program with well designed functions to produce daily, weekly, and monthly usage reports by user or by remote host based on the information obtained from the 'last' command.

Instructions

Program Name and valid command line arguments

Name your Python3 program as usage_report.py. The program should accept zero or more "file name" as as its command line parameters. for examples:

  • python3 usage_report.py, or
  • python3 usage_report.py filename, or
  • python3 usage_report.py filename1 filename2 etc ... - any number of filenames from 1 to as many as the command-line supports.

If there is no command line argument, your python program should get the login records from the 'last' command with the appropriate flags.

If there is one filename provided at the command line, gets the login records from the contents of the given file. The format of each line in the file should be the same as the output of 'last -F'.

If there is more than one filename provided, merges all the files together with the first one at the top and the last one at the bottom. Read and process the file contents in that order in your program.

Header

All your Python codes for this program must be placed in a single source file. Please include the following declaration by you as comment in your Python source code file (replace "Student Name" with your own name):

OPS435 Assignment 1 - Winter 2018
Program: usage_report.py
Author: "Student Name"
The python code in this file (usage_report.py) is original work written by
"Student Name". No code in this file is copied from any other source 
including any person, textbook, or on-line resource. I have not shared
this python program with anyone or anything except for submission for grading.  
I understand that the Academic Honesty Policy will be enforced and violators 
will be reported and appropriate action will be taken.

Main Menu

When your Python program is running, it should present the user with the following menus:

Reading login records... Done.

Usage Report - Main Menu
========================
d) Daily Usage Report
w) Weekly Usage Report
m) Monthly Usage Report
q) Quit

Option d, w, and m when selected will display a new sub-menu.

When option q is selected, you program should terminate.

Daily Usage Menu

  • If the Daily Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Daily Usage Report Menu
=======================
u) By User
h) By Remote Host
r) Return to Main Menu

When option u is selected, the sub-menu for Daily Usage Report by User should be displayed.

When option h is selected, the sub-menu for Daily Usage Report by Remote Host should be displayed.

When option r is selected, the main menu should be displayed.

Daily Usage Report by User

Daily Usage Report - by User
============================
List of valid users:
user1 user2 user3 user4 ...
...
r) Return to Daily Usage Report Menu

Valid user is regular user (super user and system users should not be included) who are allowed to login to the system.

When option r is selected, the Daily Usage Report menu should be displayed.

When a valid user is selected, the Daily Usage Report for the selected user should be generated. The following is a sample Daily Usage Report for user1 on host.cty.senecacollege.ca:

Daily Usage Report for user1 on host.cty.senecacollege.ca
=========================================================
Date          Usage in Minutes
2018-02-14          60
2018-02-07          45
2018-02-01           5

Total              110

Daily Usage Report by Remote Host

Daily Usage Report - by Remote Host
===================================
Valid Remote Host:
10.94.10.25
10.94.10.120
172.16.99.1
192.168.45.3
...
r) Return to Daily Usage Report Menu

Valid Remote Host is any host that any valid user used to login to the system.

When option r is selected, the Daily Usage Report menu should be displayed.

When a valid Remote Host is selected, the Daily Usage Report for the selected Remote Host should be generated. The following is a sample Daily Usage Report from Remote Host 10.94.10.25 on host.cty.senecacollege.ca:

Daily Usage Report from 10.94.10.25 on host.cty.senecacollege.ca
================================================================
Date          Usage in Minutes
2018-02-14          30
2018-02-07          41
2018-02-01           9

Total               80

Weekly Usage Menu

  • If the Weekly Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Weekly Usage Report Menu
========================
u) By User
h) By Remote Host
r) Return to Main Menu

When option u is selected, the sub-menu for Weekly Usage Report by User should be displayed.

When option h is selected, the sub-menu for Weekly Usage Report by Remote Host should be displayed.

When option r is selected, the main menu should be displayed.

Weekly Usage Report by User

Weekly Usage Report - by User
=============================
Valid Users:
User1 User2 User3 ...
...
r) Return to Weekly Usage Report Menu

When option r is selected, the Weekly Usage Report menu should be displayed.

When a valid user is selected, the Weekly Usage Report for the selected user should be generated from week 1 to week 52, if the weekly usage is zero, skips the week. The following is a sample Weekly Usage Report for user1 on host.cty.senecacollege.ca:

Weekly Usage Report for user1 on host.cty.senecacollege.ca
=========================================================
Week #         Usage in Minutes
1                  160
2                   45
3                    5
4                   20

Total              220

Weekly Usage Report by Remote Host

Weekly Usage Report - by Remote Host
===================================
Valid Remote Hosts:
10.94.10.25
10.94.10.120
172.16.99.1
192.168.45.3
...
r) Return to Weekly Usage Report Menu

When option r is selected, the Weekly Usage Report menu should be displayed.

When a valid Remote Host is selected, the Weekly Usage Report for the selected Remote Host should be generated from week 1 to week 52, if the weekly usage is zero, skips the week. The following is a sample Weekly Usage Report from the remote host 10.94.10.25 on host.cty.senecacollege.ca:

Daily Usage Report from 10.94.10.25 on host.cty.senecacollege.ca
================================================================
Week #     Usage in Minutes
1                30
3                41
5                 9
6                11

Total            91

Monthly Usage Menu

  • If the Monthly Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Monthly Usage Report Menu
=========================
u) By User
h) By Remote Host
r) Return to Main Menu

When option u is selected, the sub-menu for Monthly Usage Report by User should be displayed.

When option h is selected, the sub-menu for Monthly Usage Report by Remote Host should be displayed.

When option r is selected, the main menu should be displayed.

Monthly Usage Report by User

Monthly Usage Report - by User
==============================
Valid Users:
User1 User2 User3 ...
...
r) Return to Monthly Usage Report Menu

When option r is selected, the Monthly Usage Report menu should be displayed.

When a valid user is selected, the Monthly Usage Report for the selected user should be generated for Jan to Dec. It the usage of a given month is zero, skips that month. The following is a sample Monthly Usage Report for user1 on host.cty.senecacollege.ca:

Monthly Usage Report for user1 on host.cty.senecacollege.ca
=========================================================
Month         Usage in Minutes
January            160
February            45

Total              205

Monthly Usage Report by Remote Host

Monthly Usage Report - by Remote Host
=====================================
Valid Remote Hosts:
10.94.10.25
10.94.10.120
172.16.99.1
192.168.45.3
...
r) Return to Monthly Usage Report Menu

When option r is selected, the Monthly Usage Report menu should be displayed.

When a valid Remote Host is selected, the Monthly Usage Report for the selected Remote Host should be generated for Jan to Dec. It the usage of a given month is zero, skips that month. The following is a sample Monthly Usage Report for 10.94.10.25 on host.cty.senecacollege.ca:

Monthly Usage Report from 10.94.10.25 on host.cty.senecacollege.ca
================================================================
Week #     Usage in Minutes
January          30
February         41

Total            71

Sample login records file

Submission

After fully testing your program, submit the .py file on Blackboard