Changes

Jump to: navigation, search

OPS435 Assignment 1 A

2,289 bytes removed, 07:46, 7 June 2018
Header
[[Category:OPS435-Python]][[Category:rchan]]
<font color='red'>'''DRAFT - Under Construction'''</font>
=Assignment 1 - Usage Report=
'''Weight:''' 15% of the overall grade
In this assignment, your task is to create a python program to produce daily, weekly, and monthly usage reports by user or by remote host based on the information obtained from the 'last' command or given files which contain similar information as the 'last' command.
== Resource for useful modules ==
* the <b>argparse</b> module
** [https://docs.python.org/3/howto/argparse.html Argparse Tutorial] - should read this first.
** [https://docs.python.org/3/library/argparse.html Argparse API reference information page]
* the <b>time</b> module
** [https://www.tutorialspoint.com/python3/python_date_time.htm Time module Tutorial]
** [https://docs.python.org/3/library/time.html Time module API reference page]
== Instructions ==
=== Program Name and valid command line arguments ===
Name your Python3 program as <code>usage_reportur.py</code>. The program should accept zero one or more "file name" as its command line parametersand other optional parameters as shown below. for examplesYour ur.py script should produce the following usage when run with the --help option:* <b><codepre>[rchan@centos7 a1]$ python3 usage_report./ur.py</code></b>, or-h* <b><code>python3 usage_reportusage: ur.py filename</code></b>[-h] [-l {user,host}] [-r RHOST] [-t {daily,weekly, ormonthly}] [-u USER] [-v]* <b><code>python3 usage_report.py filename1 filename2 </code></b> etc . F [F .. - any number of file names from 1 to as many as the command-line supports.]
Usage Report based on the last command positional arguments: F list of files to be processed optional arguments: -h, --help show this help message and exit -l {user,host}, --list {user,host} generate user name or remote host IP from the given files -r RHOST, --rhost RHOST usage report for the given remote host IP -t {daily,weekly,monthly}, --type {daily,weekly,monthly} type of report: daily, weekly, and monthly -u USER, --user USER usage report for the given user name -v, --verbose tune on output verbosity Copyright 2018 - Raymond Chan </pre>Replace the last line with your own full name   If there one of the file name given is no command line argument"last", your python program should get the login records from the 'last' command with the appropriate flags.
If there is one file name provided at the command line, read 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 -Fiw'.
=== Header ===
All your Python codes for this program must be placed in a <font color='red'><b><u>single source file</u></b></font>. Please include the following declaration by <b><u><you</u></b> as comment in your Python source code file (replace "Student Name" with your own name):
<source>OPS435 Assignment 1 - Winter Summer 2018Program: usage_reportur.py
Author: "Student Name"
The python code in this file (usage_reportur.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
</source>
=== Main Menu ===
When your Python program is running, it should present the user with the following menus:
 
<source>Reading login records... Done.
 
Usage Report - Main Menu
========================
d) Daily Usage Report
w) Weekly Usage Report
m) Monthly Usage Report
q) Quit
</source>
 
Option <b>d</b>, <b>w</b>, and <b>m</b> when selected will display a new sub-menu.
 
When option <b>q</b> 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:
 
<source>
Daily Usage Report Menu
=======================
u) By User
h) By Remote Host
r) Return to Main Menu
</source>
 
When option <b>u</b> is selected, the sub-menu for Daily Usage Report by User should be displayed.
 
When option <b>h</b> is selected, the sub-menu for Daily Usage Report by Remote Host should be displayed.
 
When option <b>r</b> is selected, the main menu should be displayed.
==== Daily Usage Report by User ====
The following is a sample Daily Usage Report for user1 on host.cty.senecacollege.ca:<sourcepre>Daily Usage Report - by Userfor user1
============================
List of valid users:user1 user2 user3 user4 ......r) Return to Daily Usage Report Menu</source> <b>Valid user</b> is regular user (super user and system users should not be included) who are allowed to login to the system.  When option <b>r</b> is selected, the Daily Usage Report menu should be displayed. When a <b>valid user</b> 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:<pre>Daily Usage Report for user1 on host.cty.senecacollege.ca=========================================================Date Usage in Minutesseconds2018-02-14 602018-02-07 452018-02-01 5
Total 110
==== Daily Usage Report by Remote Host====
<source>Daily Usage Report - by Remote Host===================================Valid Remote Host:10.94.10.2510.94.10.120172.16.99.1192.168.45.3...r) Return to Daily Usage Report Menu</source> <b>Valid Remote Host</b> is any host that any <b>valid user</b> used to login to the system. When option <b>r</b> is selected, the Daily Usage Report menu should be displayed. When a <b>valid Remote Host</b> 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:
<pre>
Daily Usage Report from 10.94.10.25 on host.cty.senecacollege.ca================================================================Date Usage in Minutesseconds2018-02-14 302018-02-07 412018-02-01 9
Total 80
</pre>
 
=== 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:
 
<source>
Weekly Usage Report Menu
========================
u) By User
h) By Remote Host
r) Return to Main Menu
</source>
 
When option <b>u</b> is selected, the sub-menu for Weekly Usage Report by User should be displayed.
 
When option <b>h</b> is selected, the sub-menu for Weekly Usage Report by Remote Host should be displayed.
 
When option <b>r</b> is selected, the main menu should be displayed.
==== Weekly Usage Report by User ====
<source>
Weekly Usage Report - by User
=============================
Valid Users:
User1 User2 User3 ...
...
r) Return to Weekly Usage Report Menu
</source>
 
When option <b>r</b> is selected, the Weekly Usage Report menu should be displayed.
 
When a <b>valid user</b> 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:
<pre>
Weekly Usage Report for user1 on host.cty.senecacollege.ca=========================================================Week # Usage in MinutesSeconds1 2017 01 1602 2017 02 453 2017 03 54 2017 04 20
Total 220
==== Weekly Usage Report by Remote Host ====
<source>
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
</source>
 
When option <b>r</b> is selected, the Weekly Usage Report menu should be displayed.
 
When a <b>valid Remote Host</b> 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:
<pre>
Daily Weekly Usage Report from 10.94.10.25 on host.cty.senecacollege.ca================================================================Week # Usage in MinutesSeconds1 2017 01 303 2017 03 415 2017 05 96 2017 06 11
Total 91
</pre>
 
=== 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:
 
<source>
Monthly Usage Report Menu
=========================
u) By User
h) By Remote Host
r) Return to Main Menu
</source>
 
When option <b>u</b> is selected, the sub-menu for Monthly Usage Report by User should be displayed.
 
When option <b>h</b> is selected, the sub-menu for Monthly Usage Report by Remote Host should be displayed.
 
When option <b>r</b> is selected, the main menu should be displayed.
==== Monthly Usage Report by User ====
The following is a sample Monthly Usage Report for user1 on host.cty.senecacollege.ca:<sourcepre>Monthly Usage Report - by Userfor user1
==============================
Valid Users:Month Usage in SecondsUser1 User2 User3 ...2017 01 160...2017 02 45r) Return to Monthly Usage Report MenuTotal 205</sourcepre>
When option <b>r</b> ==== Monthly Usage Report by Remote Host ====The following is selected, the a sample Monthly Usage Report menu should be displayedfor 10.94.10.25 on host.cty.senecacollege.ca:
When a <b>valid user</b> 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:
<pre>
Monthly Usage Report for user1 on hostfrom 10.cty94.senecacollege10.ca25===========================================================Month Usage in MinutesSecondsJanuary 1602017 01 30February 452017 02 41
Total 205 71
</pre>
==== Monthly Usage Report by Remote Host ==Program Development and Testing ==<source>Monthly Usage Report You should create python functions to handle the following sub- by Remote Hosttasks:=====================================* gets login records from the output of "last" command and filters out unwanted recordsValid Remote Hosts:* reads login records from files and filters out unwanted records10.94.10.25* generate daily usage reports by user or by remote host10.94.10.120* generate weekly usage reports by user or by remote host172.16.99.1* generate monthly usage reports by user or by remote host192To help you with this assignment, [[OPS435 A1 Usage Report Template|here is a template]] you can use as a starting point in developing your Python Usage Report program.168.45.3...r) Return Once you have finished coding a function, you should start a Python3 interactive shell, import your functions and manually call the function you want to Monthly Usage Report Menu</source>test.
When option <b>r</b> Once you have all the individual function tested and that each is selectedworking properly, perform the final test with test data provided by your professor and verify that your program produces the Monthly Usage Report menu should be displayedcorrect results before submitting your python program on Blackboard.
When a <b>valid Remote Host<== Sample login records file and sample run ==* [https://b> 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.94scs.10senecac.25 on host.ctyca/~raymond.senecacollege.ca:chan/ops435/a1/ Sample test date files and sample runs]
<pre>Monthly Usage Report from 10.94.10.25 on host.cty.senecacollege.ca==Rubric ==============================================================Week # Usage in MinutesJanuary 30February 41
{| class="wikitable" border="1"! Task !! Maximum mark !! Actual mark|-| Program Authorship Declaration ||1 |||-| Program usage || 2 |||-| Program Options || 2 |||-| Daily Usage Report by User || 2 |||-| Daily Usage Report by Remote Host || 2 |||-| Weekly Usage Report by User || 2 |||-| Weekly Usage Report by Remote Host || 2 |||-| Monthly Usage Report by User || 2 |||-| Monthly Usage Report by Remote Host || 2 |||-| Get Login Records from 'last' || 2 |||-| Get Login Records from files || 2 |||-| Generate user name list || 2 |||-| Generate remote host IP list|| 2 || |-| '''Total 71</pre>''' || 25 ||
== Sample login records file ==* Will be provide on Feb 22, 2018|}
== Submission ==
After fully testing your program, submit the your ur.py file on Blackboard
1,760
edits

Navigation menu