Search in sources :

Example 1 with ResourceConfig

use of com.integrien.alive.common.adapter3.config.ResourceConfig in project Server_Management_Plugin_vRealize by Huawei.

the class ESightAdapter method onCollect.

/**
 * This method is called for each collection cycle. By default, this value
 * is 5 minutes unless user changes it
 *
 * @param adapterInstResource ResourceConfig
 * @param monitoringResources Collection<ResourceConfig>
 */
@Override
public void onCollect(ResourceConfig adapterInstResource, Collection<ResourceConfig> monitoringResources) {
    if (logger.isInfoEnabled()) {
        logger.info("Inside onCollect method of ESightAdapter class");
    }
    final IdentifierCredentialProperties prop = new IdentifierCredentialProperties(adapterLoggerFactory, adapterInstResource);
    String hostIp = prop.getIdentifier(Constant.KEY_SERVER_IP_ADDRESS, "").trim();
    setHost(hostIp);
    int hostPort = prop.getIntIdentifier(Constant.KEY_ESIGHT_SERVER_PORT, Constant.DEFAULT_ESIGHT_SERVER_PORT);
    String username = prop.getCredential(Constant.KEY_ESIGHT_ACCOUNT);
    String eSightCode = prop.getCredential(Constant.KEY_ESIGHT_CODE);
    String openid = null;
    try {
        openid = service.login(hostIp, hostPort, username, eSightCode);
    } catch (EsightException e) {
        logger.error(e.getMessage() + ": eSight server (" + hostIp + ") authentication failed.", e);
    }
    if (openid == null || openid.isEmpty()) {
        configEsight(hostIp);
        return;
    }
    final Long startTime = System.nanoTime();
    DiscoveryResult discoveryResult = collectResult.getDiscoveryResult(true);
    List<ResourceKey> resources = collectResourceDataFromESight(hostIp);
    // 注销会话 openid
    service.logout(openid);
    if (resources.size() == 0) {
        logger.error("No resources collected from server with IP " + hostIp);
    } else {
        logger.error(resources.size() + " resources collected from server with IP " + hostIp);
    }
    for (ResourceKey resourceKey : resources) {
        useResourceKey(discoveryResult, resourceKey);
    }
    Long seconds = TimeUnit.SECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
    logger.error("Collected resource from esight elapsed time is " + seconds + " seconds.");
    if (seconds > Constant.DEFAULT_COLLECT_INTERVAL * 60) {
        logger.error("PLEASE UPDATE THE COLLECT INTERVAL GREATER THAN " + seconds + " SECONDS.");
    }
}
Also used : DiscoveryResult(com.integrien.alive.common.adapter3.DiscoveryResult) EsightException(com.huawei.esight.exception.EsightException) IdentifierCredentialProperties(com.integrien.alive.common.adapter3.IdentifierCredentialProperties) ResourceKey(com.integrien.alive.common.adapter3.ResourceKey)

Example 2 with ResourceConfig

use of com.integrien.alive.common.adapter3.config.ResourceConfig in project Server_Management_Plugin_vRealize by Huawei.

the class ESightAdapter method useResourceKey.

private void useResourceKey(DiscoveryResult discoveryResult, ResourceKey resourceKey) {
    if (isNewResource(resourceKey)) {
        discoveryResult.addResource(new ResourceConfig(resourceKey));
    }
    // Check if resource is part of monitored set, otherwise continue
    ResourceConfig resourceConfig = getMonitoringResource(resourceKey);
    if (resourceConfig == null) {
        return;
    }
    // Add metrics
    addMetricData(resourceConfig, metricsByResource.get(resourceKey));
    // Add relationships
    Relationships rel = new Relationships();
    rel.setRelationships(resourceKey, relationshipsByResource.get(resourceKey), Collections.singleton(getAdapterKind()));
    discoveryResult.addRelationships(rel);
}
Also used : Relationships(com.integrien.alive.common.adapter3.Relationships) ResourceConfig(com.integrien.alive.common.adapter3.config.ResourceConfig)

Example 3 with ResourceConfig

use of com.integrien.alive.common.adapter3.config.ResourceConfig in project Server_Management_Plugin_vRealize by Huawei.

the class ESightAdapter method onConfigure.

/**
 * This method is called when a new adapter instance is created.
 *
 * @param resStatus           ResourceStatus
 * @param adapterInstResource ResourceConfig
 */
@Override
public void onConfigure(ResourceStatus resStatus, ResourceConfig adapterInstResource) {
    final IdentifierCredentialProperties prop = new IdentifierCredentialProperties(adapterLoggerFactory, adapterInstResource);
    String hostIp = prop.getIdentifier(Constant.KEY_SERVER_IP_ADDRESS, "").trim();
    logger.error("A new adapter instance with server ip '" + hostIp + "' is created");
}
Also used : IdentifierCredentialProperties(com.integrien.alive.common.adapter3.IdentifierCredentialProperties)

Example 4 with ResourceConfig

use of com.integrien.alive.common.adapter3.config.ResourceConfig in project Server_Management_Plugin_vRealize by Huawei.

the class ESightAdapter method onTest.

/**
 * This method is called when presses "Test" button while
 * creating/editing an adapter instance.
 *
 * @param testParam TestParam
 * @return boolean
 */
@Override
public boolean onTest(TestParam testParam) {
    ResourceConfig adapterInstanceResource = testParam.getAdapterConfig().getAdapterInstResource();
    final IdentifierCredentialProperties prop = new IdentifierCredentialProperties(adapterLoggerFactory, adapterInstanceResource);
    if (logger.isInfoEnabled()) {
        logger.info("Inside onTest method of ESightAdapter class");
    }
    String empty = "";
    String hostIp = prop.getIdentifier(Constant.KEY_SERVER_IP_ADDRESS, empty).trim();
    int serverPort = prop.getIntIdentifier(Constant.KEY_ESIGHT_SERVER_PORT, Constant.DEFAULT_ESIGHT_SERVER_PORT);
    String username = prop.getCredential(Constant.KEY_ESIGHT_ACCOUNT);
    String password = prop.getCredential(Constant.KEY_ESIGHT_CODE);
    try {
        if (!isValidUrl(hostIp, serverPort)) {
            throw new EsightException("invalid host ip");
        }
        ESightService serviceImpl = new ESightServiceImpl();
        String openid = serviceImpl.login(hostIp, serverPort, username, password);
        if (openid == null || openid.isEmpty()) {
            return false;
        }
        serviceImpl.logout(openid);
    } catch (EsightException e) {
        logger.error("Test eSight login failed.", e);
        return false;
    }
    return true;
}
Also used : ESightServiceImpl(com.huawei.esight.service.ESightServiceImpl) EsightException(com.huawei.esight.exception.EsightException) ESightService(com.huawei.esight.service.ESightService) ResourceConfig(com.integrien.alive.common.adapter3.config.ResourceConfig) IdentifierCredentialProperties(com.integrien.alive.common.adapter3.IdentifierCredentialProperties)

Example 5 with ResourceConfig

use of com.integrien.alive.common.adapter3.config.ResourceConfig in project Server_Management_Plugin_vRealize by Huawei.

the class ESightAdapter method configEsight.

private void configEsight(String hostIp) {
    ResourceKey resourceKey = new ResourceKey(hostIp, Constant.KIND_HOST_INSTANCE, getAdapterKind());
    long timestamp = System.currentTimeMillis();
    List<MetricData> metricDataList = new ArrayList<>();
    // 设置eSight服务器的状态为离线状态
    metricDataList.add(new MetricData(new MetricKey(false, Constant.ATTR_HEALTHSTATE), timestamp, ConvertUtils.convertHealthState(-1)));
    metricsByResource.put(resourceKey, metricDataList);
    DiscoveryResult discoveryResult = collectResult.getDiscoveryResult(true);
    if (isNewResource(resourceKey)) {
        discoveryResult.addResource(new ResourceConfig(resourceKey));
    }
    // Check if resource is part of monitored set, otherwise continue
    ResourceConfig resourceConfig = getMonitoringResource(resourceKey);
    if (resourceConfig == null) {
        return;
    }
    // Add metrics
    addMetricData(resourceConfig, metricsByResource.get(resourceKey));
    // Add relationships
    Relationships rel = new Relationships();
    rel.setRelationships(resourceKey, relationshipsByResource.get(resourceKey), Collections.singleton(getAdapterKind()));
    discoveryResult.addRelationships(rel);
    return;
}
Also used : DiscoveryResult(com.integrien.alive.common.adapter3.DiscoveryResult) MetricKey(com.integrien.alive.common.adapter3.MetricKey) Relationships(com.integrien.alive.common.adapter3.Relationships) ArrayList(java.util.ArrayList) ResourceConfig(com.integrien.alive.common.adapter3.config.ResourceConfig) ResourceKey(com.integrien.alive.common.adapter3.ResourceKey) MetricData(com.integrien.alive.common.adapter3.MetricData)

Aggregations

IdentifierCredentialProperties (com.integrien.alive.common.adapter3.IdentifierCredentialProperties)3 ResourceConfig (com.integrien.alive.common.adapter3.config.ResourceConfig)3 EsightException (com.huawei.esight.exception.EsightException)2 DiscoveryResult (com.integrien.alive.common.adapter3.DiscoveryResult)2 Relationships (com.integrien.alive.common.adapter3.Relationships)2 ResourceKey (com.integrien.alive.common.adapter3.ResourceKey)2 ESightService (com.huawei.esight.service.ESightService)1 ESightServiceImpl (com.huawei.esight.service.ESightServiceImpl)1 MetricData (com.integrien.alive.common.adapter3.MetricData)1 MetricKey (com.integrien.alive.common.adapter3.MetricKey)1 ArrayList (java.util.ArrayList)1