Open main menu

CDOT Wiki β

Changes

OPS435 Assignment 1 A

2,329 bytes added, 07:46, 7 June 2018
Header
[[Category:OPS435-Python]][[Category:rchan]]
<font color='red'>'''DRAFT - Under Construction'''</font>=Assignment 1 - Users' Usage Report='''Weight:''' 2015% of the overall grade
'''Due Date:''' Ask your professor for exact date
==Overview==
Most system administrators would like to know the utilization of their systems by their users. On a Linux system, the userseach user' s login records are normally stored in the binary file /var/log/wtmp. The login records 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. Please check the man page of the 'last' command for available options. The following listing is a sample output of running the 'last' commandwith the '-F' flag on:
<pre>
$ last -F
</pre>
In this assignment, your task is to create a python program with well designed functions to produce daily, weekly, and monthly usage report 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. Your ur.py script should produce the following usage when run with the --help option:* <bpre><code>filename<[rchan@centos7 a1]$ python3 ./code></b>ur.py -husage: ur.py [-h] [-l {user,host}] [-r RHOST] [-t {daily,weekly, ormonthly}] [-u USER] [-v]* <b><code>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 filenames 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
If there is no command line argument, your python program should get the login records from Copyright 2018 - Raymond Chan </pre>Replace the 'last' command line with the appropriate flags.your own full name
If there is one filename provided at the command line, gets the login records from the contents of the given file. The format of the lines in the file should be the same as the output of 'last -F'.
If one of the file name given is "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'. If there is more than one filename file name 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 <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 based on the given command line arguments:
<source>Reading login records==== Daily Usage Report by User ====The following is a sample Daily Usage Report for user1 on host.cty.senecacollege. Done.ca:<pre>Daily Usage Report for user1============================Date Usage in seconds2018 02 14 602018 02 07 452018 02 01 5
Usage Report - Main Menu========================d) Daily Usage Reportw) Weekly Usage Reportm) Monthly Usage Reportq) QuitTotal 110</sourcepre>
Option <b>d</b>, <b>w</b>, and <b>m</b> when selected will display ==== Daily Usage Report by Remote Host====The following is a new sub-menusample Daily Usage Report from Remote Host 10.94.10.25 on host.cty.senecacollege.ca:
When option <bpre>q</b> is selected, you program should terminateDaily Usage Report from 10.94.10.25 ===================================Date Usage in seconds2018 02 14 302018 02 07 412018 02 01 9
=== Daily Usage Menu ===Total 80* If the Daily Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:</pre>
<source>Daily Usage Report==============Weekly Usage Report by User ====u) By Userh) By Remote Hostr) Return to Main Menu</source>The following is a sample Weekly Usage Report for user1 on host.cty.senecacollege.ca:
When option <bpre>u</b> is selected, the sub-menu Weekly Usage Report for Daily user1=============================Week # Usage Report by User should be displayed.in Seconds2017 01 1602017 02 452017 03 52017 04 20
When option <b>hTotal 220</bpre> is selected, the sub-menu for Daily Usage Report by Remote Host should be displayed.
When option <b>r</b> ==== Weekly Usage Report by Remote Host ====The following is selected, a sample Weekly Usage Report from the main menu should be displayedremote host 10.94.10.25 on host.cty.senecacollege.ca:
<sourcepre>Daily Weekly Usage Report - by Userfrom 10.94.10.25====================================...Week # Usage in SecondsDisplay list of valid user2017 01 30...2017 03 41r) Return to Daily Usage Report2017 05 9</source>When a <b>valid user</b> is selected, display the Daily Usage Report for the selected user.2017 06 11
When option <b>rTotal 91</bpre> is selected, the Daily Usage Report menu should be displayed.
<source>Daily ==== Monthly Usage Report - by Remote Host=User ====The following is a sample Monthly Usage Report for user1 on host.cty.senecacollege.ca:<pre>Monthly Usage Report for user1==============================...Month Usage in SecondsDisplay list of valid Remote Host2017 01 160...r) Return to Daily Usage Report</source>2017 02 45
When a <b>valid Remote HostTotal 205</bpre> is selected, display the Daily Usage Report for the selected Remote Host.
==== Monthly Usage Report by Remote Host ====
The following is a sample Monthly Usage Report for 10.94.10.25 on host.cty.senecacollege.ca:
When option <bpre>r</b> is selected, the Daily Monthly Usage Report menu should be displayedfrom 10.94.10.25=====================================Month Usage in Seconds2017 01 302017 02 41
=== Weekly Usage Menu ===Total 71* 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======+============u) By Userh) By Remote Hostr) 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</bpre> is selected, the main menu should be displayed.
<source>Weekly Usage Report - by User=======+===================Program Development and Testing ==...You should create python functions to handle the following sub-tasks:Display list * gets login records from the output of valid "last" command and filters out unwanted records* reads login records from files and filters out unwanted records* generate daily usage reports by useror by remote host...* generate weekly usage reports by user or by remote host* generate monthly usage reports by user or by remote hostr) Return to Weekly To help you with this assignment, [[OPS435 A1 Usage Report Menu</source>When Template|here is a template]] you can use as a <b>valid user</b> is selected, display the Weekly starting point in developing your Python Usage Report for the selected userprogram.
When option <b>r</b> is selectedOnce you have finished coding a function, you should start a Python3 interactive shell, import your functions and manually call the Weekly Usage Report menu should be displayedfunction you want to test<source>Weekly Usage Report - by Remote Host===================================...Display list of valid Remote Host...r) Return to Weekly Usage Report Menu</source>
When a <b>valid Remote Host</b> Once you have all the individual function tested and that each is selectedworking properly, display perform the Weekly Usage Report for final test with test data provided by your professor and verify that your program produces the selected Remote Hostcorrect results before submitting your python program on Blackboard.
== Sample login records file and sample run ==
* [https://scs.senecac.on.ca/~raymond.chan/ops435/a1/ Sample test date files and sample runs]
When option <b>r</b> is selected, the Weekly Usage Report menu should be displayed.== Rubric ==
{| 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 Menu ===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''' || 25 ||
== Sample login records file ==|}
== Submission ==
After fully testing your program, submit the your ur.py file on Blackboard
1,760
edits