Search in sources :

Example 1 with DiagTest

use of com.emc.vipr.model.sys.healthmonitor.DiagTest in project coprhd-controller by CoprHD.

the class DiagnosticsExecTest method testNodeDiagnostics.

@Test
public void testNodeDiagnostics() {
    HealthMonitorService healthMonitorService = new HealthMonitorService();
    DiagnosticsRestRep resp = healthMonitorService.getDiagnostics(null, "1", null);
    Assert.assertNotNull(resp);
    Assert.assertNotNull(resp.getNodeDiagnosticsList());
    Set<String> testNames = new HashSet<String>();
    for (NodeDiagnostics diag : resp.getNodeDiagnosticsList()) {
        Assert.assertTrue(diag.getNodeId() != null && !diag.getNodeId().isEmpty());
        Assert.assertTrue(diag.getIp() != null && !diag.getIp().isEmpty());
        Assert.assertNotNull(diag.getDiagTests());
        for (DiagTest test : diag.getDiagTests()) {
            testNames.add(test.getName());
            Assert.assertTrue(test.getStatus() != null && !test.getStatus().isEmpty());
            if (test.getTestParams() != null) {
                for (TestParam param : test.getTestParams()) {
                    Assert.assertTrue(param.getKey() != null && !param.getKey().isEmpty());
                    Assert.assertTrue(param.getValue() != null && !param.getValue().isEmpty());
                }
            }
        }
        Assert.assertTrue(testNames.containsAll(DIAG_TESTS));
    }
}
Also used : HealthMonitorService(com.emc.storageos.systemservices.impl.resource.HealthMonitorService) TestParam(com.emc.vipr.model.sys.healthmonitor.TestParam) DiagnosticsRestRep(com.emc.vipr.model.sys.healthmonitor.DiagnosticsRestRep) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest) NodeDiagnostics(com.emc.vipr.model.sys.healthmonitor.NodeDiagnostics) HashSet(java.util.HashSet) Test(org.junit.Test) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest)

Example 2 with DiagTest

use of com.emc.vipr.model.sys.healthmonitor.DiagTest in project coprhd-controller by CoprHD.

the class DiagnosticsExec method convertStringToDiagTestList.

/**
 * Converts the diagtool output string to DiagTest objects.
 * Expected stdOut format when verbose option is set:
 * * Network routing: [OK]
 * network_gw=10.247.96.1
 * * DNS: [OK]
 * network_nameserver=10.254.66.23 [OK]
 * network_nameserver=10.254.66.24 [OK]
 * * Remote Repository: [OK]
 */
protected static List<DiagTest> convertStringToDiagTestList(String stdOut) {
    if (stdOut == null || stdOut.isEmpty()) {
        return null;
    }
    List<DiagTest> diagTests = new ArrayList<DiagTest>();
    Pattern paramValPattern = Pattern.compile("(.*)\\s+\\[(.*)\\]");
    Pattern testPattern = Pattern.compile("^\\*\\s+(\\S.*):\\s+\\[(.*)\\]");
    String[] tests = stdOut.split("\n");
    List<TestParam> paramStrs = null;
    for (String test : tests) {
        Matcher matcher = testPattern.matcher(test.trim());
        if (matcher.find()) {
            paramStrs = new ArrayList<TestParam>();
            diagTests.add(new DiagTest(matcher.group(1), matcher.group(2), paramStrs));
        } else {
            String[] keyVal = test.split("=");
            if (keyVal.length >= 2) {
                Matcher paramValMatcher = paramValPattern.matcher(keyVal[1]);
                if (paramValMatcher.find()) {
                    paramStrs.add(new TestParam(keyVal[0].trim(), paramValMatcher.group(1), paramValMatcher.group(2)));
                } else {
                    paramStrs.add(new TestParam(keyVal[0].trim(), keyVal[1]));
                }
            }
        }
    }
    return diagTests;
}
Also used : Pattern(java.util.regex.Pattern) TestParam(com.emc.vipr.model.sys.healthmonitor.TestParam) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest)

Example 3 with DiagTest

use of com.emc.vipr.model.sys.healthmonitor.DiagTest in project coprhd-controller by CoprHD.

the class HealthMonitorService method getDiagnostics.

/**
 * Get results of diagtool shell script for all virtual machines in a ViPR
 * controller appliance. Also gives test details when verbose option
 * is set.
 *
 * @brief Get diagtool script results
 * @param nodeIds node ids for which diagnostic results are collected.
 * @param nodeNames node names for which diagnostic results are collected.
 * @param verbose when set to "1"  will run command with -v option.
 * @prereq none
 * @return Returns diagnostic test results.
 */
@GET
@Path("/diagnostics")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public DiagnosticsRestRep getDiagnostics(@QueryParam("node_id") List<String> nodeIds, @QueryParam("verbose") String verbose, @QueryParam("node_name") List<String> nodeNames) {
    _log.info("Initiating diagnostics test for nodes");
    nodeIds = _coordinatorClientExt.combineNodeNamesWithNodeIds(nodeNames, nodeIds);
    boolean isVerbose = ("1".equals(verbose)) ? true : false;
    DiagRequestParams diagRequestParams = new DiagRequestParams(isVerbose);
    DiagnosticsRestRep diagnosticsRestRep = new DiagnosticsRestRep();
    List<NodeInfo> nodeInfoList = ClusterNodesUtil.getClusterNodeInfo(nodeIds);
    Map<String, NodeDiagnostics> nodesData = NodeDataCollector.getDataFromNodes(nodeInfoList, INTERNAL_NODE_DIAGNOSTICS_URI, Action.POST, diagRequestParams, NodeDiagnostics.class, null);
    String allocationResult = _checker.getNodeResourceAllocationCheckResult();
    DiagTest allocationTest = new DiagTest("Resource allocation", allocationResult, new ArrayList<TestParam>());
    for (Map.Entry<String, NodeDiagnostics> entry : nodesData.entrySet()) {
        List<DiagTest> diagTests = entry.getValue().getDiagTests();
        diagTests.add(allocationTest);
        entry.getValue().setDiagTests(diagTests);
    }
    diagnosticsRestRep.getNodeDiagnosticsList().addAll(nodesData.values());
    return diagnosticsRestRep;
}
Also used : TestParam(com.emc.vipr.model.sys.healthmonitor.TestParam) DiagRequestParams(com.emc.vipr.model.sys.healthmonitor.DiagRequestParams) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest) NodeInfo(com.emc.storageos.systemservices.impl.resource.util.NodeInfo) DiagnosticsRestRep(com.emc.vipr.model.sys.healthmonitor.DiagnosticsRestRep) NodeDiagnostics(com.emc.vipr.model.sys.healthmonitor.NodeDiagnostics) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with DiagTest

use of com.emc.vipr.model.sys.healthmonitor.DiagTest in project coprhd-controller by CoprHD.

the class DiagnosticsScheduler method run.

@Override
public void run() {
    List<DiagTest> diagTests = DiagnosticsExec.getDiagToolResults(DiagConstants.VERBOSE);
    DiagTestMetadata diagTestMetadata;
    for (DiagTest test : diagTests) {
        if ((diagTestMetadata = DiagTestsMetadata.getMetadata().get(test.getName())) != null) {
            String[] statusArr = test.getStatus().split(",");
            for (String status : statusArr) {
                status = status.trim();
                if (!diagTestMetadata.getOk().contains(status)) {
                    if (diagTestMetadata.getWarn().contains(status)) {
                        alertsLog.warn(test);
                    } else if (diagTestMetadata.getError().contains(status)) {
                        alertsLog.error(test);
                    } else if (diagTestMetadata.getCrit().contains(status)) {
                        alertsLog.fatal(test);
                    }
                }
            }
        }
    }
    // Monitor dbsvc and geodbsvc status and persist service downtime to ZK
    _dbDowntimeTracker.run();
    // Analysis db and zk logs, if the errors match pre-define patterns, alter it in SystemEvents.
    _dbLogAnalyser.analysisLogs();
    _zkLogAnalyser.analysisLogs();
    _controllerSvcLogAnalyser.analysisLogs();
}
Also used : DiagTestMetadata(com.emc.storageos.systemservices.impl.healthmonitor.beans.DiagTestMetadata) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest)

Example 5 with DiagTest

use of com.emc.vipr.model.sys.healthmonitor.DiagTest in project coprhd-controller by CoprHD.

the class DiagnosticsExecTest method testConversion.

@Test
public void testConversion() {
    List<DiagTest> diagTests = convertStringToDiagTestList(STDOUT);
    System.out.println("STDOUT: " + STDOUT);
    System.out.println("diagTests: " + diagTests);
    Assert.assertTrue(diagTests != null && diagTests.size() == 2);
    for (DiagTest test : diagTests) {
        if (test.getName().equals(TEST_NAME1)) {
            Assert.assertTrue(test.getStatus().equals(TEST_STATUS1));
        } else if (test.getName().equals(TEST_NAME2)) {
            Assert.assertTrue(test.getStatus().equals(TEST_STATUS2));
        } else {
            Assert.fail();
        }
    }
}
Also used : DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest) Test(org.junit.Test) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest)

Aggregations

DiagTest (com.emc.vipr.model.sys.healthmonitor.DiagTest)5 TestParam (com.emc.vipr.model.sys.healthmonitor.TestParam)3 DiagnosticsRestRep (com.emc.vipr.model.sys.healthmonitor.DiagnosticsRestRep)2 NodeDiagnostics (com.emc.vipr.model.sys.healthmonitor.NodeDiagnostics)2 Test (org.junit.Test)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 DiagTestMetadata (com.emc.storageos.systemservices.impl.healthmonitor.beans.DiagTestMetadata)1 HealthMonitorService (com.emc.storageos.systemservices.impl.resource.HealthMonitorService)1 NodeInfo (com.emc.storageos.systemservices.impl.resource.util.NodeInfo)1 DiagRequestParams (com.emc.vipr.model.sys.healthmonitor.DiagRequestParams)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1