/** * Set up properties for the given virtual application object representing a NetScaler loading * balance. and its discovery extension. Create the GslbServiceAgent to capture the lbvserver and * app services that are configured on this target and are bound to the specified GSLB. Also * create the transaction commodity sold by the vApp. * * @param gslb VirtualApplication for the load balancing server * @param specificTarget NetScaler appliance target * @param vServerExt NetScalerGslbVirtualAppDiscExt Discovery extension for the virtual * application * @param localName gslb server name to be set as local name in the discovery extension * @param vAppUuid UUID created for the virtual application * @param vAppType load balancing service protocol * @param classname static string "gslbvserver" to set as class name in the discovery extension * @param lbvServers list of lbvservers configured on the gslb on this target * @return modified vApp object */ private VirtualApplication createGslbVirtualApplication( VirtualApplication gslb, VMTTarget specificTarget, NetScalerGslbVirtualAppDiscExt vServerExt, String localName, String vAppUuid, String vAppType, String classname, List<String> lbvServers) { // set properties in the virtual app and the discovery extension // and create the transaction commodity sold gslb = createVirtualApplication( gslb, specificTarget, vServerExt, localName, // service name as the local name "", // there is no IP and port associated with the GSLB 0, // there is no port for the GSLB service vAppUuid, // uuid for the gslb vapp containing its service name only vAppType, // service type NetScalerUtil.GSLB_VSERVER // class name for the poller ); // agent to represent this service on this target String agentName = NetScalerUtil.GSLB_AGENT_PREFIX + gslb.getName() + "-" + target.getNameOrAddress(); GslbServiceAgent lbAgent = (GslbServiceAgent) createObject(MediationPackage.eINSTANCE.getGslbServiceAgent(), agentName); lbAgent.setDisplayName(gslb.getName() + "-" + target.getNameOrAddress()); // discovery extension for the agent NetScalerGslbServiceAgentDiscExt agentDiscExt = (NetScalerGslbServiceAgentDiscExt) lbAgent.createExtension( DiscoveryExtensionsPackage.eINSTANCE.getNetScalerGslbServiceAgentDiscExt()); // we set the GSLB server name as the local name setExtProps( agentDiscExt, specificTarget, NetScalerUtil.LB_VSERVER, // class name attribute in the extension used during polling agentName, // display name attribute in the extension localName, // local name attribute localName, // id attribute logPrefix); // attach to the vApp gslb.getAgents().add(lbAgent); agentDiscExt.getLbvServers().addAll(lbvServers); if (logger.isDebugEnabled()) logger.debug( logPrefix + gslb.toVMTString() + " : create glsb agent on target " + target.getNameOrAddress()); return gslb; }
/** * syncProbe() Called during incremental discovery Rediscover and parse the load balancing virtual * server object that is represented by the given VirtualApplication object * * @param objects List of existing VirtualApplication objects to be rediscovered */ private void syncProbe(EList<Object> objects) { if (!FeaturesManager.vmtMANAGER.isLoadBalancerEnabled()) { logger.error("Operations Manager is not licensed for Load Balancer targets"); return; } if (!objects.isEmpty() && initProbe() != null) { if (logPrefix == "") logPrefix = target.getNameOrAddress() + " : "; for (Object object : objects) { if (!(object instanceof VirtualApplication)) continue; // Get all the lbv servers from NetScaler appliance VirtualApplication vApp = (VirtualApplication) object; DiscoveryExtension discExt = vApp.getDiscoveryExtension(); if (logger.isDebugEnabled()) logger.debug(logPrefix + " rediscovering virtual application " + vApp.toVMTString()); if (discExt instanceof NetScalerVirtualAppDiscExt) { // lbvserver lbvserver server = NetScalerUtil.getLbvServer(session, vApp.getName(), target, logPrefix); if (server != null) parseServer(server); else exceptions = true; } else if (discExt instanceof NetScalerGslbVirtualAppDiscExt) { // gslb vserver gslbvserver gslb = NetScalerUtil.getGslbvServer(session, vApp.getName(), target, logPrefix); if (gslb != null) parseGslbServer(gslb); else exceptions = true; } } // If no exceptions clear previous occurrences of DISCOVERY notifications if (!exceptions) target.clearNotifications(NotificationCategory.DISCOVERY); } }
/** * syncProbe - main probe Get all the load balancing virtual server objects from NetScaler and * parse them */ private void syncProbe() { if (!FeaturesManager.vmtMANAGER.isLoadBalancerEnabled()) { logger.error("Operations Manager is not licensed for Load Balancer targets"); return; } if (initProbe() != null) { if (logPrefix == "") logPrefix = target.getNameOrAddress() + " : "; // --------- global load balancing servers // The gslb virtual servers correspond to gslb virtual server applications // Get all the gslb vservers from NetScaler appliance gslbvserver[] gslbvServers = NetScalerUtil.getAllGslbvServers(session, target, logPrefix); if (gslbvServers != null) { logger.info( logPrefix + "Retrieved " + gslbvServers.length + " instances of GSLB Virtual Application"); // Parse each server object for (gslbvserver vServer : gslbvServers) { VirtualApplication vApp = parseGslbServer(vServer); if (logger.isDebugEnabled()) logger.debug(logPrefix + " discovered GSLB virtual application " + vApp.toVMTString()); } } else { exceptions = true; } // -------------- lb vservers // The lbv servers correspond to virtual load balancing virtual server applications // Get all the lbv servers from NetScaler appliance lbvserver[] vServers = NetScalerUtil.getAllLbvServers(session, target, logPrefix); if (vServers != null) { logger.info( logPrefix + "Retrieved " + vServers.length + " instances of Virtual Application"); // Parse each server object for (lbvserver vServer : vServers) { VirtualApplication vApp = parseServer(vServer); if (vApp != null && logger.isDebugEnabled()) logger.debug(logPrefix + " discovered virtual application " + vApp.toVMTString()); } } else { exceptions = true; } // If no exceptions clear previous occurrences of DISCOVERY notifications if (!exceptions) target.clearNotifications(NotificationCategory.DISCOVERY); } } // end syncProbe()
/** * initProbe() Initialize name2Obj table - table consisting of the objects discovered * * @return VMTTarget */ @Override protected VMTTarget initProbe() { target = super.initProbe(); // initialize objects map initTables(); // open a new NetScaler session session = NetScalerUtil.createSession(target, logPrefix); if (session == null) { logger.error( logPrefix + "Could not establish a connection with target at " + target.getNameOrAddress() + ". Terminating discovery"); return null; } exceptions = false; return target; }
/** * createObject handles if the probe created an object with same UUID as another existing object * * @param ecls * @param entityName * @param entityUuid * @return VMTRootobject */ private VMTRootObject createObject(EClass ecls, String entityName, String entityUuid) { VMTRootObject obj = null; VMTRootObject newObj = null; String finalUuid = null; if (entityUuid != null) { finalUuid = REPOSMAN.hashUuid(entityUuid); } obj = name2obj.get(entityName); if (obj == null) { // this is an initial discovery, check if a different probe created an object with the same // uuid obj = REPOSMAN.getObject(finalUuid); if (obj != null) { // This object was created by a different probe if (!obj.eClass().equals(ecls)) { newObj = createObject(ecls, entityName, finalUuid + entityName); handleSameUUID( (VMTManagedEntity) obj, (VMTManagedEntity) newObj, entityName, ecls, false, VMTSeverity.MAJOR); } else { if (logger.isTraceEnabled() && obj instanceof VirtualApplication) logger.trace( target.getNameOrAddress() + "### : " + obj.toVMTString() + " already was created by another probe with uuid " + obj.getUuid()); } } else { // This is the first object created with such a uuid obj = (VMTRootObject) ecls.getEPackage().getEFactoryInstance().create(ecls); if (finalUuid != null) obj.setUuid(finalUuid); obj.setName(entityName); if (logger.isTraceEnabled() && obj instanceof VirtualApplication) logger.trace( target.getNameOrAddress() + ": created NEW object " + obj.toVMTString() + " with uuid " + obj.getUuid()); DISCMAN.incrementCount((VMTManagedEntity) obj); } } else if (!obj.eClass().equals(ecls)) { // object of a different class with the same uuid was created by this probe // newObj = createObject(ecls, entityName, finalUuid + entityName); // handleSameUUID((VMTManagedEntity)obj, (VMTManagedEntity)newObj, finalUuid, ecls, // VMTSeverity.WARNING); handleSameUUID((VMTManagedEntity) obj, null, entityName, ecls, false, VMTSeverity.MAJOR); newObj = null; } if (newObj != null) obj = newObj; name2obj.put(entityName, obj); return obj; } // end createObject()
/** * Update the Gslb Agent attached to the Gslb application that the lbvserver is bound to * * @param vServerIP */ private void updateGslbVAppAgent(String vServerIP, Integer vServerPort) { // the gslb vApp that this lbvserver is bound to VirtualApplication gslb = lbvServerVIPToGslbVAppMap.get(vServerIP); // if (logger.isDebugEnabled()) logger.info( logPrefix + "LB virtual server at VIP " + vServerIP + " on target " + target.getNameOrAddress() + " is bound to GSLB " + gslb.toVMTString()); // port for the GSLB service gslb.setPort(vServerPort); // gslb agent for this target GslbServiceAgent lbAgent = NetScalerUtil.getTargetAgent(gslb, target); if (lbAgent == null) { logger.warn("null gslb service agent for gslb " + gslb.toVMTString()); // TODO: create it ? } NetScalerGslbServiceAgentDiscExt lbAgentDiscExt = (NetScalerGslbServiceAgentDiscExt) lbAgent.getDiscoveryExtension(); Map<String, String> vipToServiceName = lbAgentDiscExt.getVipToLbServiceName(); if (vipToServiceName == null) { vipToServiceName = new HashMap<String, String>(); lbAgentDiscExt.setVipToLbServiceName(vipToServiceName); } vipToServiceName.put(vServerIP, lbvserver_ip2serviceName.get(vServerIP)); Map<String, Map<String, String>> vipToAppServices = lbAgentDiscExt.getVipToAppServices(); if (vipToAppServices == null) { vipToAppServices = new HashMap<String, Map<String, String>>(); lbAgentDiscExt.setVipToAppServices(vipToAppServices); } vipToAppServices.put(vServerIP, ip2NameIPPort); if (logger.isDebugEnabled()) { logger.debug( logPrefix + " added vipToServiceName Map : " + lbAgentDiscExt.getVipToLbServiceName() + " for " + lbAgent.toVMTString()); logger.debug( logPrefix + " added vipToAppServices Map : " + lbAgentDiscExt.getVipToAppServices() + " for " + lbAgent.toVMTString()); } // create IP objects for the app service endpoints. for (String ip : ip2NameIPPort.keySet()) { IP serviceIP = DiscoveryUtil.createOrGetIPObj(ip, logPrefix); if (logger.isDebugEnabled()) logger.debug( target.getNameOrAddress() + " created IP : " + serviceIP.toVMTString() + " for " + ip + " :: Name/IP/Port : " + ip2NameIPPort.get(ip)); } }
/** * Global load balancing virtual server and its bound services * * @param vServer * @return */ private VirtualApplication parseGslbServer(gslbvserver vServer) { if (logger.isTraceEnabled()) logger.trace(logPrefix + vServer); // Retrieve the gslb virtual server information String vServerName, vServerUuid, vServerType; try { vServerName = vServer.get_name(); // name of the loading balancing virtual server, is changeable vServerUuid = "VirtualApplicationUuid" + "_" + vServerName; // create UUID, no target address // because the same service could be configured on multiple targets vServerType = vServer.get_servicetype(); // Protocol used by the service (also called the service type) if (logger.isDebugEnabled()) logger.debug( logPrefix + "GSLB Load Balancing Server service name " + vServerName + "::service type " + vServerType + "::uuid " + vServerUuid); } catch (Exception e) { exceptions = true; logger.error( logPrefix + "Failed retrieving gslb virtual server information on target " + target.getNameOrAddress(), e); return null; } // Get the binding objects for the services bound to each load balancer virtual server on the // appliance gslbvserver_gslbservice_binding[] bindObjs = NetScalerUtil.getBoundGslbServices(session, vServerName, target, logPrefix); if (logger.isTraceEnabled()) { int length = (bindObjs == null) ? 0 : bindObjs.length; logger.trace(logPrefix + "GSLB Server " + vServerName + " has " + length + " bound services"); } List<String> lbvServers = new ArrayList<String>(); if (bindObjs != null) { try { for (gslbvserver_gslbservice_binding svcBinding : bindObjs) { // save all the lb virtual server's ip addresses configured in the gslbvserver in this // list // we will encounter the local lb virtual server while parsing the lbvServers in the // target // VIP address of the load balancing virtual server lbvServers.add(svcBinding.get_ipaddress()); } } catch (Exception ex) { exceptions = true; logger.error( logPrefix + "Failed retrieving information for services bound to gslb " + vServerName, ex); ex.printStackTrace(); } } if (logger.isDebugEnabled()) logger.debug( logPrefix + "GSLB Server " + vServerName + " has these local LB virtual server VIPs " + lbvServers); VirtualApplication gslb; NetScalerGslbVirtualAppDiscExt vServerExt; synchronized (REPOSMAN) { // Create the VirtualApplication object gslb = (VirtualApplication) createObject( AbstractionPackage.eINSTANCE.getVirtualApplication(), NetScalerUtil.VAPP_PREFIX + vServerName, vServerUuid); // create VirtualApp Discovery extension vServerExt = (NetScalerGslbVirtualAppDiscExt) gslb.createExtension( DiscoveryExtensionsPackage.eINSTANCE.getNetScalerGslbVirtualAppDiscExt()); for (String vserver : lbvServers) { // add instead of allAll, so the ones added by another target are not // overwritten if (!vServerExt.getLbvServers().contains(vserver)) vServerExt.getLbvServers().add(vserver); } if (logger.isDebugEnabled()) logger.debug( logPrefix + "GSLB Server " + vServerName + " saved LB virtual server VIPs " + vServerExt.getLbvServers()); // create a map of the lbvservers and the gslb that it is bound to on this target // we use this to determine if we need to create vApps for // lbvservers when we encounter them on this target for (String lbvServer : lbvServers) { lbvServerVIPToGslbVAppMap.put(lbvServer, gslb); } // set properties in the virtual app and the discovery extension // and create the transaction commodity sold gslb = createGslbVirtualApplication( gslb, target, vServerExt, vServerName, // service name as the local name); vServerUuid, // uuid for the gslb vapp containing its service name only vServerType, // service type NetScalerUtil.GSLB_VSERVER, // class name for the poller lbvServers // list of lbvservers configured in the gslb on this target ); } return gslb; }
/** * Validates the Flow target given by attempting to retrieve data * * @param target The target to validate * @return VALIDATED if the target was successfully validated, an error message otherwise */ public static String validateFlowTarget(VMTTarget target) { if (target != null) { String logPrefix = target.getNameOrAddress() + " : "; if (!FeaturesManager.vmtMANAGER.isNetworkModeEnabled()) { logger.warn(logPrefix + "Validation failed"); return UNLICENSED; } if ("NETFLOW".equals(target.getVersion())) { ch.ethz.ssh2.Connection conn = null; try { if (logger.isDebugEnabled()) logger.debug(logPrefix + "Validating " + target.getNameOrAddress()); VMTCredentials credentials = target.getCredentials(); if (credentials instanceof UsernamePassword) { UsernamePassword user = (UsernamePassword) credentials; String password = VMTEncryptionUtil.decrypt( credentials, MediationPackage.eINSTANCE.getUsernamePassword_Password()); conn = SshUtil.establishConnection( target.getNameOrAddress(), user.getUsername(), password); if (conn != null && conn.isAuthenticationComplete()) { Session ioSess = conn.openSession(); ioSess.execCommand(nFlowDumpCommand); return VALIDATED; } else { logger.warn(logPrefix + "Validation failed"); String reason = "Cannot establish SSH connection with the flow collector using the credential"; return reason; } } } catch (Exception e) { logger.warn(logPrefix + "Validation failed"); return e.getClass().getSimpleName(); } finally { SshUtil.closeConnection(conn, target); } } else if ("SFLOW".equals(target.getVersion())) { String targetAddress = target.getNameOrAddress(); String url = formUrl(targetAddress, SFLOW_REQUEST_IN_JSON); URL nodesURL; URLConnection nodesConnection = null; InputStreamReader in = null; try { nodesURL = new java.net.URL(url); nodesConnection = nodesURL.openConnection(); nodesConnection.connect(); in = new InputStreamReader((InputStream) nodesConnection.getContent()); if (in.ready()) return VALIDATED; else return "Cannot validate the SFLOW target"; } catch (Exception e) { return e.getMessage(); } finally { // Close the connection if (in != null) { try { in.close(); } catch (IOException e) { handleException( e, logger, "The following exception occured while attempting to close the connection"); } } } } } else { logger.warn("Null target : Validation failed"); return "TARGET IS NULL"; } return VALIDATED; // TODO: probably not the wanted behaviour }