def discoverServices(self): serviceQueryBuilder = SnmpQueryBuilder(SVC_OID_OFFSET) serviceQueryBuilder.addQueryElement(1, 'svc_name') serviceQueryBuilder.addQueryElement(3, 'ip') serviceQueryBuilder.addQueryElement(4, 'protocol') serviceQueryBuilder.addQueryElement(5, 'port') serviceQueryBuilder.addQueryElement(41, 'ip_range') serviceQueryBuilder.addQueryElement(42, 'port_range') snmpRowElements = self.snmpAgent.getSnmpData(serviceQueryBuilder) poolMemberToPoolQueryBuilder = SnmpQueryBuilder(CNTSVC_OID_OFFSET) poolMemberToPoolQueryBuilder.addQueryElement(2, 'cnt_name') poolMemberToPoolQueryBuilder.addQueryElement(3, 'svc_name') poolMemberToPoolElements = self.snmpAgent.getSnmpData( poolMemberToPoolQueryBuilder) svcToCntMap = {} for poolMemberToPoolElement in poolMemberToPoolElements: cnt = self.resourcePools[poolMemberToPoolElement.cnt_name] cntList = svcToCntMap.get(poolMemberToPoolElement.svc_name, []) cntList.append(cnt) svcToCntMap[poolMemberToPoolElement.svc_name] = cntList for snmpRowElement in snmpRowElements: poolMember = modeling.createHostOSH(snmpRowElement.ip, 'host_node') # KB specific: fix of port translations serviceAddressPort = snmpRowElement.port serviceAddress = modeling.createServiceAddressOsh( poolMember, snmpRowElement.ip, serviceAddressPort, CNT_PROTOCOL_MAP[snmpRowElement.protocol]) self.OSHVResult.add(poolMember) if svcToCntMap.has_key(snmpRowElement.svc_name): cntList = svcToCntMap[snmpRowElement.svc_name] for cnt in cntList: # KB specific: if there is not any port translation between the input and output IPs ports, create the same port destinationPort = serviceAddressPort destinationAddress = serviceAddress if destinationPort == '0': inputServiceAddress = self.resourcePoolsToServiceAddress[ cnt.getAttributeValue('data_name')] destinationPort = inputServiceAddress.getAttributeValue( 'ipport_number') destinationAddress = modeling.createServiceAddressOsh( poolMember, snmpRowElement.ip, destinationPort, CNT_PROTOCOL_MAP[snmpRowElement.protocol]) self.OSHVResult.add(destinationAddress) self.OSHVResult.add( modeling.createLinkOSH('member', cnt, destinationAddress)) else: self.OSHVResult.add(serviceAddress) errobj = errorobject.createError( errorcodes.NO_SERVICE_FOUND_FOR_NODE, [snmpRowElement.svc_name], 'No service found for destination node') logger.reportWarningObject(errobj)
def DiscoveryMain(Framework): vector = ObjectStateHolderVector() knownPortsConfigFile = Framework.getConfigFile(CollectorsParameters.KEY_COLLECTORS_SERVERDATA_PORTNUMBERTOPORTNAME) endpoint = Framework.getDestinationAttribute('ip_port_pair') address, port = endpoint.rsplit(':', 1) endpoint = netutils.createTcpEndpoint(address, port) ipServiceName = Framework.getDestinationAttribute('ip_service_name') if ipServiceName == 'sap_jmx': endpoint = convertToHttpEndpoint(endpoint) if endpoint: logger.debug('Current %s' % endpoint) vector, errors, warnings = _discover(Framework, knownPortsConfigFile, endpoint) logger.debug('Result vector size: %d' % vector.size()) logger.debug('Errors: %s' % errors) logger.debug('Warnings: %s' % warnings) fptools.each(logger.reportErrorObject, errors) fptools.each(logger.reportWarningObject, warnings) else: protocolName = 'sapjmxprotocol' protocolLabel = errormessages.protocolNames[protocolName] messagePattern = errormessages.NO_HTTP_ENDPOINTS_TO_PROCESS_ERROR msg = errormessages.makeErrorMessage(protocolName, pattern=messagePattern) errCode = errorcodes.NO_HTTP_ENDPOINTS_TO_PROCESS errobj = errorobject.createError(errCode, [protocolLabel], msg) logger.reportWarningObject(errobj) return vector
def getMAC(shell, int_name): cmdResult = None rawCmdResult = None mac = None entstat = None try: entstat_command = concatenate('entstat ', int_name) logger.debug(concatenate(' Executing command: ', entstat_command)) entstat = shell.execCmd(entstat_command) if entstat != None: m = re.search('Device Type: (.+)', entstat) description = None if(m): description = m.group(1).strip() m = re.search('Hardware Address: ([0-9a-f:]{17})', entstat) rawMac = None if(m): rawMac = m.group(1) mac = netutils.parseMac(rawMac) except: msg = " Failed getting MAC address for interface '%s'" % int_name errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return None return mac
def iterate_over_creds(main_fn, proto_name, stop_on_first=True, is_cred_ok_fn=identity): ''' Decorator for the DiscoveryMain function in case when connection attempts performed over available protocols @param main_fn: DiscoveryMain function reference @param proto_name: protocol to connect with @param stop_on_first: Stop on first successful discovery @param is_cred_ok_fn: predicate to check whether credentials are suitable Signature is (Framework, CredsManager, str -> bool) Usage: from fptools import paritallyApply as Fn, _ as __ @Fn(iterate_over_creds, __, ClientsConsts.SSH_PROTOCOL_NAME) def DiscoveryMain(rich_framework, creds_manager, cred_id): '@types: Framework, CredsManager, str -> list[osh], list[str]' ... return oshs, warnings ''' @wraps(main_fn) def decorator(framework): vector = ObjectStateHolderVector() framework = RichFramework(framework) creds_manager = CredsManager(framework) creds = creds_manager.get_creds_for_destination(proto_name) creds = filter(Fn(is_cred_ok_fn, framework, creds_manager, __), creds) if not creds: logger.reportErrorObject(_create_missed_creds_error(proto_name)) else: connection_exs = [] discovery_exs = [] warnings = [] at_least_once_discovered = False for cred_id in creds: try: oshs, warnings = main_fn(framework, creds_manager, cred_id) vector.addAll(oshs) at_least_once_discovered = True if stop_on_first: break except ConnectionException, ce: logger.debugException(str(ce)) connection_exs.append(ce) except (DiscoveryException, Exception, JException), de: logger.debugException(str(de)) discovery_exs.append(de) if at_least_once_discovered: if warnings: each(logger.reportWarning, warnings) else: for ex in connection_exs: obj = _create_connection_errorobj(proto_name, ex.message) logger.reportWarningObject(obj) for ex in discovery_exs: obj = _create_discovery_errorobj(proto_name, ex.message) logger.reportErrorObject(obj)
def getMAC(shell, int_name): cmdResult = None rawCmdResult = None mac = None entstat = None try: entstat_command = concatenate('entstat ', int_name) logger.debug(concatenate(' Executing command: ', entstat_command)) entstat = shell.execCmd(entstat_command) if entstat != None: m = re.search('Device Type: (.+)', entstat) description = None if (m): description = m.group(1).strip() m = re.search('Hardware Address: ([0-9a-f:]{17})', entstat) rawMac = None if (m): rawMac = m.group(1) mac = netutils.parseMac(rawMac) except: msg = " Failed getting MAC address for interface '%s'" % int_name errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return None return mac
def discoverDnsZoneTopologies(dnsDiscoverer, zoneList, protocolName): r'''DnsDiscoverer, seq[str], str -> seq[_ZoneTopology] @note: make error reporting to the UI ''' topologies = [] try: zoneList = zoneList and map(dns.Zone, zoneList) zones = zoneList or dnsDiscoverer.listZones() isError = 0 for zone in zones: if (dns.isLocalhostZone(zone) or dns.isReverseZone(zone) or dns.isRootZone(zone)): continue topology = ZoneTopology(zone) try: logger.debug('transfer zone: %s' % zone) types = ( RecordType.A, # IPv4 address RecordType.CNAME, # Alias RecordType.AAAA) # IPv6 address records = dnsDiscoverer.transferZone(zone, *types) topology.records.extend(records) except dns.DiscoveryException, dde: logger.warn('Failed to transfer zone "%s"' % zone) logger.debugException(str(dde)) isError = 1 else: topologies.append(topology) if isError: errCode = errorcodes.FAILED_TRANSFER_DNS_ZONE message = "Failed to transfer zone records for one or more zones" errobj = errorobject.createError(errCode, [protocolName], message) logger.reportWarningObject(errobj)
def _logWarn(errorCode, params, errorMessage): 'int, list(str), str -> None' if not (modeling.CmdbClassModel().version() >= 9.0): errorMessage = errormessages.makeErrorMessage(params[1].upper(), params[0], errormessages.ERROR_DISCOVERY_BY_PROTOCOL) logger.debugException(errorMessage) errobj = errorobject.createError(errorCode, params, errorMessage) logger.reportWarningObject(errobj)
def discoverDnsZoneTopologies(dnsDiscoverer, zoneList, protocolName): r'''DnsDiscoverer, seq[str], str -> seq[_ZoneTopology] @note: make error reporting to the UI ''' topologies = [] try: zoneList = zoneList and map(dns.Zone, zoneList) zones = zoneList or dnsDiscoverer.listZones() isError = 0 for zone in zones: if (dns.isLocalhostZone(zone) or dns.isReverseZone(zone) or dns.isRootZone(zone)): continue topology = ZoneTopology(zone) try: logger.debug('transfer zone: %s' % zone) types = (RecordType.A, # IPv4 address RecordType.CNAME, # Alias RecordType.AAAA) # IPv6 address records = dnsDiscoverer.transferZone(zone, *types) topology.records.extend(records) except dns.DiscoveryException, dde: logger.warn('Failed to transfer zone "%s"' % zone) logger.debugException(str(dde)) isError = 1 else: topologies.append(topology) if isError: errCode = errorcodes.FAILED_TRANSFER_DNS_ZONE message = "Failed to transfer zone records for one or more zones" errobj = errorobject.createError(errCode, [protocolName], message) logger.reportWarningObject(errobj)
def reportToFramework(self, framework): cfg = self.errConfig errobj = errorobject.createError(cfg.errorCode, self.params, self.msg) if cfg.isWarn(): logger.reportWarningObject(errobj) elif cfg.isError(): logger.reportErrorObject(errobj)
def discoverExchangeServer(wmiAgent, ipAddress, credentialsId, OSHVResult, Framework, hostOsh, hostName): queryBuilder = WmiQueryBuilder('Exchange_Server') queryBuilder.addWmiObjectProperties('FQDN', 'GUID', 'Type', 'MTADataPath', 'CreationTime', 'ExchangeVersion', 'MonitoringEnabled', 'AdministrativeNote', 'MessageTrackingEnabled', 'MessageTrackingLogFilePath', 'MessageTrackingLogFileLifetime') queryBuilder.addWhereClause('Name = \'%s\'' % hostName) Exchange_Servers = wmiAgent.getWmiData(queryBuilder) if len(Exchange_Servers) == 0: errobj = errorobject.createError(errorcodes.EMPTY_DATA_RECEIVED, ['Exchange servers', 'WMI'], 'No Exchange servers available via WMI') logger.reportWarningObject(errobj) return for Exchange_Server in Exchange_Servers: exchangeServerOsh = modeling.createExchangeServer(hostOsh, ipAddress, credentialsId, ms_exchange_utils.VERSION_2003) exchangeServerOsh.setAttribute('guid', extractId(Exchange_Server.GUID)) exchangeServerOsh.setAttribute('fqdn', Exchange_Server.FQDN) exchangeServerOsh.setAttribute('application_version_number', ms_exchange_utils.VERSION_2003) exchangeServerOsh.setAttribute('build_number', Exchange_Server.ExchangeVersion) exchangeServerOsh.setAttribute('data_description', Exchange_Server.AdministrativeNote) exchangeServerOsh.setAttribute('mta_data_path', Exchange_Server.MTADataPath) exchangeServerOsh.setBoolAttribute('is_monitoring_enabled', Exchange_Server.MonitoringEnabled) exchangeServerOsh.setAttribute('log_file_path', Exchange_Server.MessageTrackingLogFilePath) exchangeServerOsh.setBoolAttribute('message_tracking_enabled', Exchange_Server.MessageTrackingEnabled) exchangeServerOsh.setIntegerAttribute('log_file_lifetyme', Exchange_Server.MessageTrackingLogFileLifetime) exchangeServerOsh.setDateAttribute('creation_date', parseDate(Exchange_Server.CreationTime)) exchangeServerOsh.setAttribute('type', SERVER_TYPES[Exchange_Server.Type]) OSHVResult.add(hostOsh) OSHVResult.add(exchangeServerOsh)
def DiscoveryMain(Framework): ipAddress = Framework.getDestinationAttribute('ip_address') shell = None try: client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) f5Discoverer = createF5Discoverer(shell, ipAddress) f5Discoverer.discover() return f5Discoverer.getTopology() except NoF5Exception: logger.reportWarning("No F5 LTM found on the remote machine") except: errorMsg = 'Failed to get general information' errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['shell', 'general information'], errorMsg) logger.debugException(errorMsg) logger.reportWarningObject(errobj) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell')
def doQuery(self, queryStr): cmdRemoteAgent = self.DEFAULT_REG_TOOL + queryStr ntcmdErrStr = 'Remote command returned 1(0x1)' timeout = 180000 buffer = self.shell.execCmd(cmdRemoteAgent, timeout) # @@CMD_PERMISION ntcmd protocol execution logger.debug('Outputing ', cmdRemoteAgent, ': ...') reg_mamRc = self.shell.getLastCmdReturnCode() if (reg_mamRc != 0) or (buffer.find(ntcmdErrStr) != -1): logger.debug('reg ended unsuccessfully with return code:%d, error:%s' % (reg_mamRc, buffer)) logger.debug('Failed getting services info using reg.exe trying the reg_mam.exe') localFile = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder() + CollectorsParameters.FILE_SEPARATOR + self.REG_MAM_REG_TOOL remoteFile = self.shell.copyFileIfNeeded(localFile) cmdRemote = self.REG_MAM_REG_TOOL if not remoteFile: logger.warn('Failed copying %s' % cmdRemote) return cmdRemoteAgent = remoteFile + queryStr buffer = self.shell.execCmd(cmdRemoteAgent, timeout) # @@CMD_PERMISION ntcmd protocol execution regRc = self.shell.getLastCmdReturnCode() if (regRc != 0) or (buffer.find(ntcmdErrStr) != -1): errMessage = 'NTCMD: Failed getting services info.' errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['NTCMD', 'services info'], errMessage) logger.reportWarningObject(errobj) logger.debug('Failed getting services info, reg_mam.exe ended with %d, error:%s' % (regRc, buffer)) return return buffer
def decorator_fn(original_fn): @wraps(original_fn) def wrapper(framework): client_factories_provider = kwargs.get('client_factories_provider') if not client_factories_provider: client_factories_provider = default_client_factories_provider proto_name = kwargs.get('protocol_name') stop_on_first = kwargs.get('stop_on_first') vector = ObjectStateHolderVector() framework = RichFramework(framework) if not proto_name: proto_name = framework.get_dest_attribute('Protocol') creds_manager = CredsManager(framework) client_factories = client_factories_provider(framework, creds_manager) first_factory = take(0, 1, client_factories) if not first_factory: logger.reportErrorObject(_create_missed_creds_error(proto_name)) else: connection_exs = [] discovery_exs = [] warnings = [] at_least_once_discovered = False oshs = [] client_factories = list(itertools.chain(first_factory, client_factories)) main_fn = original_fn for index, client_factory in enumerate(client_factories): try: with client_factory() as client: args_ = (framework, client, index) kwargs_ = {} oshs_, warnings_ = main_fn(*args_, **kwargs_) oshs.extend(oshs_) warnings.extend(warnings_) at_least_once_discovered = True if stop_on_first: break except ConnectionException, ce: logger.debugException(str(ce)) connection_exs.append(ce) except (DiscoveryException, Exception), de: logger.debugException(str(de)) discovery_exs.append(de) if at_least_once_discovered: each(logger.reportWarningObject, warnings) else: for ex in connection_exs: obj = _create_connection_errorobj(proto_name, ex.message) logger.reportWarningObject(obj) for ex in discovery_exs: obj = _create_discovery_errorobj(proto_name, ex.message) logger.reportErrorObject(obj) vector.addAll(oshs)
def processTCPResult(self): status = self.processTCPCmdResult() if status == TCPDisByLSOFableShell.LSOF_WRONG_VERSION_ERROR: message = 'It appears like lsof on destination %s does not work properly(wrong version?). Runs it with lsof disabled' % self.client.getIpAddress() logger.debug(message) errobj = errorobject.createError(errorcodes.LSOF_WRONG_VERSION, [self.client.getIpAddress()], message) logger.reportWarningObject(errobj) self.discoverTCPnoLSOF()
def getClusterVersion(shell, hostOS, AIX_ClusterPackageName): try: packageInfoCmd = None packageInfoStr = None version = None if (hostOS == 'NA'): rawCmdResult = shell.execCmd('uname') if (re.search('aix', rawCmdResult.lower())): hostOS = 'aix' else: raise ValueError, "OS type not found; unable to build command for query package version" else: hostOS = hostOS.lower().strip() ## Build the correct command based on platform if hostOS == 'aix': packageInfoCmd = concatenate('lslpp -l ', AIX_ClusterPackageName) else: return None ## Run the package query for HACMP version logger.debug(concatenate(' Executing command: ', packageInfoCmd)) packageInfoStr = shell.execCmd(packageInfoCmd) # Sample Output # cluster.license 5.4.0.0 COMMITTED HACMP Electronic License result = packageInfoStr.strip() ## Parse the result keywords = [ 'No package provides', 'No such file or directory', 'not installed', 'Error:' ] for keyword in keywords: if re.search(keyword, result, re.I): return None version = None lines = result.split('\n') for line in lines: m = re.search('^\s*\S+\s+(\d+[^ ]+)\s', line) if (m): version = m.group(1) logger.debug(concatenate(' Cluster package version: ', version)) break except: msg = "Could not execute Package Info Command " errobj = errorobject.createError( errorcodes.COMMAND_OUTPUT_VERIFICATION_FAILED, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return None return version
def _logWarn(errorCode, params, errorMessage): 'int, list(str), str -> None' if not (modeling.CmdbClassModel().version() >= 9.0): errorMessage = errormessages.makeErrorMessage( params[1].upper(), params[0], errormessages.ERROR_DISCOVERY_BY_PROTOCOL) logger.debugException(errorMessage) errobj = errorobject.createError(errorCode, params, errorMessage) logger.reportWarningObject(errobj)
def parseLSOFListen(self, line, listenIpPorts): try: IpPortIpPortStatusListenArray = None protocol = modeling.TCP_PROTOCOL protocolName = 'tcp' try: IpPortIpPortStatusListenArray = re.search(self.TCPRegExp, line) if IpPortIpPortStatusListenArray != None: linkStatus = IpPortIpPortStatusListenArray.group(3) if linkStatus.find(self.LISTEN_str) == -1: return TCPDiscovery.OK except: return TCPDiscovery.OK if (IpPortIpPortStatusListenArray == None) and (self.UDPRegExp != None): try: IpPortIpPortStatusListenArray = re.search(self.UDPRegExp, line) protocol = modeling.UDP_PROTOCOL protocolName = 'udp' except: return TCPDiscovery.OK if IpPortIpPortStatusListenArray == None: return TCPDiscovery.OK pid = IpPortIpPortStatusListenArray.group(1) listenipPort = IpPortIpPortStatusListenArray.group(2) ip = listenipPort.split(':')[0] if not self.isIpv4(ip): logger.debug ('Skipping not valid IPv4 address %s' % ip) return TCPDiscovery.OK if not ip_addr.isValidIpAddress(ip) and not str(ip).startswith('0.'): errorMessage = 'On parsing listen ports by lsof for protocol ' + protocolName + ' extracted invalid ip:<' + ip + '>' logger.warn(errorMessage) errobj = errorobject.createError(errorcodes.IP_PARSING_ERROR, [protocolName, ip, 'On parsing listen ports by lsof'], errorMessage) logger.reportWarningObject(errobj) return TCPDiscovery.OK #if ip_addr.IPAddress(ip).get_is_loopback(): # return TCPDiscovery.OK port = listenipPort.split(':')[1] #sometimes we get on UDP something like this: #postmaste 2412 sfmdb 7u IPv4 0xe00000015f8ed100 0t0 UDP 127.0.0.1:49176->127.0.0.1:49176 #in this case split by ':' brings us at port 49176->127.0.0.1 port = re.search('\d+',port).group(0) #this is TCP port and we add it to port_process table for future connections discovery self._addTcpData(ip, port, pid, 1, protocol, listenIpPorts = listenIpPorts) return TCPDiscovery.OK except: logger.errorException('parseLSOFListen:failed to process TCP entry: ', line) return TCPDiscovery.ERROR
def getClusterVersion(shell, hostOS, AIX_ClusterPackageName): try: packageInfoCmd = None packageInfoStr = None version = None if (hostOS == 'NA'): rawCmdResult = shell.execCmd('uname') if (re.search('aix', rawCmdResult.lower())): hostOS = 'aix' else: raise ValueError, "OS type not found; unable to build command for query package version" else: hostOS = hostOS.lower().strip() ## Build the correct command based on platform if hostOS == 'aix': packageInfoCmd = concatenate('lslpp -l ', AIX_ClusterPackageName) else: return None ## Run the package query for HACMP version logger.debug(concatenate(' Executing command: ', packageInfoCmd)) packageInfoStr = shell.execCmd(packageInfoCmd) # Sample Output # cluster.license 5.4.0.0 COMMITTED HACMP Electronic License result = packageInfoStr.strip() ## Parse the result keywords = ['No package provides', 'No such file or directory', 'not installed', 'Error:'] for keyword in keywords: if re.search(keyword,result,re.I): return None version = None lines = result.split('\n') for line in lines: m = re.search('^\s*\S+\s+(\d+[^ ]+)\s', line) if (m): version = m.group(1) logger.debug(concatenate(' Cluster package version: ', version)) break except: msg = "Could not execute Package Info Command " errobj = errorobject.createError(errorcodes.COMMAND_OUTPUT_VERIFICATION_FAILED, None, msg) logger.reportWarningObject(errobj) logger.debug(msg) return None return version
def processTCPResult(self): status = self.processTCPCmdResult() if status == TCPDisByLSOFableShell.LSOF_WRONG_VERSION_ERROR: message = 'It appears like lsof on destination %s does not work properly(wrong version?). Runs it with lsof disabled' % self.client.getIpAddress( ) logger.debug(message) errobj = errorobject.createError(errorcodes.LSOF_WRONG_VERSION, [self.client.getIpAddress()], message) logger.reportWarningObject(errobj) self.discoverTCPnoLSOF()
def doExchangeSystem(self, fqdn): queryBuilder = WmiQueryBuilder('Exchange_Server') queryBuilder.addWmiObjectProperties('Name', 'FQDN', 'DN', 'RoutingGroup', 'AdministrativeGroup') Exchange_Servers = self.wmiAgent.getWmiData(queryBuilder) if len(Exchange_Servers) == 0: errobj = errorobject.createError( errorcodes.EMPTY_DATA_RECEIVED, ['Exchange servers', 'WMI'], 'No Exchange servers available via WMI') logger.reportWarningObject(errobj) return for Exchange_Server in Exchange_Servers: ''' In case host name was not determined earlier, try to obtain it using Exchange_Server.FQDN property ''' if not self.exchangeServerName and fqdn == Exchange_Server.FQDN: self.exchangeServerName = Exchange_Server.Name exchangeSystemOsh = ObjectStateHolder('exchangesystem') exchangeSystemOsh.setAttribute( 'data_name', extractOrganizationNameFromDn(Exchange_Server.DN)) modeling.setAppSystemVendor(exchangeSystemOsh) self.add(exchangeSystemOsh) administrativeGroupOsh = ObjectStateHolder( 'exchange_administrative_group') administrativeGroupOsh.setAttribute( 'data_name', Exchange_Server.AdministrativeGroup) administrativeGroupOsh.setContainer(exchangeSystemOsh) self.add(administrativeGroupOsh) routingGroupOsh = ObjectStateHolder('routing_group') routingGroupOsh.setAttribute('data_name', Exchange_Server.RoutingGroup) routingGroupOsh.setContainer(administrativeGroupOsh) self.add(routingGroupOsh) if self.exchangeServerName and self.exchangeServerName.lower( ) == Exchange_Server.Name.lower(): self.add( modeling.createLinkOSH('member', administrativeGroupOsh, self.exchangeServerOsh)) self.add( modeling.createLinkOSH('member', routingGroupOsh, self.exchangeServerOsh)) self.add( modeling.createLinkOSH('member', exchangeSystemOsh, self.exchangeServerOsh)) self.exchangeSystemOsh = exchangeSystemOsh
def discoverServices(self): serviceQueryBuilder = SnmpQueryBuilder(SVC_OID_OFFSET) serviceQueryBuilder.addQueryElement(1, 'svc_name') serviceQueryBuilder.addQueryElement(3, 'ip') serviceQueryBuilder.addQueryElement(4, 'protocol') serviceQueryBuilder.addQueryElement(5, 'port') serviceQueryBuilder.addQueryElement(41, 'ip_range') serviceQueryBuilder.addQueryElement(42, 'port_range') snmpRowElements = self.snmpAgent.getSnmpData(serviceQueryBuilder) poolMemberToPoolQueryBuilder = SnmpQueryBuilder(CNTSVC_OID_OFFSET) poolMemberToPoolQueryBuilder.addQueryElement(2, 'cnt_name') poolMemberToPoolQueryBuilder.addQueryElement(3, 'svc_name') poolMemberToPoolElements = self.snmpAgent.getSnmpData(poolMemberToPoolQueryBuilder) svcToCntMap = {} for poolMemberToPoolElement in poolMemberToPoolElements: cnt = self.resourcePools[poolMemberToPoolElement.cnt_name] cntList = svcToCntMap.get(poolMemberToPoolElement.svc_name, []) cntList.append(cnt) svcToCntMap[poolMemberToPoolElement.svc_name] = cntList for snmpRowElement in snmpRowElements: poolMember = modeling.createHostOSH(snmpRowElement.ip, 'host_node') # KB specific: fix of port translations serviceAddressPort = snmpRowElement.port serviceAddress = modeling.createServiceAddressOsh(poolMember, snmpRowElement.ip, serviceAddressPort, CNT_PROTOCOL_MAP[snmpRowElement.protocol]) self.OSHVResult.add(poolMember) if svcToCntMap.has_key(snmpRowElement.svc_name): cntList = svcToCntMap[snmpRowElement.svc_name] for cnt in cntList: # KB specific: if there is not any port translation between the input and output IPs ports, create the same port destinationPort = serviceAddressPort destinationAddress = serviceAddress if destinationPort == '0': inputServiceAddress = self.resourcePoolsToServiceAddress[cnt.getAttributeValue('data_name')] destinationPort = inputServiceAddress.getAttributeValue('ipport_number') destinationAddress = modeling.createServiceAddressOsh(poolMember, snmpRowElement.ip, destinationPort, CNT_PROTOCOL_MAP[snmpRowElement.protocol]) self.OSHVResult.add(destinationAddress) self.OSHVResult.add(modeling.createLinkOSH('member', cnt, destinationAddress)) else: self.OSHVResult.add(serviceAddress) errobj = errorobject.createError(errorcodes.NO_SERVICE_FOUND_FOR_NODE, [snmpRowElement.svc_name], 'No service found for destination node') logger.reportWarningObject(errobj)
def DiscoveryMain(Framework): ip = Framework.getDestinationAttribute('ip_address') domain = Framework.getDestinationAttribute('ip_domain') codepage = Framework.getCodePage() shell = None credentialId = None OSHVResult = None warningsList = [] errorsList = [] protocolType = PowerShell.PROTOCOL_TYPE credentials = [] # use the latest used credentials if any lastConnectedCredential = Framework.loadState() lastConnectedCredential and credentials.append(lastConnectedCredential) # and other defined for triggered IP credentials.extend( netutils.getAvailableProtocols(Framework, protocolType, ip, domain)) if credentials: shell, credentialId = getShellUtils(Framework, protocolType, credentials, ip, codepage, warningsList, errorsList) else: msg = errormessages.makeErrorMessage( protocolType, pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError( errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolType], msg) errorsList.append(errobj) if shell: # successfully connected, do discovery errorsList = [] warningsList = [] Framework.saveState(credentialId) OSHVResult = doDiscovery(Framework, shell, ip, credentialId, codepage, protocolType, warningsList, errorsList) else: if not len(errorsList): msg = errormessages.makeErrorMessage( protocolType, pattern=errormessages.ERROR_CONNECTION_FAILED) errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolType], msg) errorsList.append(errobj) Framework.clearState() for errobj in warningsList: logger.reportWarningObject(errobj) for errobj in errorsList: logger.reportErrorObject(errobj) return OSHVResult
def reportErrorMessage(self): '''Join all messages into one big message and report it as error or if no registered - report error "Tried all protocols" ''' if len(self.errorMsg) > 0: errorResult = '' for error in self.errorMsg: errorResult = errorResult + '\n' + str(error) errobj = errorobject.createError(errorcodes.CONNECTION_FAILED_WITH_DETAILS, [str(self.getJ2eeServerType()), errorResult], errorResult) else: errobj = errorobject.createError(errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS, ['Tried all protocols'], 'Failed to connect using all protocols') logger.reportWarningObject(errobj)
def disLinux(host_obj, client, Framework = None, langBund = None, packageToCmdLine = None, pid2Process = None): hostId = Framework.getDestinationAttribute('hostId') protocol = Framework.getDestinationAttribute('Protocol') discoverProcesses = Boolean.parseBoolean(Framework.getParameter('discoverProcesses')) myVec = ObjectStateHolderVector() timezone = None try: timezone = getTimezone(client) except ValueError, ex: msg = str(ex) errobj = errormessages.resolveError(msg, 'shell') logger.reportWarningObject(errobj)
def executeWmiQuery(wmiClient, Framework, vector, nodeOsh = None): '''WmiClient, Framework, oshVector -> None @deprecated use hostresources_win_wmi instead ''' try: containerOSH = nodeOsh or modeling.createHostOSH(wmiClient.getIpAddress()) wmiProvider = WmiAgentProvider(wmiClient) domainName = _getDomainName(wmiProvider) userResources = UserDiscoverer(wmiProvider).discoverByDomain(domainName) userResources.build(containerOSH) vector.addAll( userResources.report() ) except HostResourceDiscoveryException, hrde: errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION_NO_PROTOCOL, ['User discovery'], str(hrde)) logger.reportWarningObject(errobj)
def clientDiscovery(Framework, ip): (vec, errObj) = mainFunction(Framework, 1, ip) logger.debug('OSHVector contains ', vec.size(), ' objects.') if vec.size() == 0: logger.debug('Failed to connect or no valid protocols defined. No Host CI will be created') if (errObj == None or errObj.errMsg == None or errObj.errMsg.strip() == ''): altErr = errorobject.createError(errorcodes.INTERNAL_ERROR ,None , 'Discovery failed due to internal error') logger.reportErrorObject(altErr) else: logger.reportWarningObject(errObj) else: Framework.sendObjects(vec) Framework.flushObjects() return None
def discoverA10_vthunder(self, a10_vthunder): queryBuilder = SnmpQueryBuilder(A10_OID_SYS) queryBuilder.addQueryElement(1, 'PrimaryVersion') queryBuilder.addQueryElement(2, 'SecondaryVersion') try: versionInformation = self.snmpAgent.getSnmpData(queryBuilder)[0] a10_vthunder.setAttribute('application_version', versionInformation.PrimaryVersion) except: errorMsg = 'Failed to get general information' errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['snmp', 'general information'], errorMsg) logger.debugException(errorMsg) logger.reportWarningObject(errobj) self.discoverVirtualServers(a10_vthunder)
def parseTcpListenPorts(self, line, listenIpPorts): linkStatus = '' try: IpPortIpPortStatusListenArray = None protocol = modeling.TCP_PROTOCOL protocolName = 'tcp' try: IpPortIpPortStatusListenArray = re.compile(self.TCPRegExp).search(line) if IpPortIpPortStatusListenArray != None: linkStatus = IpPortIpPortStatusListenArray.group(5).upper() if (linkStatus.find(self.LISTEN_str) == -1) and (linkStatus.find("LISTEN") == -1): return TCPDiscovery.OK except: return TCPDiscovery.OK if (IpPortIpPortStatusListenArray == None) and (self.UDPRegExp != None) and (len(self.UDPRegExp) > 0): try: IpPortIpPortStatusListenArray = re.search(self.UDPRegExp, line) if (IpPortIpPortStatusListenArray != None) and len(IpPortIpPortStatusListenArray.groups()) == 3: linkStatus = IpPortIpPortStatusListenArray.group(3) protocol = modeling.UDP_PROTOCOL protocolName = 'udp' except: return TCPDiscovery.OK if IpPortIpPortStatusListenArray == None: return TCPDiscovery.OK ip = self.__parseIpv6(IpPortIpPortStatusListenArray.group(1)) port = IpPortIpPortStatusListenArray.group(2) if not ip_addr.isValidIpAddress(ip): errorMessage = 'On parsing listen ports by netstat for protocol ' + protocolName + ' extracted invalid ip:<' + ip + '>' logger.warn(errorMessage) errobj = errorobject.createError(errorcodes.IP_PARSING_ERROR, [protocolName, ip, 'On parsing listen ports by netstat'], errorMessage) logger.reportWarningObject(errobj) return TCPDiscovery.OK #if ip_addr.IPAddress(ip).get_is_loopback(): # return TCPDiscovery.OK pid = self.getPid(linkStatus) self._addTcpData(ip, port, pid, 1, protocol, listenIpPorts = listenIpPorts) return TCPDiscovery.OK except: logger.errorException('parseTcpListenPorts:failed to process TCP entry: ', line) return TCPDiscovery.ERROR
def DiscoveryMain(Framework): # get attribute shell = None client = None OSHVResult = ObjectStateHolderVector() try: ip = reportIpAddress(Framework, OSHVResult) # do host connection client, shell, warningsList, errorsList, hostOsh = host_connection.doConnection(Framework, ip, OSHVResult) if not (client and shell): logger.debug("host connection failed") for errobj in warningsList: logger.reportWarningObject(errobj) for errobj in errorsList: logger.reportErrorObject(errobj) return OSHVResult # do host application runningApplications, processes, connectivityEndPoints, connections, errorsList = host_application.doApplication( Framework, ip, OSHVResult, client, shell, hostOsh) if not (runningApplications and processes and connectivityEndPoints and connections): logger.debug("host application failed") for errobj in errorsList: logger.reportErrorObject(errobj) return OSHVResult # do next hop next_hop.doNextHop(Framework, ip, OSHVResult, shell, runningApplications, processes, connectivityEndPoints, connections, hostOsh) finally: #close connection if shell: try: shell.closeClient() except: logger.warnException('Client was not closed properly') # close client anyway if client and client.close(): pass return OSHVResult
def DiscoveryMain(Framework): vector = ObjectStateHolderVector() (vec, warnList, errList) = WMI_Connection_Utils.mainFunction(Framework) logger.debug('OSHVector contains ', vec.size(), ' objects.') # just in case we couldnt do any connection if vec.size() == 0: for errobj in errList: logger.reportErrorObject(errobj) for errobj in warnList: logger.reportWarningObject(errobj) else: vector.addAll(vec) return vector
def DiscoveryMain(Framework): vector = ObjectStateHolderVector() codePage = Framework.getCodePage() props = Properties() props.setProperty(BaseAgent.ENCODING, codePage) shell = None try: client = Framework.createClient(props) shell = shellutils.ShellFactory().createShell(client) dnsResolver = dns_resolver.NsLookupDnsResolver(shell) language = shell.osLanguage logger.debug("Using '%s' language bundle" % language.bundlePostfix) bundle = shellutils.getLanguageBundle('langMsCluster', language, Framework) clusterCmd = ms_cluster_discoverer.createClusterCmd(shell, bundle) if clusterCmd.isUsingCmd(): bundle = clusterCmd.detectLangBandle(Framework) clusterCmd.setBundle(bundle) vector.addAll(_discoverTopology(clusterCmd, bundle, dnsResolver)) except NoInstanceFound: errobj = errorobject.createError( errorcodes.MS_CLUSTER_INSTANCES_NOT_FOUND, None, 'MS cluster instances not found in discovery') logger.reportWarningObject(errobj) except: msg = str(sys.exc_info()[1]) logger.debugException(msg) if (msg.lower().find('timeout') > -1): errobj = errorobject.createError( errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL, None, 'Connection timed out - reactivate with larger timeout value') logger.reportErrorObject(errobj) logger.debugException('Connection timed out') else: errobj = errormessages.resolveError(msg, 'ntcmd') logger.reportErrorObject(errobj) logger.errorException(msg) try: shell and shell.closeClient() except: logger.debugException() logger.error("Unable to close shell") return vector
def DiscoveryMain(Framework): ip = Framework.getDestinationAttribute('ip_address') domain = Framework.getDestinationAttribute('ip_domain') codepage = Framework.getCodePage() shell = None credentialId = None OSHVResult = None warningsList = [] errorsList = [] protocolType = PowerShell.PROTOCOL_TYPE credentials = [] # use the latest used credentials if any lastConnectedCredential = Framework.loadState() lastConnectedCredential and credentials.append(lastConnectedCredential) # and other defined for triggered IP credentials.extend(netutils.getAvailableProtocols(Framework, protocolType, ip, domain)) if credentials: shell, credentialId = getShellUtils(Framework, protocolType, credentials, ip, codepage, warningsList, errorsList) else: msg = errormessages.makeErrorMessage(protocolType, pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolType], msg) errorsList.append(errobj) if shell: # successfully connected, do discovery errorsList = [] warningsList = [] Framework.saveState(credentialId) OSHVResult = doDiscovery(Framework, shell, ip, credentialId, codepage, protocolType, warningsList, errorsList) else: if not len(errorsList): msg = errormessages.makeErrorMessage(protocolType, pattern=errormessages.ERROR_CONNECTION_FAILED) errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolType], msg) errorsList.append(errobj) Framework.clearState() for errobj in warningsList: logger.reportWarningObject(errobj) for errobj in errorsList: logger.reportErrorObject(errobj) return OSHVResult
def discoverServers(self): '''Discover application servers @types: -> None''' errobj = None suitableProtocols = None if self.credentialID != None: suitableProtocols = [[ProtocolManager.getProtocolById(self.credentialID), None]] else: j2eePorts = self.Framework.getTriggerCIDataAsList('ports') suitableProtocols = self.getProtocols(j2eePorts) if suitableProtocols.__len__() == 0: errobj = errorobject.createError(errorcodes.PROTOCOL_NOT_DEFINED, [' suitable ' + str(self.getJ2eeServerType())], 'No suitable ' + str(self.getJ2eeServerType()) + ' protocol defined') logger.reportWarningObject(errobj) else: self.discoverServersByCredentials(suitableProtocols)
def discoverConfigFiles(Framework, sgclusterOSH, shellUtils, cmclconfig_path, cmclconfig_files_pattern, OSHVResult): #get list of all config files file_name = None exstention = None if cmclconfig_files_pattern.rfind('.') > 0: file_name = cmclconfig_files_pattern else: exstention = cmclconfig_files_pattern try: fileMonitor = file_mon_utils.FileMonitor(Framework, shellUtils, OSHVResult, exstention, None) fileMonitor.getFiles(sgclusterOSH, cmclconfig_path, file_name) except: errorMessage = 'Failed to find configuration files for Service Guard Cluster' logger.debugException('errorMessage') errobj = errorobject.createError(errorcodes.FAILED_FINDING_CONFIGURATION_FILE, ['Service Guard Cluster'], errorMessage) logger.reportWarningObject(errobj)
def reportErrorMessage(self): '''Join all messages into one big message and report it as error or if no registered - report error "Tried all protocols" ''' if len(self.errorMsg) > 0: errorResult = '' for error in self.errorMsg: errorResult = errorResult + '\n' + str(error) errobj = errorobject.createError( errorcodes.CONNECTION_FAILED_WITH_DETAILS, [str(self.getJ2eeServerType()), errorResult], errorResult) else: errobj = errorobject.createError( errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS, ['Tried all protocols'], 'Failed to connect using all protocols') logger.reportWarningObject(errobj)
def createWebServer(self, serverHeaderStr, ip, port, hostOSH): #Header has the following format [Server type]/[verison] [comment] #This pattern assumes there is a slash (/) in the string matcher = re.match('([-\w ]*)/\s*([^\s]*)\s*([^\n]*)', serverHeaderStr) serverType = None serverVersion = None comment = None if matcher: serverType = matcher.group(1).strip() serverVersion = matcher.group(2) comment = matcher.group(3) else: #String does not contain a slash, regard all contents as serverType matcher = re.match(r"^([sS]erver:)?\s+(.+?[\d.][\d.]*\s|.*)", serverHeaderStr, re.IGNORECASE) if matcher: serverType = matcher.group(2) if serverType: isIIS = serverType.find('IIS') if self.createdServers.has_key(serverHeaderStr): if isIIS == -1: logger.warn('WebServer of type %s was already reported. Assuming same server listens a number of ports.' % serverType) logger.debug('Header is: %s.' % serverHeaderStr) errobj = errorobject.createError(errorcodes.ADDITIONAL_WEBSERVER_INSTANCES_ARE_SKIPPED, None, 'WebServer of type %s was already reported. Assuming same server listens a number of ports.') logger.reportWarningObject(errobj) return self.createdServers[serverHeaderStr] else: osh = None #check for application server if serverType.lower().count("weblogic"): osh = modeling.createJ2EEServer("weblogic", ip, port, hostOSH) else: osh = modeling.createWebServerOSH(serverType, port, 'N/A', hostOSH, 0, serverVersion) osh.setBoolAttribute("root_enableageing", "true") comment and osh.setAttribute('data_note', comment) osh.setAttribute('data_description',serverHeaderStr) osh.setAttribute('application_ip',ip) if isIIS >= 0: self.createdServers[serverHeaderStr] = osh return osh else: logger.warn("Failed to get serverType from header '%s'" % serverHeaderStr)
def discoverF5(self, f5Osh): queryBuilder = SnmpQueryBuilder('1.1') queryBuilder.addQueryElement(1, 'kernel') queryBuilder.addQueryElement(2, 'package') queryBuilder.addQueryElement(3, 'edition') queryBuilder.addQueryElement(4, 'agent') try: versionInformation = self.snmpAgent.getSnmpData(queryBuilder)[0] f5Osh.setAttribute('application_version', versionInformation.kernel) except: errorMsg = 'Failed to get general information' errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['snmp', 'general information'], errorMsg) logger.debugException(errorMsg) logger.reportWarningObject(errobj) self.discoverVirtualServers(f5Osh)
def discoverRealGroups(self, realGroupIndexToVirtualServer): queryBuilder = SnmpQueryBuilder(REAL_GROUPS) queryBuilder.addQueryElement(1, 'index', 'int') queryBuilder.addQueryElement(2, 'realServers', 'hexa') queryBuilder.addQueryElement(8, 'groupName') realGroups = self.snmpAgent.getSnmpData(queryBuilder) serverList = self.discoverRealServers() self.discoverPortLinks() for realGroup in realGroups: cluster = ObjectStateHolder('loadbalancecluster') dataName = realGroup.groupName index = realGroup.index.strip() if not dataName: dataName = index cluster.setAttribute('data_name', dataName) self.OSHVResult.add(cluster) realPort = None if realGroupIndexToVirtualServer.has_key(index): virtualServerWrapper = realGroupIndexToVirtualServer[index] virtualServerWrapper.addResultsToVector(self.OSHVResult, cluster) realPort = realGroupIndexToVirtualServer[index].realPort else: logger.warn('Alteon real group index %s taken from oid 1.3.6.1.4.1.1872.2.5.4.1.1.3.3.1.1 does not match any virtual service\'s real group index taken from oid 1.3.6.1.4.1.1872.2.5.4.1.1.4.5.1' % index) errobj = errorobject.createError(errorcodes.FAILED_LINKING_ELEMENTS, ['real group %s' % dataName, 'virtual service'], 'Failed to link real group %s to virtual service' % dataName) logger.reportWarningObject(errobj) realServerNumbers = parseMappingString(realGroup.realServers.strip()) #reporting real ports from Virtual service table for each real server: for realServer in realServerNumbers: if serverList.has_key(realServer): if realPort: serviceAddress = modeling.createServiceAddressOsh(serverList[realServer].getServer(), serverList[realServer].getIPAddress(), realPort, modeling.SERVICEADDRESS_TYPE_TCP) self.OSHVResult.add(serviceAddress) self.OSHVResult.add(modeling.createLinkOSH('member', cluster, serviceAddress)) elif self.portMappings.has_key(realServer): portMapping = self.getPortMapping(realServerindex) for port in portMapping.getPorts(): serviceAddress = modeling.createServiceAddressOsh(serverList[realServer].getServer(), serverList[realServer].getIPAddress(), port, modeling.SERVICEADDRESS_TYPE_TCP) self.OSHVResult.add(serviceAddress) self.OSHVResult.add(modeling.createLinkOSH('member', cluster, serviceAddress)) else: serviceAddress = modeling.createServiceAddressOsh(serverList[realServer].getServer(), serverList[realServer].getIPAddress(), 0, modeling.SERVICEADDRESS_TYPE_TCP, 'unknown') self.OSHVResult.add(serviceAddress) self.OSHVResult.add(modeling.createLinkOSH('member', cluster, serviceAddress))
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() (vec, errObj) = NTCMD_Connection_Utils.mainFunction(Framework) logger.debug('OSHVector contains ', vec.size(), ' objects.') # just in case we couldn't do any connection if vec.size() == 0: logger.debug('Failed to connect. No Host CI will be created') if (errObj == None or errObj.errMsg == None or errObj.errMsg.strip() == ''): altErr = errorobject.createError(errorcodes.INTERNAL_ERROR ,None , 'Discovery failed due to internal error') logger.reportErrorObject(altErr) else: logger.reportWarningObject(errObj) else: OSHVResult.addAll(vec) return OSHVResult
def processTCPCmdResult(self): # logger.debug('Processing results with regular expressions') self.tcpCmdResult = sanitizeIps(self.tcpCmdResult) shouldReportWarn = 0 lines = self.tcpCmdResult.split('\n') self.setRegExp() # logger.debug('Using tcp regexp:', self.TCPRegExp) # logger.debug('Using udp regexp:', self.UDPRegExp) listenIpPorts = [] for line in lines: lineProcessStatus = 0 lineProcessStatus = self.processListenPorts(line, listenIpPorts) if lineProcessStatus: shouldReportWarn = 1 # logger.debug('Processing non listener connections') lines = self.tcpCmdResult.split('\n') for line in lines: lineProcessStatus = 0 lineProcessStatus = self.processNonListenPorts(line, listenIpPorts) if lineProcessStatus > TCPDiscovery.FATAL_ERROR_MIN_CODE: return lineProcessStatus if lineProcessStatus: shouldReportWarn = 1 if shouldReportWarn: errobj = errorobject.createError( errorcodes.PARSING_ERROR_NO_PROTOCOL_NO_DETAILS, None, 'There was parsing error. Please check logs') logger.reportWarningObject(errobj) try: self.pdu.flushPortToProcesses() except: pass try: self.pdu.flushTcpConnection() except: pass self.pdu.close()
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() exchangeServerId = Framework.getDestinationAttribute('id') fqdn = Framework.getDestinationAttribute('fqdn') hostName = getHostName(Framework) exchangeServerOsh = ms_exchange_utils.restoreExchangeServerOSH( exchangeServerId) props = Properties() props.put(AgentConstants.PROP_WMI_NAMESPACE, WMI_NAMESPACE) try: wmiClient = Framework.createClient(props) wmiAgent = WmiAgent(wmiClient, Framework) try: exchangeDiscoverer = ExchangeDiscoverer(wmiAgent, exchangeServerOsh, Framework, OSHVResult, hostName) try: exchangeDiscoverer.doExchangeSystem(fqdn) exchangeDiscoverer.doFolderTrees() except: errorMsg = 'Failed to discover folder trees and public folders' logger.warnException(errorMsg) errobj = errorobject.createError( errorcodes.FAILED_DISCOVERING_RESOURCE, ['folder trees and public folders'], errorMsg) logger.reportWarningObject(errobj) if not exchangeDiscoverer.objectsDiscovered: errobj = errorobject.createError( errorcodes.MS_EXCHANGE_OBJECTS_NOT_FOUND, None, 'Microsoft Exchange objects not found in discovery') logger.reportErrorObject(errobj) finally: wmiClient.close() except: exInfo = logger.prepareJythonStackTrace('') errormessages.resolveAndReport(exInfo, WMI_PROTOCOL, Framework) return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() (vec, errObj) = NTCMD_Connection_Utils.mainFunction(Framework) logger.debug('OSHVector contains ', vec.size(), ' objects.') # just in case we couldn't do any connection if vec.size() == 0: logger.debug('Failed to connect. No Host CI will be created') if (errObj == None or errObj.errMsg == None or errObj.errMsg.strip() == ''): altErr = errorobject.createError( errorcodes.INTERNAL_ERROR, None, 'Discovery failed due to internal error') logger.reportErrorObject(altErr) else: logger.reportWarningObject(errObj) else: OSHVResult.addAll(vec) return OSHVResult
def discoverF5(self, f5Osh): queryBuilder = SnmpQueryBuilder('1.4') queryBuilder.addQueryElement(1, 'name') queryBuilder.addQueryElement(2, 'version') queryBuilder.addQueryElement(3, 'build') queryBuilder.addQueryElement(4, 'edition') queryBuilder.addQueryElement(5, 'date') snmpAgent = SnmpAgent('1.3.6.1.4.1.3375.2', self.snmpAgent.snmpClient, self.Framework) try: productInformation = snmpAgent.getSnmpData(queryBuilder)[0] f5Osh.setAttribute('application_version', productInformation.version) except: errorMsg = 'Failed to get general information' errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['snmp', 'general information'], errorMsg) logger.debugException(errorMsg) logger.reportWarningObject(errobj) self.discoverVirtualServers(f5Osh)
def processTCPCmdResult(self): # logger.debug('Processing results with regular expressions') self.tcpCmdResult = sanitizeIps(self.tcpCmdResult) shouldReportWarn = 0 lines = self.tcpCmdResult.split('\n') self.setRegExp() # logger.debug('Using tcp regexp:', self.TCPRegExp) # logger.debug('Using udp regexp:', self.UDPRegExp) listenIpPorts = [] for line in lines: lineProcessStatus = 0 lineProcessStatus = self.processListenPorts(line, listenIpPorts) if lineProcessStatus: shouldReportWarn = 1 # logger.debug('Processing non listener connections') lines = self.tcpCmdResult.split('\n') for line in lines: lineProcessStatus = 0 lineProcessStatus = self.processNonListenPorts(line, listenIpPorts) if lineProcessStatus > TCPDiscovery.FATAL_ERROR_MIN_CODE: return lineProcessStatus if lineProcessStatus: shouldReportWarn = 1 if shouldReportWarn: errobj = errorobject.createError(errorcodes.PARSING_ERROR_NO_PROTOCOL_NO_DETAILS, None, 'There was parsing error. Please check logs') logger.reportWarningObject(errobj) try: self.pdu.flushPortToProcesses() except: pass try: self.pdu.flushTcpConnection() except: pass self.pdu.close()
def discoverConfigFiles(Framework, sgclusterOSH, shellUtils, cmclconfig_path, cmclconfig_files_pattern, OSHVResult): #get list of all config files file_name = None exstention = None if cmclconfig_files_pattern.rfind('.') > 0: file_name = cmclconfig_files_pattern else: exstention = cmclconfig_files_pattern try: fileMonitor = file_mon_utils.FileMonitor(Framework, shellUtils, OSHVResult, exstention, None) fileMonitor.getFiles(sgclusterOSH, cmclconfig_path, file_name) except: errorMessage = 'Failed to find configuration files for Service Guard Cluster' logger.debugException('errorMessage') errobj = errorobject.createError( errorcodes.FAILED_FINDING_CONFIGURATION_FILE, ['Service Guard Cluster'], errorMessage) logger.reportWarningObject(errobj)
def checkNonNativeAgentInstalled(Framework): # Set the nonnative flags Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE, 'false') InventoryUtils.resetBaseDir(Framework) AgentUtils.setUpgradingNativeAgent(Framework, 'true') # Ensure we're disconnected InventoryUtils.releaseConnection(Framework) Framework.setProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE, AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE) # For now - the usual check logger.debug( 'Going to check whether non-native agent already installed or not') warningsList = [] errorsList = [] agent = AgentUtils.agentConnect( Framework, AgentUtils.getUdAgentProtocolForMigration(Framework).getIdAsString(), warningsList, errorsList) if not agent: for errobj in warningsList: logger.reportWarningObject(errobj) for errobj in errorsList: logger.reportErrorObject(errobj) Framework.reportError( inventoryerrorcodes.INVENTORY_DISCOVERY_ENSURE_CONNECTED_FAILED, ['Could not connect to the remote agent']) Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) else: logger.debug('Connected to agent!!!!') Framework.setProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE, '') InventoryUtils.setConnectedClientIdentifier(Framework, agent) agent.close() Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def discoverServers(self): '''Discover application servers @types: -> None''' errobj = None suitableProtocols = None if self.credentialID != None: suitableProtocols = [[ ProtocolManager.getProtocolById(self.credentialID), None ]] else: j2eePorts = self.Framework.getTriggerCIDataAsList('ports') suitableProtocols = self.getProtocols(j2eePorts) if suitableProtocols.__len__() == 0: errobj = errorobject.createError( errorcodes.PROTOCOL_NOT_DEFINED, [' suitable ' + str(self.getJ2eeServerType())], 'No suitable ' + str(self.getJ2eeServerType()) + ' protocol defined') logger.reportWarningObject(errobj) else: self.discoverServersByCredentials(suitableProtocols)
def discoverRules(self, nameToVirtualServerHelper, nameToPool): queryBuilder = SnmpQueryBuilder('10.8.2.1') queryBuilder.addQueryElement(1, 'serverName') queryBuilder.addQueryElement(2, 'ruleName') ruleToServerEntries = self.snmpAgent.getSnmpData(queryBuilder) ruleNameToServerName = {} for ruleToServerEntry in ruleToServerEntries: ruleNameToServerName[ruleToServerEntry.ruleName] = ruleToServerEntry.serverName queryBuilder = SnmpQueryBuilder('8.1.2.1') queryBuilder.addQueryElement(1, 'name') queryBuilder.addQueryElement(2, 'definition') #Type is currently not used, consider about adding it to description queryBuilder.addQueryElement(3, 'type') rules = self.snmpAgent.getSnmpData(queryBuilder) for rule in rules: try: virtualServerHelper = nameToVirtualServerHelper[ruleNameToServerName[rule.name]] virtualServerOsh = virtualServerHelper.getOsh() ruleOsh = modeling.createConfigurationDocumentOSH(rule.name, '', rule.definition, virtualServerOsh) virtualServerHelper.addOsh(ruleOsh) lines = rule.definition.splitlines() lines = [line.strip() for line in lines if line and line.strip()] for line in lines: if not line.startswith('#') and not re.search(';\s*\#', line): poolRef = re.match("pool\s+(\S+)", line) if poolRef: poolName = poolRef.group(1) logger.debug('Found pool ' + poolName + ' in rule ' + rule.name) if nameToPool.has_key(poolName): virtualServerHelper.linkToContainingCluster(nameToPool[poolName], poolName) except: errorMsg = 'Failed to obtain virtual server for rule %s' % rule.name errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION_NO_PROTOCOL, ['virtual server for rule %s' % rule.name], errorMsg) logger.debugException(errorMsg) logger.reportWarningObject(errobj)
def discoverPools(self, nameToVirtualServerHelper, f5Osh, nameToPool): queryBuilder = SnmpQueryBuilder('5.1.2.1') queryBuilder.addQueryElement(1, 'name') pools = self.snmpAgent.getSnmpData(queryBuilder) for pool in pools: poolOsh = ObjectStateHolder('loadbalancecluster') poolOsh.setAttribute('data_name', pool.name) self.add(poolOsh) memberLink = modeling.createLinkOSH('membership', poolOsh, f5Osh) self.add(memberLink) nameToPool[pool.name] = poolOsh for name, virtualServerHelper in nameToVirtualServerHelper.items(): if virtualServerHelper.getDefaultPoolName() == pool.name and not virtualServerHelper.hasParentCluster(pool.name): virtualServerHelper.linkToContainingCluster(poolOsh, pool.name) queryBuilder = SnmpQueryBuilder('10.6.2.1') queryBuilder.addQueryElement(1, 'virtualServerName') queryBuilder.addQueryElement(2, 'poolName') queryBuilder.addQueryElement(3, 'poolDefaultRuleName') poolToServerEntries = self.snmpAgent.getSnmpData(queryBuilder) for poolToServerEntry in poolToServerEntries: try: virtualServerHelper = nameToVirtualServerHelper[poolToServerEntry.virtualServerName] poolOsh = nameToPool[poolToServerEntry.poolName] if not virtualServerHelper.hasParentCluster(poolToServerEntry.poolName): virtualServerHelper.linkToContainingCluster(poolOsh, poolToServerEntry.poolName) except: errorMsg = 'Failed to link %s server with %s pool' % (poolToServerEntry.virtualServerName, poolToServerEntry.poolName) errobj = errorobject.createError(errorcodes.FAILED_LINKING_ELEMENTS, ['%s server' % poolToServerEntry.virtualServerName, '%s pool' % poolToServerEntry.poolName], errorMsg) #TODO Change log level to debug logger.debugException(errorMsg) logger.reportWarningObject(errobj) self.discoverPoolMembers(nameToPool)
def checkNonNativeAgentInstalled(Framework): # Set the nonnative flags Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE, 'false') InventoryUtils.resetBaseDir(Framework) AgentUtils.setUpgradingNativeAgent(Framework, 'true') # Ensure we're disconnected InventoryUtils.releaseConnection(Framework) Framework.setProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE, AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE) # For now - the usual check logger.debug('Going to check whether non-native agent already installed or not') warningsList = [] errorsList = [] agent = AgentUtils.agentConnect(Framework, AgentUtils.getUdAgentProtocolForMigration(Framework).getIdAsString(), warningsList, errorsList) if not agent: for errobj in warningsList: logger.reportWarningObject(errobj) for errobj in errorsList: logger.reportErrorObject(errobj) Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_ENSURE_CONNECTED_FAILED, ['Could not connect to the remote agent']) Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE) else: logger.debug('Connected to agent!!!!') Framework.setProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE, '') InventoryUtils.setConnectedClientIdentifier(Framework, agent) agent.close() Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)