Changes

Jump to: navigation, search

OPS435 Assignment 1 A

5,210 bytes removed, 07:46, 7 June 2018
Header
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 ... ] 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}, -- any number type {daily,weekly,monthly} type of file names from 1 to as many as report: daily, weekly, and monthly -u USER, --user USER usage report for the commandgiven user name -v, --line supports.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'.
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 menu:
 
<source>Reading login records... Done.
 
Usage Report - Main Menu
========================
d) Daily Usage Report
w) Weekly Usage Report
m) Monthly Usage Report
q) Quit
</source>
 
Display an appropriate sub-menu when option <b>d</b>, <b>w</b>, or <b>m</b> is selected.
 
When option <b>q</b> is selected, you program should terminate.
 
Redisplay the same menu if the user entered any other letters.
 
=== 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.
 
Redisplay the same menu if the user entered any other letters.
==== Daily Usage Report by User ====
<source>
Daily Usage Report - by User
============================
0) All users
1) user1
2) user2
3) user3
...
9) user9
r) Return to Daily Usage Report Menu
</source>
 
<b>Note</b>: If there are fewer than 9 users, display only the actual number of users on the menu.
 
When option <b>r</b> is selected, the previous Daily Usage Report menu should be displayed.
 
When one of <b>0-9</b> is selected, the Daily Usage Report for the selected user(s) should be generated.
Redisplay the same menu if the user entered any other digits/letters.
 
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
===================================
0) All Remote Host
1) 10.94.10.25
2) 10.94.10.120
3) 172.16.99.1
...
9) 192.168.45.3
r) Return to Daily Usage Report Menu
</source>
 
<b>Note</b>: If there are fewer than 9 remote hosts, display only the actual number of remote host on the menu.
 
When option <b>r</b> is selected, the previous Daily Usage Report menu should be displayed.
 
When one of <b>0-9</b> is selected, the Daily Usage Report for the selected Remote Host(s) should be generated.
 
Redisplay the same menu if the user entered any other digits/letters.
 
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
=============================
0) All Users
1) User1
2) User2
3) User3
...
9) User9
r) Return to Weekly Usage Report Menu
</source>
 
<b>Note</b>: If there are fewer than 9 users, display only the actual number of user on the menu.
 
When option <b>r</b> is selected, the previous Weekly Usage Report menu should be displayed.
 
When one of <b>0-9</b> is selected, the Weekly Usage Report for the selected user(s) should be generated from week 1 to week 52, skips the week where the weekly usage is zero.
 
Redisplay the same menu if the user entered any other digits/letters.
 
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
===================================
0) All Remote Hosts
1) 10.94.10.25
2) 10.94.10.120
3) 172.16.99.1
...
9) 192.168.45.3
r) Return to Weekly Usage Report Menu
</source>
 
<b>Note</b>: If there are fewer than 9 remote hosts, display only the actual number of remote host on the menu.
 
When option <b>r</b> is selected, the previous Weekly Usage Report menu should be displayed.
 
When one of <b>0-9</b> is selected, the Weekly Usage Report for the selected Remote Host(s) should be generated from week 1 to week 52, skip the week where the weekly usage is zero.
 
Redisplay the same menu if the user entered any other digits/letters.
 
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 ====
<source>
Monthly Usage Report - by User
==============================
0) All Users
1) User1
2) User2
3) User3
...
9) User 9
r) Return to Monthly Usage Report Menu
</source>
 
<b>Note</b>: If there are fewer than 9 users, display only the actual number of user on the menu.
 
When option <b>r</b> is selected, the previous Monthly Usage Report menu should be displayed.
 
When one of <b>0-9</b> is selected, the Monthly Usage Report for the selected user(s) should be generated for Jan to Dec. Skips the month where the Monthly Usage is zero.
 
Redisplay the same menu if the user entered any other digits/letters.
 
The following is a sample Monthly Usage Report for user1 on host.cty.senecacollege.ca:
<pre>
Monthly Usage Report for user1 on host.cty.senecacollege.ca===========================================================Month Usage in MinutesSecondsJanuary 2017 01 160February 2017 02 45
Total 205
==== Monthly Usage Report by Remote Host ====
<source>
Monthly Usage Report - by Remote Host
=====================================
0) All Remote Hosts
1) 10.94.10.25
2) 10.94.10.120
3) 172.16.99.1
...
9) 192.168.45.3
r) Return to Monthly Usage Report Menu
</source>
 
<b>Note</b>: If there are fewer than 9 remote hosts, display only the actual number of remote host on the menu.
 
When option <b>r</b> is selected, the previous Monthly Usage Report menu should be displayed.
 
When one of <b>0-9</b> is selected, the Monthly Usage Report for the selected Remote Host(s) should be generated for Jan to Dec. Skips that month where the Monthly Usage is zero.
 
Redisplay the same menu if the user entered any other digits/letters.
 
The following is a sample Monthly Usage Report for 10.94.10.25 on host.cty.senecacollege.ca:
<pre>
Monthly Usage Report from 10.94.10.25 on host.cty.senecacollege.ca================================================================Week # Month Usage in MinutesSecondsJanuary 2017 01 30February 2017 02 41
Total 71
</pre>
== Program Development and Testing ==
You should create python functions to handle the following sub-tasks:
* displays main menu, sub-menu and get user's response via the keyboard
* gets login records from the output of "last" command and filters out unwanted records
* reads login records from files and filters out unwanted records
Once you have all the individual function tested and that each is working properly, perform the final test with test data provided by your professor and verify that your program produces the correct results before submitting your python program on Blackboard.
== Sample login records file and sample run ==* Will be provide [https://scs.senecac.on Feb 22, 2018.ca/~raymond.chan/ops435/a1/ Sample test date files and sample runs]
== Rubric ==
| Program Authorship Declaration ||1 ||
|-
| Main Menu Program usage || 2 |||-| Daily Usage Menu || 1 |||-| Daily Usage Report by User Menu || 1 |||-| Daily Usage Report by Remote Host Menu|| 1 ||
|-
| Weekly Usage Menu Program Options || 1 2 ||
|-
| Weekly Daily Usage Report by User Menu || 1 2 ||
|-
| Weekly Daily Usage Report by Remote Host Menu|| 1 2 ||
|-
| Monthly Weekly Usage Menu Report by User || 1 2 ||
|-
| Monthly Weekly Usage Report by User Menu Remote Host || 1 2 ||
|-
| Monthly Usage Report by Remote Host MenuUser || 1 2 ||
|-
| Get Login Records from 'last' Monthly Usage Report by Remote Host || 3 2 ||
|-
| Get Login Records from files 'last' || 3 2 ||
|-
| Generate Daily Usage Report Get Login Records from files || 2 ||
|-
| Generate Weekly Usage Reportuser name list || 2 ||
|-
| Generate Monthly Usage Report remote host IP list|| 2 ||
|-
| '''Total''' || 24 25 ||
|}
== Submission ==
After fully testing your program, submit the your ur.py file on Blackboard
1,760
edits

Navigation menu