#!/appl/perl/perl5.003/bin/perl # license_report.cgi # By: Jim Speights # Date: 2/10/99 # Description: Program to generate an html page containing a license report for the date # specified in the PATH_INFO environment variable. The date should be in the # following format: YYYY-MM-DD # The program will generate a usage report with data obtained from the MySql database # running on gilligan. This database is populated by the following programs, which # use ptcmonitor and ptcstatus and are run by cron on gilligan: # # /usr/people/gilligan/speights/scripts/lic_mon3/pop_LIC_MONITOR.pl # /usr/people/gilligan/speights/scripts/lic_mon3/pop_UTILIZATION.pl # # These programs populate the LIC_MONITOR and UTILIZATION tables in the PTC_MONITOR # database. # # # -------------------------------------------------------------------------------------------------- # Revision History # # 2/10/99 J. Speights Initial Release # # 4/6/99 J. Speights Added two modules Pro/MEC-Vibration and Pro/MEC-Cus-Loads # per Jay Seifert's license update. # # 4/7/99 J. Speights Changed main program so that only a single sql command is executed, # and sorting is now done in the cgi program. Also added ability # to detect posted year, month, and day and to use it for the # report date if available. # # 4/8/99 J. Speights Removed the following modules: # # "Pro/INTERFACE", "Pro/SHEETMETAL", "Pro/ECAD", # "Pro/SURFACE", "Pro/PROCESS_ASM" # # 6/8/99 J. Speights Added percentage labels to vertical axis # -------------------------------------------------------------------------------------------------- require '../cgi-lib.pl'; use lib '/appl/enterprise/cgi-bin/CommonSK'; use OracleSetup; use Setup; MAIN: { my( @modules ) = ( "PROE_19891", "PDM_20102", "ILINK_CLIENT_715330", "FLYTHRU_715331", "Pro/MESH", "Pro/CABLING", "Pro/DIAGRAM", "Pro/HARNESS-MFG", "Pro/MEC-Vibration", "Pro/MEC-Cus-Loads", "MECINTERFCE_20175", "MECSTRUCUI_20175", "MECSTRUCENG_20175", "MECMOTUI_20175", "MECMOTENG_20175", "MECTHERMUI_20175", "MECTHERMENG_20175" ); my ($x, $y, $i, $hourly_data, @date, @charts, @data); my @report_hours = ( "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18" ); my $report_date=""; my $seats = 0; # make database connection my ( $sth, $dbh, $row, $rc, $error ); my @return_vals; $lda = &oracle_login('d01', 'pro_admin', 'allparts'); eval 'use Oraperl; 1' || die $@ if $] >= 5; # If a report date is passed in on the query string use it, else look for a posted report # date. If neither are found, or if the value used is invalid, print an error message &ReadParse( *input ); if( defined( $input{'YEAR'}) ) { $report_date = $input{'YEAR'}."-".$input{'MONTH'}."-".$input{'DAY'}; } else { if( defined( $ENV{"PATH_INFO"} ) ) { $report_date = $ENV{"PATH_INFO"}; $report_date =~ s/^.//; } } if( $report_date !~ /[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]/ ) { # &CgiDie("An invalid report date has been specified. Unable to generate report.\n"); } # print header for html page &print_html_header( $report_date ); # get all MySql data points for the requested day $csr = &ora_open($lda, "select to_char(RECORD_DATE, 'YYYY-MM-DD HH24:MI:SS'), MODULE1, LIC_IN_USE / (LIC_IN_USE + LIC_FREE), (LIC_IN_USE + LIC_FREE) from UTILIZATION where RECORD_DATE between to_date(\'$report_date 00:00:00\', \'YYYY-MM-DD HH24:MI:SS\') and to_date(\'$report_date 23:59:59\', \'YYYY-MM-DD HH24:MI:SS\') ") || &oracle_error(2); $no_row = 0; while (($out_recdate, $out_module1, $out_cal1, $out_cal2) = &ora_fetch($csr)) { $no_row = $no_row + 1; push(@out_recdate1, $out_recdate); push(@out_module11, $out_module1); push(@out_cal11, $out_cal1); push(@out_cal21, $out_cal2); } # create html bar charts foreach $y ( @modules ) { @data = (); $seats = 0; foreach $x ( @report_hours ) { # if no data for this hour is found, a value of 0 will be used $hourly_data = 0; for ($i = 0; $i< $no_row; $i++) { my $temp = $y; $temp =~ s/\//\\\//; if( ( $out_recdate1[$i] =~ /....-..-.. $x:..:../ ) && ( $out_module11[$i] =~ /$temp/ ) ) { $hourly_data = $out_cal11[$i]; # $hourly_data = $hourly_data+$out_cal11[$i]; if( $seats == 0 ){ $seats = $out_cal21[$i] } } } push( @data, $hourly_data ); } &html_bar_chart( $y, $seats, @data ); } &ora_close($csr); exit(0); } sub print_html_header { my $report_date = $_[0]; print < PTC License Utilization Report For $report_date
PTC License Utilization Report For $report_date


EOT } # sub html_bar_chart # Description: Creates an html bar chart based on the contents of below arrays. # # # Notes: The number of charts to be created is equal to the number of # titles in the @chart_titles array. # # The html page created uses redbar.jpg and whitebar.jpg for # the graphics source files for the actual bar on each bar chart. # These files must be available in order to view the html file. sub html_bar_chart { my( $chart ) = $_[0]; my( $seats ) = $_[1]; my( @yvalues ) = ( $_[2], $_[3], $_[4], $_[5], $_[6], $_[7], $_[8], $_[9], $_[10], $_[11], $_[12], $_[13] ) ; # Should be in percentages my( $redbar ) = "\'http://gilligan.stortek.com/images/redbar.jpg\'"; my( $whitebar ) = "\'http://gilligan.stortek.com/images/whitebar.jpg\'"; my( $bar_width ) = 14; my( $vscale )= 200; # Scale, used to multiply the percentage to get bar chart height my( $chart_height )= $vscale + 10; my( @xlabels )= (7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6); # X axis label for each bar my( $i, $x, $y, @temp ); my( $xtitle ) = "   Time     ( 7:00 AM to 6:00 PM MST )"; # print chart header print <
\n$xtitle
 

$chart      ( $seats licenses available )
100 % -




50 % -




0 % -

   \n EOT # create a bar for each y value foreach $y (@yvalues) { # zero height images end up being rather tall, so add one just incase the height is 0 $y = $y*$vscale + 1; print <     EOT } print( "
        "); # Print x-axis labels foreach $x (@xlabels) { print( "$x      \n" ); } print("\n
\n\n"); print("\n"); } # end sub html_bar_chart # sub html_auth_report # Description: Creates html text suitable for insertion into an existing html file. # The text contains a listing of nodes appearing in the global array # @todays_list that do not appear in the file specified by the first # argument to this function auth_nodes_file. # # Arguments: $auth_nodes_file - contains a list of authorized nodes. The first # part of the fully qualified host name should be used only. # # Returns: A single string containing html formatted text suitable for # insertion directly into an html file. The text will contain # a list of unauthorized nodes. sub html_auth_report { my( @todays_list, $x, $report_text, $return_string, @nodes, @temp, $nodename, @unauthorized); my( $auth_nodes_file ) = $_[0]; local( *INFILE ) ; open( INFILE, "<$auth_nodes_file " ) || die "can't open AUTHORIZED NODES file: $!\n"; # read in list of authorized nodes @nodes = ; close( INFILE ); #check to see that each node on todays_list is authorized foreach $x (@todays_list) { @temp = split(" ", $x); # the authorized nodes list has the first part of the hostname only, so # get rid of any periods in the names before comparing. if( grep( /\./, $temp[1] ) == 1 ) { @temp= split( '.', $temp[1] ); $nodename = $temp[0]; } else { $nodename = $temp[1]; } if( grep( /$nodename/i, @nodes ) == 0 ) { if( $#unauthorized < 0 ) { push(@unauthorized, "

The following unauthorized users were found:

Pro SN | Node | User | Start Date | Start Time | End Date | End Time

"); push(@unauthorized,"
", $x ); } else { push(@unauthorized,"
", $x ); } } } # end foreach $x if( $#unauthorized == 0 ) { push(@unauthorized, "
No unauthorized users reported."); } # create report text string, starting with a title for the section $report_text = "




Authorization Report



\n"; # append unauthorized array line by line to report_text string foreach $x (@unauthorized) { $report_text .= $x." \n"; } # return test string $return_string = $report_text; } #end sub html_auth_report