"Read warning" , 2 => "Write warning" , 3 => "Hard error" , 4 => "Media" , 5 => "Read failure" , 6 => "Write failure" , 7 => "Media life" , 8 => "Not data grade" , 9 => "Write protect" , 10 => "Media removal prevented" , 11 => "Cleaning media" , 12 => "Unsupported format" , 13 => "Recoverable mechanical cartridge failure" , 14 => "Unrecoverable mechanical cartridge failure" , 15 => "Memory chip in cartridge failure" , 16 => "Forced eject" , 17 => "Read only format" , 18 => "Tape directory corrupted on load" , 19 => "Nearing media life" , 20 => "Cleaning required" , 21 => "Cleaning requested" , 22 => "Expired cleaning media" , 23 => "Invalid cleaning media" , 24 => "Retension requested" , 25 => "Multi-port interface error on a primary port" , 26 => "Cooling fan failure" , 27 => "Power supply failure" , 28 => "Power consumption" , 29 => "Drive preventive maintenance required" , 30 => "Hardware A" , 31 => "Hardware B" , 32 => "Primary interface" , 33 => "Eject media" , 34 => "Microcode update fail" , 35 => "Drive humidity" , 36 => "Drive temperature" , 37 => "Drive voltage " , 38 => "Predictive failure" , 39 => "Diagnostics required" , //40 – 46 Obsolete //47 – 49 Reserved 50 => "Lost statistics" , 51 => "Tape directory invalid at unload" , 52 => "Tape system area write failure" , 53 => "Tape system area read failure" , 54 => "No start of data" , 55 => "Loading or threading failure" , 56 => "Unrecover-able unload failure" , 57 => "Automation interface failure" , 58 => "Microcode failure" , 59 => "WORM medium - integrity check failed" , 60 => "WORM medium - overwrite attempted" //61 – 64 Reserved ); // Handle the progress screen if opened and get the NEW data $logFileLabel = ""; $logFileToShow = ""; $hiddenFileValue = ""; $fileNotFound = "false"; $isEmailConfigured = "false"; $buffersize = 1*(256); // 256 char chunks $buffer = ''; /* // TapeAlertLog: // DATE TIME,SERIAL NUMBER, BARCODE, TAPEALERT# */ class CMediaData { var $aTime; var $serial; var $barcode; var $tapeAlert; var $use; function CMediaData($aTime, $serial, $barcode, $tapeAlert) { $this->aTime = $aTime; $this->serial = $serial; $this->barcode = $barcode; $this->tapeAlert = $tapeAlert; $this->use = true; } }; $backLoc = '/reportMediaIntegrity.htm'; $reportType = "Media Integrity"; $chartLineWidth = 3; // The default size of the lines the charts are drawn with. if ($_SERVER[REQUEST_METHOD] == "POST") { error_log("_POST = ". print_r($_POST,true) ); // Load the passed in data $Range = $_POST['range']; $Group = $_POST['group']; $Type = $_POST['type']; $ChartType = $_POST['chartType']; $At_mi = $_POST['at_mi']; $At_dsn = $_POST['at_dsn']; $At_ta = $_POST['at_ta']; $Sort = $_POST['sort']; $SelBy = $_POST['SelBy']; $StaticPoints = $_POST['staticPoints']; // The file to work with is $headerString = "Date/Time, Serial, Barcode, TapeAlert, TapeAlert Description\n"; $fileNameOrig = "/home/embedded/library/CoreService/dat/TapeAlertLog"; $fileNameT = "/tmp/TapeAlertLog"; $fileName = "/tmp/TapeAlertLog.csv"; // First copy the current DriveLog to tmp error_log("Creating the concatenated file out of all TapeAlert archives"); $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE cp ".$fileNameOrig." ".$fileNameT, $iRet); error_log("Call to system (cp TapeAlert) returned a \"$iRet\" and the output was \"$sRet\""); $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE chmod 666 ".$fileNameT, $iRet); error_log("Call to system (chmod 666 TapeAlert) returned a \"$iRet\" and the output was \"$sRet\""); // Now concatenate all the archive files into the new file in tmp $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE zcat -d ".$fileNameOrig.".* >> ". $fileNameT, $iRet); error_log("Call to system (zcat TapeAlert.*) returned a \"$iRet\" and the output was \"$sRet\""); $today = time(); // Find the date for the date range compare switch($Range) { case 'R_all': $formatStr = "ym"; $theRangeStart = date('ym',strtotime("-2 years") ); $theRangeEnd = date('ym',$today); break; case 'R_3m': $formatStr = "ym"; $theRangeStart = date('ym',strtotime("-3 month") ); $theRangeEnd = date('ym',$today); break; case 'R_4w': $formatStr = "ymd"; $theRangeStart = date('ymd',strtotime("-28 day") ); $theRangeEnd = date('ymd',$today); break; case 'R_7d': $formatStr = "ymd"; $theRangeStart = date('ymd',strtotime("-7 days") ); $theRangeEnd = date('ymd',$today); break; } error_log("\nThe startDate = ". $theRangeStart ); // Process the file set_time_limit(0); // Turn off timelimit or php will complain with large amounts of data $outBuf = ""; if ($handle = fopen($fileNameT, 'rb')) { $i=0; while(!feof($handle) and (connection_status()==0)) { //print(fread($handle, 1024*1)); // Because we need to examin the date on each line we will use the fgets instead. $buffer = fgets( $handle, $buffersize ); $tData = split(",", $buffer ); if( $tData[0] == "" ) continue; // The last one can be blank - pass it up but let the loop end normally $i++; // First see if this data item is in range or not. // If not - don't use it $timeStamp = strtotime($tData[0]); //error_log("Reading record ".$i." of the data. StartDate = ".$theRangeStart." | timeStampFormated = ".date($formatStr, $timeStamp )); if( date($formatStr, $timeStamp ) <= $theRangeStart) { //error_log("The date ". $tData[0] ." is out of range for ". $Range ." | ". date($formatStr, $timeStamp ) ." < ". $theRangeStart); continue; // Try the next one } // Add the Tape Alert Description to the end of each line. $iTmp = (int)$tData[3]; //error_log("tData = ". print_r($tData, true)); //error_log("tData[3] = ". $tData[3]); //error_log("TapeAlertDesc[iTmp] = ". $TapeAlertDesc[$iTmp]); $outBuf .= (trim($buffer,"\n") .",". $TapeAlertDesc[$iTmp] ."\n"); //error_log("outBuf = ". $outBuf); //flush(); } } if($i = 0) { // There was no data - so let the user know $outBuf = "No data found in date range!\n"; } //flush(); fclose($handle); //error_log("outBuf size = ".sizeof($outBuf)."\nThe buffer = ".$outBuf."\n\n\n\n\n"); if( $fh = fopen($fileName, 'w')) { fwrite($fh, $headerString, strlen($headerString)); fwrite($fh, $outBuf, strlen($outBuf)); fclose($fh); } else { error_log("Could not open the output file for writing"); error_back(0x0b); } set_time_limit(30); // Set back to the default ////////////////////////////////////////////// // Now do the operation the user requested. ////////////////////////////////////////////// if( $_POST['whatsSelected'] == "save" ) { if (file_exists($fileName)) { $size = filesize($fileName); error_log("The size of the file being saved is: ". $size); header("Pragma: "); header("Cache-Control: "); header("Content-Type: text/csv"); header("Content-Length: $size"); header('Content-Disposition: attachment; filename="' . basename($fileName) . '"'); header("Content-Location: $fileName"); header("Cache-Control: private"); $handle = fopen($fileName, "r"); //######################################################### //# NOTE: Not using fpassthru() here becaseu it has a bug //# in it where it was taking on the HTML code from this //# page to the bottom of the TapeApletLog file. It worked //# fine on the DriveLog file. //# The current code works with all the log files. //########################################################## // fpassthru($handle); if ($handle = fopen($fileName, 'rb')) { while(!feof($handle) and (connection_status()==0)) { print(fread($handle, 1024*1)); flush(); } } fclose($handle); return; } else { error_log("Could not log file: ".$fileName); echo ""; } } else if( $_POST['whatsSelected'] == "email" ) { $operationInProgress = true; $status = new ReturnStatus(); email_file( $user, $fileName, $_POST['emailAddress'], "Library TapeAlert Log File" ); print $status->out(); return; } } else { $Range = $_GET['range']; $Group = $_GET['group']; $Type = $_GET['type']; $ChartType = $_GET['chartType']; $At_mi = $_GET['at_mi']; $At_dsn = $_GET['at_dsn']; $At_ta = $_GET['at_ta']; $Sort = $_GET['sort']; $SelBy = $_GET['SelBy']; $StaticPoints = $_GET['staticPoints']; error_log("_GET = ". print_r($_GET, true) ); } $emailConfig = get_email_configuration($user); if( isset($emailConfig) ) { if( trim($emailConfig->smtpServer) != '' ) $isEmailConfigured = "true"; } function check_file_exists( $filename ) { global $fileNotFound; $fh = fopen( $filename, 'rb' ); if( $fh == false ) { $fileNotFound = "true"; } else { fclose( $fh ); } } ///////////////////////////////////////////////////////////////////////////////// // Color Code the Columns to show where the chart element is getting it's data ///////////////////////////////////////////////////////////////////////////////// $chartColors = array( '#ff0000', '#00ff00', '#0000ff' ); //$umntColor = ($_GET['attrib'] == 'AT_MH' ? $chartColors[0] : '#809CA6'); $dateColor = '#809CA6'; $serialColor = '#809CA6'; $barcodeColor = '#809CA6'; $tapeAlertColor = '#809CA6'; ///////////////////////////////////////////////////////////////////////////////// // Create the data we will use to display the chart from the data in the file. ///////////////////////////////////////////////////////////////////////////////// $title = "Media Integrity Report"; // Default $useCol2 = false; $formatStr = ""; $today = time(); error_log("Today is: ". date('l dS \o\f F Y h:i:s A', $today) ); // Set the X Captions //$xCaption = "Count"; //$xCursorCaption = "Count:"; switch( $Group ) { case 'G_ALL': $xCaption = "All"; $xCursorCaption = "Cartridge Barcode:"; break; case 'G_SEL_PSN': $xCaption = "Selected Drive by Physical SN:".$SelBy; $xCursorCaption = "Serial Number:".$SelBy; break; case 'G_SEL_ID': $xCaption = "Selected Cartridge By Barcode:".$SelBy; $xCursorCaption = "Cartridge Barcode:".$SelBy; break; } ///////////////////////////////////////////////////////////////////////////////// // Set the title of the report depending on the attribute settings. ///////////////////////////////////////////////////////////////////////////////// $title = ""; if( $At_mi == 1 ) $title .= "Cartridge Barcode/"; if( $At_dsn == 1 ) $title .= "Drive Physical SN/"; if( $At_ta == 1 ) $title .= "TapeAlert/"; $title = trim($title,"/"); if( $title == "" ) $title = "Count"; ///////////////////////////////////////////////////////////////////////////////// // Set the title of the report depending on the attribute setting. ///////////////////////////////////////////////////////////////////////////////// $colTitle1 = "Count";//TapeAlert $colTitle2 = "Count"; $yCaption = "Count";//TapeAlert $yCursorCaption = "count"; $range = ""; switch( $Range ) { case 'R_all': $range = "All Historical Data"; break; case 'R_3m': $range = "Last 3 Months"; break; case 'R_4w': $range = "Last 4 Weeks"; break; case 'R_7d': $range = "Last 7 Days"; break; } switch ( $Sort) { case 'S_A': $sort = "Alphabetical"; break; case 'S_C': $sort = "Count"; break; case 'S_L': $sort = "Last Occurrence"; break; } // Create the strings to show in the description of the page. //$group = strtolower($xCaption); //$attrib = strtolower($title); $group = $xCaption; $attrib = $title; $theAction = $_SERVER[REQUEST_URI]."?range=". $Range ."&group=". $Group ."&type=". $Type ."&chartType=". $ChartType ."&reportType=media". "&at_mi=". $At_mi ."&at_dsn=". $At_dsn ."&at_ta=". $At_ta ."&orientation=horizontal&SelBy=". $SelBy; $StaticPoints = isset($StaticPoints)?'true':'false'; //////////////////////////////////////////////////////////////////////////////////////////////////// // Determine the orientation $isHorizontal = false; if( isset($_GET['orientation']) ) if( $_GET['orientation'] == horizontal ) $isHorizontal = true; $isHorizontal = false; ?>