def startJob(runtime): """Standard job entry point. Arguments: runtime (dict) : object used for providing input into jobs and tracking the job thread through the life of its runtime. """ try: endpoint = runtime.endpoint['value'] ## Raw socket connection via Python - requires client to run elevated failed = ping.ping_ip(endpoint, maxTries=3, logger=runtime.logger) if failed: runtime.logger.debug("{name!r}: FAILED on endpoint {endpoint!r}", name = __name__, endpoint = endpoint) runtime.status(2) runtime.message('Endpoint did not respond to ping.') else: runtime.logger.debug("{name!r}: SUCCESS on endpoint {endpoint!r}", name = __name__, endpoint= endpoint) runtime.status(1) ## Add the IP onto the Results object addIp(runtime, address=endpoint) except: runtime.setError(__name__) ## end startJob return
def createObjects(runtime, shortname, domain, description, deviceOID, location, firmware, serialNumber, model, assetId, endpoint, ips, protocolId): """Create objects and links in our results.""" try: ## First create the node nodeId, exists = addObject(runtime, 'Node', hostname=shortname, domain=domain, description=description, snmp_oid=deviceOID, location=location) ## Now create the hardware if serialNumber is not None: hardwareId, exists = addObject(runtime, 'HardwareNode', serial_number=serialNumber, bios_info=firmware, model=model, asset_tag=assetId) addLink(runtime, 'Usage', nodeId, hardwareId) ## Now create the IPs for ip in ips: with suppress(ValueError): ipId, exists = addIp(runtime, address=ip) addLink(runtime, 'Usage', nodeId, ipId) ## In case the IP we've connected in on isn't in the IP table list: if endpoint not in ips: with suppress(ValueError): ipId, exists = addIp(runtime, address=endpoint) addLink(runtime, 'Usage', nodeId, ipId) ## Now create the SNMP object realm = runtime.jobMetaData.get('realm') snmpId, exists = addObject(runtime, 'SNMP', container=nodeId, ipaddress=endpoint, protocol_reference=protocolId, realm=realm, node_type='Unknown') addLink(runtime, 'Enclosed', nodeId, snmpId) ## Update the runtime status to success runtime.status(1) except: runtime.setError(__name__) ## end createObjects return
def createNewIp(runtime, trackedIPs, thisIP): """Reduce the number of times we lookup an IP and add to the results.""" if thisIP in trackedIPs: return trackedIPs.get(thisIP) ipId, exists = addIp(runtime, address=thisIP) trackedIPs[thisIP] = ipId ## end createNewIp return ipId
def startJob(runtime): """Standard job entry point. Arguments: runtime (dict) : object used for providing input into jobs and tracking the job thread through the life of its runtime. """ client = None try: endpoint = runtime.endpoint['value'] ## Configure local client client = localClient(runtime, 'powershell') if client is not None: ## Open client session before starting the work client.open() if isPingable(runtime, client, endpoint): runtime.logger.debug( "{name!r}: SUCCESS on endpoint {endpoint!r}", name=__name__, endpoint=endpoint) runtime.status(1) ## Add the IP onto the Results object addIp(runtime, address=endpoint) else: runtime.logger.debug( "{name!r}: FAILED on endpoint {endpoint!r}", name=__name__, endpoint=endpoint) runtime.status(2) runtime.message('Endpoint did not respond to ping.') ## Good house keeping; though I force this after the exception below client.close() except: runtime.setError(__name__) with suppress(Exception): if client is not None: client.close() ## end startJob return
def createObjects(runtime, client, realm): """Create and connect the node and REST object.""" ## Get necessary info from the client (endpoint, reference, port, url) = client.restDetails() ## Create the node nodeId, exists = addObject(runtime, 'Node', hostname=endpoint, partial=True) ## Create a REST object to leverage for future connections restId, exists = addObject(runtime, 'REST', container=nodeId, ipaddress=endpoint, protocol_reference=reference, realm=realm, port=port, base_url=url, node_type='OCP') ipId, exists = addIp(runtime, address=endpoint) ## And connect the objects addLink(runtime, 'Enclosed', nodeId, restId) addLink(runtime, 'Usage', nodeId, ipId)
def createObjects(runtime, osType, osAttrDict, biosAttrDict, nameAttrDict, ipAddresses, ipDict, endpoint, protocolReference): """Create objects and links in our results.""" protocolId = None try: ## Log when the 'printDebug' parameter is set runtime.logger.report('osAttrDict : {osAttrDict!r}', osAttrDict=osAttrDict) runtime.logger.report('biosAttrDict: {biosAttrDict!r}', biosAttrDict=biosAttrDict) runtime.logger.report('nameAttrDict : {nameAttrDict!r}', nameAttrDict=nameAttrDict) runtime.logger.report('ipAddresses : {ipAddresses!r}', ipAddresses=ipAddresses) ## First create the node domain = nameAttrDict.get('domain') hostname = nameAttrDict.get('hostname') manufacturer = biosAttrDict.get('manufacturer') nodeAttributes = {} for thisAttr in ['distribution', 'platform', 'version', 'kernel']: thisValue = osAttrDict.get(thisAttr) if thisValue is not None: nodeAttributes[thisAttr] = thisValue nodeAttributes['hardware_provider'] = manufacturer nodeId = None if domain is None: nodeId, exists = addObject(runtime, osType, hostname=hostname, **nodeAttributes) else: nodeId, exists = addObject(runtime, osType, hostname=hostname, domain=domain, **nodeAttributes) ## Establish an FQDN string for local IP addresses (loopback) realm = runtime.jobMetaData.get('realm', 'NA') FQDN = 'NA' if hostname is not None: FQDN = hostname if (domain is not None and domain not in hostname): FQDN = '{}.{}'.format(hostname, domain) ## Now create the IPs trackedZones = {} for ip in ipAddresses: ipId = None if (ip in ['127.0.0.1', '::1', '0:0:0:0:0:0:0:1']): ## Override the realm setting for two reasons: we do not want these ## IPs in endpoint query results, and we want to track one per node ipId, exists = runtime.results.addIp(address=ip, realm=FQDN) else: ipId, exists = runtime.results.addIp(address=ip, realm=realm) ## Add any DNS records found if ip in ipDict: for entry in ipDict[ip]: (domainName, recordData) = entry ## Create the zone if necessary if domainName not in trackedZones: ## Add the zone onto the result set zoneId, exists = addObject(runtime, 'Domain', name=domainName) trackedZones[domainName] = zoneId zoneId = trackedZones[domainName] ## Create the DNS record recordId, exists = addObject(runtime, 'NameRecord', name=recordData, value=ip) addLink(runtime, 'Enclosed', zoneId, recordId) addLink(runtime, 'Usage', nodeId, ipId) ## In case the IP we've connected in on isn't in the IP table list: if endpoint not in ipAddresses: ipId, exists = addIp(runtime, address=endpoint) addLink(runtime, 'Usage', nodeId, ipId) ## Now create the SSH object protocolId, exists = addObject(runtime, 'SSH', container=nodeId, ipaddress=endpoint, protocol_reference=protocolReference, realm=realm, node_type=osType) addLink(runtime, 'Enclosed', nodeId, protocolId) ## Now create the hardware serial_number = biosAttrDict.get('serial_number') bios_info = biosAttrDict.get('bios_info') model = biosAttrDict.get('model') manufacturer = biosAttrDict.get('manufacturer') uuid = biosAttrDict.get('uuid') if serial_number is not None: hardwareId, exists = addObject(runtime, 'HardwareNode', serial_number=serial_number, bios_info=bios_info, model=model, vendor=manufacturer, uuid=uuid) addLink(runtime, 'Usage', nodeId, hardwareId) ## Update the runtime status to success runtime.status(1) except: runtime.setError(__name__) ## end createObjects return protocolId
def createObjects(runtime, osAttrDict, biosAttrDict, csAttrDict, ipAddresses, endpoint, protocolId): """Create objects and links in our results.""" try: ## First create the node domain = csAttrDict.get('Domain', None) hostname = csAttrDict.get('Name', None) vendor = osAttrDict.get('Manufacturer', None) platform = osAttrDict.get('Caption', None) version = osAttrDict.get('Version', None) hw_provider = csAttrDict.get('Manufacturer', None) nodeId, exists = addObject(runtime, 'Node', hostname=hostname, domain=domain, vendor=vendor, platform=platform, version=version, hardware_provider=hw_provider) ## Now create the IPs for ip in ipAddresses: with suppress(ValueError): ipId, exists = addIp(runtime, address=ip) addLink(runtime, 'Usage', nodeId, ipId) ## In case the IP we've connected in on isn't in the IP table list: if endpoint not in ipAddresses: with suppress(ValueError): ipId, exists = addIp(runtime, address=endpoint) addLink(runtime, 'Usage', nodeId, ipId) ## Now create the WMI object realm = runtime.jobMetaData.get('realm') snmpId, exists = addObject(runtime, 'WMI', container=nodeId, ipaddress=endpoint, protocol_reference=protocolId, realm=realm, node_type='Windows') addLink(runtime, 'Enclosed', nodeId, snmpId) ## Now create the hardware serial_number = biosAttrDict.get('SerialNumber', None) bios_info = biosAttrDict.get('Caption', None) model = csAttrDict.get('Model', None) manufacturer = csAttrDict.get('Manufacturer', None) hardwareId, exists = addObject(runtime, 'HardwareNode', serial_number=serial_number, bios_info=bios_info, model=model, vendor=manufacturer) addLink(runtime, 'Usage', nodeId, hardwareId) ## Update the runtime status to success runtime.status(1) except: runtime.setError(__name__) ## end createObjects return