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

maybe it's working

parent 577891f8
No related branches found
No related tags found
No related merge requests found
...@@ -8,9 +8,9 @@ import re ...@@ -8,9 +8,9 @@ import re
import json import json
#dafneStat #dafneStat
def jsonData2Influx(fileData,clientMemcached):
def jsonPost2Influx(fileData,clientMemcached,clientInflux): jsonData = clientMemcached.get(fileData['keybind'])
fileData['memcached'] = json.load(clientMemcached.get(fileData['keybind'])) fileData['memcached'] = json.loads(jsonData)
payload = [] payload = []
payload.append({ payload.append({
"measurement": "dafneStat", "measurement": "dafneStat",
...@@ -21,6 +21,7 @@ def jsonPost2Influx(fileData,clientMemcached,clientInflux): ...@@ -21,6 +21,7 @@ def jsonPost2Influx(fileData,clientMemcached,clientInflux):
"data": json.dumps(fileData["memcached"]) "data": json.dumps(fileData["memcached"])
} }
}) })
return payload
def findTheKey(configFile,path): def findTheKey(configFile,path):
data = {} data = {}
...@@ -31,13 +32,13 @@ def findTheKey(configFile,path): ...@@ -31,13 +32,13 @@ def findTheKey(configFile,path):
match = re.search(pattern,line) match = re.search(pattern,line)
parameter = re.sub(r',|"|( ←)',"",match.group(2)) parameter = re.sub(r',|"|( ←)',"",match.group(2))
data[match.group(1)] = parameter data[match.group(1)] = parameter
if(line.find('keybind') != -1): elif(line.find('keybind') != -1):
line = re.sub(r',|( ←)',"",line) line = re.sub(r',|( ←)',"",line)
pattern = r'"(.+)":"(.+)"' pattern = r'"(.+)":"(.+)"'
match = re.search(pattern,line) match = re.search(pattern,line)
data[match.group(1)] = match.group(2) data[match.group(1)] = match.group(2)
return data return data
...@@ -56,6 +57,7 @@ args = parser.parse_args() ...@@ -56,6 +57,7 @@ args = parser.parse_args()
#python memcached2Influx.py -s vldantemon003.lnf.infn.it -po 8086 -f '/home/riccardo/Random bs go/Test/cofnigurationFile.txt' #python memcached2Influx.py -s vldantemon003.lnf.infn.it -po 8086 -f '/home/riccardo/Random bs go/Test/cofnigurationFile.txt'
#try: #try:
clientInflux = InfluxDBClient(host=args.server, port=args.port, username=args.username, password=args.password) clientInflux = InfluxDBClient(host=args.server, port=args.port, username=args.username, password=args.password)
clientInflux.switch_database("dcsMemDb")
print("succesfully logged in\n") print("succesfully logged in\n")
#except: #except:
# sys.exit("Error: Invalid parameters, please try again") # sys.exit("Error: Invalid parameters, please try again")
...@@ -68,10 +70,16 @@ try: ...@@ -68,10 +70,16 @@ try:
except: except:
sys.exit('Cannot reach the memcached server, try again later') sys.exit('Cannot reach the memcached server, try again later')
#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:
fileData = findTheKey(configFile, clientMemcached) while not (False):
jsonPost2Influx(fileData,clientMemcached,clientInflux) fileData = findTheKey(configFile, clientMemcached)
#except FileNotFoundError as e: payload = []
# sys.exit("Error: " + args.iptable + " is not valid or does not point to a DBFile.") if fileData["type"] == "json":
\ No newline at end of file payload = jsonData2Influx(fileData,clientMemcached)
clientInflux.write_points(payload)
except FileNotFoundError as e:
sys.exit("Error: " + args.iptable + " is not valid or does not point to a DBFile.")
except TypeError as e:
print("banana")
\ 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