def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip = Framework.getDestinationAttribute('ip_address') sid = Framework.getDestinationAttribute('sid') port = Framework.getDestinationAttribute('port') hostId = Framework.getDestinationAttribute('hostId') if (ip == None) or (ip == 'NA'): #checked and pass all IPs of given host ips = Framework.getTriggerCIDataAsList('host_ips') else: ips = [ip] for currIP in ips: if len(currIP) == 0: continue logger.debug('Checking sqlserver with no user on ipaddress:', currIP) protocols = Framework.getAvailableProtocols( currIP, ClientsConsts.SQL_PROTOCOL_NAME) for protocol in protocols: dbClient = None try: try: if dbutils.protocolMatch( Framework, protocol, 'microsoftsqlserver', sid, port) or dbutils.protocolMatch( Framework, protocol, 'microsoftsqlserverntlm', sid, port): props = Properties() props.setProperty('ip_address', currIP) dbClient = Framework.createClient(protocol, props) hostOSH = modeling.createOshByCmdbIdString( 'host', hostId) oracleOSH = modeling.createDatabaseOSH( 'sqlserver', sid, str(dbClient.getPort()), dbClient.getIpAddress(), hostOSH, protocol, None, dbClient.getTimeout(), dbClient.getDbVersion(), dbClient.getAppVersion()) logger.debug( 'Successfully connected to sqlserver object ', sid, ' on ', currIP) OSHVResult.add(oracleOSH) #since this is knownn oracle and we found credentials for it we can finish execution return OSHVResult except: if logger.isDebugEnabled(): logger.debugException( 'Unexpected CreateClient() for sqlserver client Exception:' ) finally: if dbClient != None: dbClient.close() Framework.reportWarning('Failed to connect using all protocols') return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip = Framework.getDestinationAttribute("ip_address") sid = Framework.getDestinationAttribute("sid") port = Framework.getDestinationAttribute("port") hostId = Framework.getDestinationAttribute("hostId") if (ip == None) or (ip == "NA"): # checked and pass all IPs of given host ips = Framework.getTriggerCIDataAsList("host_ips") else: ips = [ip] for currIP in ips: if len(currIP) == 0: continue logger.debug("Checking sqlserver with no user on ipaddress:", currIP) protocols = Framework.getAvailableProtocols(currIP, ClientsConsts.SQL_PROTOCOL_NAME) for protocol in protocols: dbClient = None try: try: if dbutils.protocolMatch( Framework, protocol, "microsoftsqlserver", sid, port ) or dbutils.protocolMatch(Framework, protocol, "microsoftsqlserverntlm", sid, port): props = Properties() props.setProperty("ip_address", currIP) dbClient = Framework.createClient(protocol, props) hostOSH = modeling.createOshByCmdbIdString("host", hostId) oracleOSH = modeling.createDatabaseOSH( "sqlserver", sid, str(dbClient.getPort()), dbClient.getIpAddress(), hostOSH, protocol, None, dbClient.getTimeout(), dbClient.getDbVersion(), dbClient.getAppVersion(), ) logger.debug("Successfully connected to sqlserver object ", sid, " on ", currIP) OSHVResult.add(oracleOSH) # since this is knownn oracle and we found credentials for it we can finish execution return OSHVResult except: if logger.isDebugEnabled(): logger.debugException("Unexpected CreateClient() for sqlserver client Exception:") finally: if dbClient != None: dbClient.close() Framework.reportWarning("Failed to connect using all protocols") return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip_address = Framework.getDestinationAttribute('ip_address') hostOSH = modeling.createHostOSH(ip_address) protocols = Framework.getAvailableProtocols(ip_address, ClientsConsts.SQL_PROTOCOL_NAME) for sqlProtocol in protocols: dbClient = None try: try: if dbutils.protocolMatch(Framework, sqlProtocol, 'sybase', None, None) == 0: continue dbClient = Framework.createClient(sqlProtocol) logger.debug('Connnected to sybase on ip ', dbClient.getIpAddress(), ', port ', str(dbClient.getPort()), ' to database ',dbClient.getDatabaseName(),'with user ', dbClient.getUserName()) dbversion = dbClient.getDbVersion() logger.debug('Found sybase server of version:', dbversion) res = dbClient.executeQuery("select srvnetname from master..sysservers where srvid = 0")#@@CMD_PERMISION sql protocol execution if res.next(): dbname=string.strip(res.getString(1)) sybasedOSH = modeling.createDatabaseOSH('sybase', dbname, str(dbClient.getPort()),dbClient.getIpAddress(),hostOSH,sqlProtocol,dbClient.getUserName(),None,dbversion) OSHVResult.add(sybasedOSH) else: Framework.reportWarning('Sybase server was not found') except MissingJarsException, e: logger.debugException(e.getMessage()) Framework.reportError(e.getMessage()) return except: logger.debugException('Failed to discover sybase with credentials ', sqlProtocol) finally:
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip_address = Framework.getDestinationAttribute('ip_address') hostOSH = modeling.createHostOSH(ip_address) protocols = Framework.getAvailableProtocols( ip_address, ClientsConsts.SQL_PROTOCOL_NAME) for sqlProtocol in protocols: dbClient = None try: try: if dbutils.protocolMatch(Framework, sqlProtocol, 'sybase', None, None) == 0: continue dbClient = Framework.createClient(sqlProtocol) logger.debug('Connnected to sybase on ip ', dbClient.getIpAddress(), ', port ', str(dbClient.getPort()), ' to database ', dbClient.getDatabaseName(), 'with user ', dbClient.getUserName()) dbversion = dbClient.getDbVersion() logger.debug('Found sybase server of version:', dbversion) res = dbClient.executeQuery( "select srvnetname from master..sysservers where srvid = 0" ) #@@CMD_PERMISION sql protocol execution if res.next(): dbname = string.strip(res.getString(1)) sybasedOSH = modeling.createDatabaseOSH( 'sybase', dbname, str(dbClient.getPort()), dbClient.getIpAddress(), hostOSH, sqlProtocol, dbClient.getUserName(), None, dbversion) OSHVResult.add(sybasedOSH) else: Framework.reportWarning('Sybase server was not found') except MissingJarsException, e: logger.debugException(e.getMessage()) Framework.reportError(e.getMessage()) return except: logger.debugException( 'Failed to discover sybase with credentials ', sqlProtocol) finally:
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ipAddress = Framework.getDestinationAttribute('ip_address') hostname = Framework.getDestinationAttribute('hostname') if hostname is None: hostname = 'NA' else: hostname = hostname.upper() protocolType = Framework.getParameter('protocolType') hostOSH = modeling.createHostOSH(ipAddress) protocols = Framework.getAvailableProtocols( ipAddress, ClientsConsts.SQL_PROTOCOL_NAME) sidList = [] for protocol in protocols: protocol_validation_status = isValidProtocol(Framework, protocol, protocolType) if protocol_validation_status == PROTOCOL_NO_PORT: logger.debug('Protocol ', protocol, ' has no defined port') elif protocol_validation_status == PROTOCOL_NO_SID: logger.debug('Protocol ', protocol, ' has no defined SID') elif dbutils.protocolMatch(Framework, protocol, protocolType, None, None): logger.debugException('Trying to connect with protocol:', protocol) dbClient = None try: try: dbClient = Framework.createClient(protocol) sid = getDbSid(dbClient, hostname) if sid is None: continue if ((sid in sidList) != 0): logger.debug( str('Database : ' + sid + ' already reported.')) continue databaseServer = createDatabaseOSH( hostOSH, dbClient, sid, dbClient.getDbVersion(), dbClient.getAppVersion()) OSHVResult.add(databaseServer) sidList.append(sid) except SQLException, sqlex: logger.debug(sqlex.getMessage()) except: msg = logger.prepareFullStackTrace('') errormessages.resolveAndReport( msg, ClientsConsts.SQL_PROTOCOL_NAME, Framework) finally:
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ip = Framework.getDestinationAttribute('ip_address') sid = Framework.getDestinationAttribute('sid') port = Framework.getDestinationAttribute('port') hostId = Framework.getDestinationAttribute('hostId') if (ip == None) or (ip == 'NA'): #checked and pass all IPs of given host ips = Framework.getTriggerCIDataAsList('host_ips') else: ips = [ip] for currIP in ips: if len(currIP) == 0: continue logger.debug('Checking oracle with no user on ipaddress:', currIP) protocols = Framework.getAvailableProtocols(currIP, ClientsConsts.SQL_PROTOCOL_NAME) for protocol in protocols: dbClient = None try: try: if dbutils.protocolMatch(Framework, protocol, 'oracle', sid, port): props = Properties() props.setProperty('ip_address', currIP) dbClient = Framework.createClient(protocol, props) hostOSH = modeling.createOshByCmdbIdString('host', hostId) oracleOSH = modeling.createDatabaseOSH('oracle', sid, str(dbClient.getPort()), dbClient.getIpAddress(), hostOSH, protocol,None, dbClient.getTimeout(),dbClient.getDbVersion(), dbClient.getAppVersion()) logger.debug('Successfully connected to oracle object ', sid, ' on ', currIP) OSHVResult.add(oracleOSH) #since this is knownn oracle and we found credentials for it we can finish execution return OSHVResult except: if logger.isDebugEnabled(): logger.debugException('Unexpected CreateClient() for oracle client Exception:') finally: if dbClient != None: dbClient.close() Framework.reportWarning('Failed to connect using all protocols') return OSHVResult
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ipAddress = Framework.getDestinationAttribute('ip_address') hostname = Framework.getDestinationAttribute('hostname') if hostname is None: hostname = 'NA' else: hostname = hostname.upper() protocolType = Framework.getParameter('protocolType') hostOSH = modeling.createHostOSH(ipAddress) protocols = Framework.getAvailableProtocols(ipAddress, ClientsConsts.SQL_PROTOCOL_NAME) sidList = [] for protocol in protocols: protocol_validation_status = isValidProtocol(Framework, protocol, protocolType) if protocol_validation_status == PROTOCOL_NO_PORT: logger.debug('Protocol ', protocol, ' has no defined port') elif protocol_validation_status == PROTOCOL_NO_SID: logger.debug('Protocol ', protocol, ' has no defined SID') elif dbutils.protocolMatch(Framework, protocol, protocolType, None, None): logger.debugException('Trying to connect with protocol:', protocol) dbClient = None try: try: dbClient = Framework.createClient(protocol) sid = getDbSid(dbClient, hostname) if sid is None: continue if ((sid in sidList) != 0): logger.debug(str('Database : ' + sid + ' already reported.')) continue databaseServer = createDatabaseOSH(hostOSH, dbClient, sid, dbClient.getDbVersion(), dbClient.getAppVersion()) OSHVResult.add(databaseServer) sidList.append(sid) except SQLException, sqlex: logger.debug(sqlex.getMessage()) except: msg = logger.prepareFullStackTrace('') errormessages.resolveAndReport(msg, ClientsConsts.SQL_PROTOCOL_NAME, Framework) finally: