def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ipAddress = Framework.getDestinationAttribute('ip_address') credentialsId = Framework.getDestinationAttribute('credentialsId') hostId = Framework.getDestinationAttribute('hostId') hostOsh = ms_exchange_utils.restoreHostById(hostId) hostName = Framework.getDestinationAttribute('hostName') if not hostName or hostName == 'N/A': hostName = ms_exchange_utils.getHostNameFromWmi(Framework) if not hostName: errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION_NO_PROTOCOL, ['host name'], 'Failed to obtain host name') logger.reportErrorObject(errobj) return props = Properties() props.put(AgentConstants.PROP_WMI_NAMESPACE, WMI_NAMESPACE) try: wmiClient = Framework.createClient(props) wmiAgent = WmiAgent(wmiClient, Framework) try: discoverExchangeServer(wmiAgent, ipAddress, credentialsId, OSHVResult, Framework, hostOsh, hostName) finally: wmiClient.close() except Exception, ex: message = ex.getMessage() if (re.search("Invalid\sclass", message)): message = 'Unable to get Exchange data from WMI' logger.debugException(message) errormessages.resolveAndReport(message, WMI_PROTOCOL, Framework)
def getHostName(Framework): hostName = Framework.getDestinationAttribute('hostName') if not hostName or hostName == 'N/A': fqdn = Framework.getDestinationAttribute('fqdn') if not fqdn or fqdn == 'N/A': hostName = ms_exchange_utils.getHostNameFromWmi(Framework) return hostName