config_file = "ncircle" _TIMEOUT = 5 for key in getMergedConf(config_file).keys(): try: host = getMergedConf(config_file)[key]['host'] user = getMergedConf(config_file)[key]['username'] password = getMergedConf(config_file)[key]['password'] try: # Connect to the server and login (server, session) = nCircleAPI._login(host, user, password) for dp in deviceProfilers: deviceProfilerDetail = nCircleAPI._getItem(server, session, dpList, dp) deviceProfilerDetail['authenticationKey'] = 'anonymized' print "{", nCircleAPI._printJson(deviceProfilerDetail) print "}" nCircleAPI._logout(server, session) except xmlrpclib.Fault, fault: print "xmlrpclib fault: %d %s" % (fault.faultCode, fault.faultString) sys.exit(1) except xmlrpclib.ProtocolError, error: print "xmlrpclib protocol error: %d %s" % (error.errcode, error.errmsg) sys.exit(1) except: pass # exit sys.exit(0)
try: # Connect to the server and login (server, session) = nCircleAPI._login(host, user, password) # Construct query to get latest audit records result = server.call(session, 'SESSION', 'getUserObject', {}) params = {} params['query'] = "id > \'%s\'" % (jsonStruct[host + user + "_maxId"]) newAuditRecords = server.call(session, 'class.AuditLog', 'search', params) if newAuditRecords: for newAuditRecord in newAuditRecords: result = '' result = server.call(session, newAuditRecord, 'getAttributes', {}) print "{", nCircleAPI._printJson(result) print "}" #print result # Max ID is stored in latest result jsonStruct[host + user + "_maxId"] = result['id'] # Safe Logout nCircleAPI._logout(server, session) except xmlrpclib.Fault, fault: print "xmlrpclib fault: %d %s" % (fault.faultCode, fault.faultString) sys.exit(1) except xmlrpclib.ProtocolError, error: print "xmlrpclib protocol error: %d %s" % (error.errcode, error.errmsg) sys.exit(1)
params = {} params['query'] = "active = \'true\' AND dp = \'%s\'" % (dp) ScanConfiguration = server.call(session, 'class.ScanConfiguration', 'search', params) if ScanConfiguration: for ScanConfigurationItem in ScanConfiguration: ScanConfigurations.append(ScanConfigurationItem) if ScanConfigurations: timestamp = str(time.time()) for ScanConfigurationItem in ScanConfigurations: scanProfile = server.call(session, ScanConfigurationItem, 'getAttributes', {}) scanProfileDetail = nCircleAPI._getItem(server, session, scanList, scanProfile['scanProfile']) networkDetail = nCircleAPI._getItem(server, session, networkList, scanProfile['network']) print '{"timestamp": "' + timestamp + '", ', nCircleAPI._printJson(scanProfile) print ', "scanProfile" : ', scanProfileDetail['profile'] = json.dumps(xmltodict.parse(scanProfileDetail['profile'])) #scanProfileDetail['profile'] = str(data).replace('\'','"') #data = str(data).replace('"{','{') #data = str(data).replace('}"','}') #scanProfileDetail['profile'] = data #data = nCircleAPI._printJson(scanProfileDetail) scanProfileDetail = str(scanProfileDetail).replace('\'','"') scanProfileDetail = str(scanProfileDetail).replace('"{','{') scanProfileDetail = str(scanProfileDetail).replace('}"','}') scanProfileDetail = str(scanProfileDetail).replace('True','1') scanProfileDetail = str(scanProfileDetail).replace('False','0') print scanProfileDetail,
if vulnResultIDs: for vulnResultID in vulnResultIDs: vulnResult = {} vulnDetail = {} hostDetail = {} osDetail = {} vulnResult = server.call(session, vulnResultID, 'getAttributes', {}) # Get additional details that are being referenced in the vulnResult vulnDetail = nCircleAPI._getItem(server, session, vulnList, vulnResult['vuln']) hostDetail = nCircleAPI._getItem(server, session, hostList, vulnResult['host']) osDetail = nCircleAPI._getItem(server, session, osList, hostDetail['os']) print "{", nCircleAPI._printJson(vulnResult) print ', "VulnDetail" : {', nCircleAPI._printJson(vulnDetail) print "},", print '"hostDetail" : {', nCircleAPI._printJson(hostDetail) print "},", print '"osDetail" : {', nCircleAPI._printJson(osDetail) print "}", print "}" # Store the latest Audit IDs for each device profiler