Skip to content
Snippets Groups Projects
Commit 86d5ccc0 authored by Riccardo Sellari's avatar Riccardo Sellari
Browse files

maybe the real working version

parent b23651fb
No related branches found
No related tags found
No related merge requests found
...@@ -7,25 +7,26 @@ import os ...@@ -7,25 +7,26 @@ import os
import re import re
import json import json
#dafneStat #dafneStat
def jsonData2Influx(fileData,clientMemcached): def jsonData2Influx(fileData,clientMemcached):
jsonData = clientMemcached.get(fileData['keybind']) jsonData = clientMemcached.get(fileData['keybind'])
fileData['memcached'] = json.loads(jsonData) fileData['memcached'] = json.loads(jsonData)
payload = []
fields = {}
for field in fileData["memcached"]: for field in fileData["memcached"]:
payload = [] fields [field] = fileData["memcached"][field]
payload.append({ payload.append({
"measurement": "dafneStat", "measurement": "dafneStat",
"tags": { "tags": {
"key": fileData["keybind"] "key": fileData["keybind"]
}, },
"fields": { "fields": fields
field:fileData["memcached"][field] })
}
})
return payload return payload
def findTheKey(configFile,path): def findTheKey(configFile):
data = {} data = {}
#find all the line with usefull data, except for keybind #find all the line with usefull data, except for keybind
pattern = r'^"(.+)":(.+,(( ←)|[^a-zA-Z ]))' pattern = r'^"(.+)":(.+,(( ←)|[^a-zA-Z ]))'
...@@ -77,13 +78,16 @@ except: ...@@ -77,13 +78,16 @@ except:
try: try:
if os.path.isfile(args.file): if os.path.isfile(args.file):
with open(args.file,'r') as configFile: with open(args.file,'r') as configFile:
while not (False): while (True):
fileData = findTheKey(configFile, clientMemcached) fileData = findTheKey(configFile)
payload = [] payload = []
print (type(fileData))
if fileData == None:
break
if fileData["type"] == "json": if fileData["type"] == "json":
payload = jsonData2Influx(fileData,clientMemcached) payload = jsonData2Influx(fileData,clientMemcached)
clientInflux.write_points(payload) print (payload)
clientInflux.write_points(payload)
except FileNotFoundError as e: except FileNotFoundError as e:
sys.exit("Error: " + args.iptable + " is not valid or does not point to a DBFile.") sys.exit("Error: " + args.iptable + " is not valid or does not point to a DBFile.")
except TypeError as e: print("program ended succesfully")
print("program ended succesfully") \ No newline at end of file
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment