Search in sources :

Example 11 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class LogStreamTest method testSmallFileLevelFilter.

/**
 * Test if logs read from LogStream match level specified in LogRequest
 */
@Test
public void testSmallFileLevelFilter() throws Exception {
    File file = new File(timeRangeFilePath);
    List<File> files = new ArrayList<File>();
    files.add(file);
    // "WARN"
    int level = 5;
    LogRequest req = new LogRequest.Builder().logLevel(level).build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream("", files, req, status);
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            break;
        }
        assertTrue("Log level should match", LogSeverity.toLevel(new String(log.getLevel())) <= level);
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 12 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class LogStreamTest method testSmallFilePatternFilter.

/**
 * Test if logs read from LogStream match pattern(keywords) specified in
 * LogRequest
 */
@Test
public void testSmallFilePatternFilter() throws Exception {
    File file = new File(timeRangeFilePath);
    List<File> files = new ArrayList<File>();
    files.add(file);
    String pattern = "reset";
    LogRequest req = new LogRequest.Builder().regex(pattern).build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream("", files, req, status);
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            break;
        }
        assertTrue("log should have the keywords", toStringOriginalFormatStr(log).indexOf(pattern) >= 0);
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 13 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class LogStreamTest method testReadNextLogMaxCountFilterGreaterThanMAXCOUNTOVERFLOW.

/**
 * Test max count filter totalCount > maxCount + MAX_OVERFLOW
 *
 * @throws Exception
 */
@Test
@Ignore
public void testReadNextLogMaxCountFilterGreaterThanMAXCOUNTOVERFLOW() throws Exception {
    List<File> files = new ArrayList<File>();
    files.add(new File(timeStampFilePath));
    // should get 16 log Messages
    long maxCount = 10;
    int count = 0;
    LogRequest req = new LogRequest.Builder().maxCont(maxCount).build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream("", files, req, status);
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            System.out.println("count=" + count);
            assertEquals("Total line number should match max count limit", 16, count);
            break;
        }
        count++;
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) ArrayList(java.util.ArrayList) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class SendAlertEvent method generateSystemEventFile.

/**
 * Gets system events for the parameters entered,
 * loads the output to file with name SYSTEM_EVENT_FILE_NAME and returns it.
 */
private String generateSystemEventFile() throws IOException {
    // Create the log request info bean from the request data.
    LogRequest logReqInfo = new LogRequest.Builder().nodeIds(_nodeIds).baseNames(sysEventlogFileNames).logLevel(_severity).startTime(_start).endTime(_end).regex(_msgRegex).maxCont(maxCount).build();
    String fileName = SYSTEM_EVENT_FILE_NAME + getFileExtension();
    generateLogFile(logReqInfo, mediaType, SYSTEM_EVENT_FILE_PATH, fileName);
    return SYSTEM_EVENT_FILE_PATH;
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest)

Example 15 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class SendAlertEvent method genAttachFiles.

/**
 * Generate the attachments for alerts event
 * 1. ovf properties file
 * 2. log file for the parameters given
 * 3. system events file for the parameters given
 */
@Override
protected ArrayList<String> genAttachFiles() throws Exception {
    _log.info("Start SendAlertEvent::genAttachFiles");
    // Generate message file
    ArrayList<String> fileList = new ArrayList<String>();
    // Generate log file
    ZipOutputStream outputStream = null;
    try {
        fileList.add(generateConfigFile());
        fileList.add(generateSystemEventFile());
        // Create the log request info bean from the request data.
        String fileName = SYSTEM_LOGS_FILE_NAME + getFileExtension();
        _log.debug("Logs zip entry name {}", fileName);
        LogRequest logReqInfo = new LogRequest.Builder().nodeIds(_nodeIds).baseNames(_logNames).logLevel(_severity).startTime(_start).endTime(_end).regex(_msgRegex).maxCont(maxCount).build();
        generateLogFile(logReqInfo, mediaType, SYSTEM_LOGS_FILE_PATH, fileName);
        fileList.add(SYSTEM_LOGS_FILE_PATH);
    } finally {
        if (outputStream != null) {
            outputStream.close();
        }
    }
    _log.info("Finish SendAlertEvent::genAttachFiles");
    return fileList;
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) ZipOutputStream(java.util.zip.ZipOutputStream) ArrayList(java.util.ArrayList)

Aggregations

LogRequest (com.emc.vipr.model.sys.logging.LogRequest)38 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)21 File (java.io.File)17 LogMessage (com.emc.storageos.systemservices.impl.logsvc.LogMessage)15 LogFileStream (com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream)13 Calendar (java.util.Calendar)13 Date (java.util.Date)13 LogStatusInfo (com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo)12 Ignore (org.junit.Ignore)12 LogReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogReader)10 LogStreamMerger (com.emc.storageos.systemservices.impl.logsvc.merger.LogStreamMerger)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 SysClientFactory (com.emc.storageos.systemservices.impl.client.SysClientFactory)2 LogNetworkWriter (com.emc.storageos.systemservices.impl.logsvc.LogNetworkWriter)2 LogNetworkStreamMerger (com.emc.storageos.systemservices.impl.logsvc.merger.LogNetworkStreamMerger)2 LogNetworkReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader)2 NodeInfo (com.emc.storageos.systemservices.impl.resource.util.NodeInfo)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2