diff --git a/windows-collect/src/collect.py b/windows-collect/src/collect.py index a0f2bdff3ea9a8b62b6984a93acbc4156ad66ad4..12ff742a8a8c39f3d98672c5a4da5d49562b7e5f 100644 --- a/windows-collect/src/collect.py +++ b/windows-collect/src/collect.py @@ -39,15 +39,15 @@ def getRegistryValue(key, subkey, value): (value, type) = _winreg.QueryValueEx(handle, value) return value -def getTelecentroInfo(info): - tlInfoFile = open(DATASIDPATH + "\\conf\\telecentroInfo", "r") - tlInfo = value = " " - while (tlInfo != info and tlInfo != ""): +def getPointInfo(info): + ptInfoFile = open(DATASIDPATH + "\\conf\\pointInfo", "r") + ptInfo = value = " " + while (ptInfo != info and ptInfo != ""): try: - (tlInfo, value) = tlInfoFile.readline().split("=") + (ptInfo, value) = ptInfoFile.readline().split("=") except: - tlInfo = value = "" - tlInfoFile.close() + ptInfo = value = "" + ptInfoFile.close() return value # Return Windows version @@ -135,47 +135,14 @@ def diskUsed(c): def collect(): mainTag = Element('collected-data') - # Collect telecentros's info - admin_name = getTelecentroInfo("responsavel") - tl_connection = getTelecentroInfo("conexao") - tl_name = getTelecentroInfo("nome") - state = getTelecentroInfo("estado") - city = getTelecentroInfo("municipio") - tl_street = getTelecentroInfo("rua") - tl_zipcode = getTelecentroInfo("cep") - tl_beneficiary = getTelecentroInfo("beneficiaria") - tl_number = getTelecentroInfo("numero") - tl_neighborhood = getTelecentroInfo("bairro") - geolocation = getTelecentroInfo("geolocalizacao") - superid = getTelecentroInfo("superid") - user_count = getTelecentroInfo("usuarios") - - tagTelecentroInfo = SubElement(mainTag, 'telecentro-info') - tagAdminName = SubElement(tagTelecentroInfo, 'admin_name') - tagAdminName.text = admin_name - tagTlConnection = SubElement(tagTelecentroInfo, 'tl_connection') - tagTlConnection.text = tl_connection - tagTlName = SubElement(tagTelecentroInfo, 'tl_name') - tagTlName.text = tl_name - tagState = SubElement(tagTelecentroInfo, 'state') - tagState.text = state - tagCity = SubElement(tagTelecentroInfo, 'city') - tagCity.text = city - tagTlStreet = SubElement(tagTelecentroInfo, 'tl_street') - tagTlStreet.text = tl_street - tagTlNumber = SubElement(tagTelecentroInfo, 'tl_number') - tagTlNumber.text = tl_number - tagTlZipcode = SubElement(tagTelecentroInfo, 'tl_zipcode') - tagTlZipcode.text = tl_zipcode - tagTlBeneficiary = SubElement(tagTelecentroInfo, 'tl_beneficiary') - tagTlBeneficiary.text = tl_beneficiary - tagTlNeighborhood = SubElement(tagTelecentroInfo, 'tl_neighborhood') - tagTlNeighborhood.text = tl_neighborhood - tagGeolocation = SubElement(tagTelecentroInfo, 'geolocation') - tagGeolocation.text = geolocation - tagSuperid = SubElement(tagTelecentroInfo, 'superid') - tagSuperid.text = superid - tagtUserCount = SubElement(tagTelecentroInfo, 'user_count') + # Collect point's info + idpoint = getPointInfo("idponto") + user_count = getPointInfo("usuarios") + + tagPointInfo = SubElement(mainTag, 'point-info') + tagIdPoint = SubElement(tagPointInfo, 'idpoint') + tagIdPoint.text = idpoint + tagtUserCount = SubElement(tagPointInfo, 'user_count') tagtUserCount.text = user_count # Collect Version @@ -187,7 +154,7 @@ def collect(): # Collect Hard Disk c = wmi.WMI() - tagInventoryDisks = SubElement (tagInventory, 'disks', {'type':'tree'}) + tagInventoryDisks = SubElement (tagInventory, 'disks') i = -1 for disk in c.win32_DiskDrive(): @@ -234,7 +201,7 @@ def collect(): macAddress = macAddress[0:-1] tagMac = SubElement(mainTag, 'interfaces') - tagMacValue = SubElement(tagMac, 'interface', {'name':'', 'mac-addres':macAddress}) + tagMacValue = SubElement(tagMac, 'interface', {'name':'', 'mac-address':macAddress}) tagMachineType = SubElement(mainTag, 'machine-type') tagMachineType.text = 'client' @@ -256,16 +223,16 @@ def netCollect(log): tagAgent = SubElement(mainTag, 'agent-version') tagAgent.text = getRegistryValue("HKEY_LOCAL_MACHINE", "SOFTWARE\\DataSID", "Version") - # Collect Telecentro's id - superid = getTelecentroInfo("superid") - tagTelecentroId = SubElement(mainTag, 'telecentro-id') - tagTelecentroId.text = superid + # Collect Point's id + idpoint = getPointInfo("idponto") + tagPointId = SubElement(mainTag, 'id-point') + tagPointId.text = idpoint # Collect MAC Address macAddress = getMac('localhost') macAddress = macAddress[0:-1] tagMac = SubElement(mainTag, 'interfaces') - tagMacValue = SubElement(tagMac, 'interface', {'name':'', 'mac-addres':macAddress}) + tagMacValue = SubElement(tagMac, 'interface', {'name':'', 'mac-address':macAddress}) # Collect network usage tagUseBandUsage = SubElement(mainTag, 'bandwidth-usage') @@ -293,17 +260,29 @@ def netCollect(log): # Example: if interval = 10:15~10:20 => mean = 10:17:30 intervalId = int(intervalId) + 1 trafficTime = timedelta(minutes=intervalId * 5 - 3) + timedelta(seconds=30) - tagNetUse = SubElement(tagUseBandUsage, 'netuse', {'id':str(intervalId)}) - tagDate = SubElement(tagNetUse, 'date', {'value':trafficDate, 'type':'string'}) - tagTime = SubElement(tagNetUse, 'time', {'value':str(trafficTime), 'type':'string'}) + tagNetUse = SubElement(tagUseBandUsage, 'netuse') + + tagNetUseId = SubElement(tagNetUse, 'id') + tagNetUseId.text = str(intervalId) + + tagDate = SubElement(tagNetUse, 'date') + tagDate.text = trafficDate + + tagTime = SubElement(tagNetUse, 'time') + tagTime.text = str(trafficTime) tagRx = SubElement(tagNetUse, 'rx') - tagPackets = SubElement(tagRx, 'packets', {'value':str(rxPackage), 'type':'int'}) - tagBytes = SubElement(tagRx, 'bytes', {'value':str(rxBytes), 'type':'int'}) + tagRxPackets = SubElement(tagRx, 'rx-packets') + tagRxPackets.text = str(rxPackage) + tagRxBytes = SubElement(tagRx, 'rx-bytes') + tagRxBytes.text = str(rxBytes) tagTx = SubElement(tagNetUse, 'tx') - tagPackets = SubElement(tagTx, 'packets', {'value':str(txPackage), 'type':'int'}) - tagBytes = SubElement(tagTx, 'bytes', {'value':str(txBytes), 'type':'int'}) + tagTxPackets = SubElement(tagTx, 'tx-packets') + tagTxPackets.text = str(txPackage) + tagTxBytes = SubElement(tagTx, 'tx-bytes') + tagTxBytes.text = str(txBytes) + intervalIdOld, rxPackageOld, rxBytesOld, txPackageOld, txBytesOld = intervalId, rxPackageAux, rxBytesAux, txPackageAux, txBytesAux traffic.close() else: