diff --git a/ricochet/monitoring/ricochetdb.py b/ricochet/monitoring/ricochetdb.py index 4a95486b91c6e54281571ff3afaa222659f6dc8b..c1da985ee9c7813814e898b1994e6ff3f716a2e4 100644 --- a/ricochet/monitoring/ricochetdb.py +++ b/ricochet/monitoring/ricochetdb.py @@ -624,6 +624,8 @@ class DataFetcher: res = r.json()[0] if(res['unit']=="kg"): data[res['scale_name']]=res['value'] + else: + data[res['name']]=res['value'] def __get_data_from_mmr3_http__(self,device_ip_address, data, file_location): diff --git a/utils/conf_ill/fetch_data.conf b/utils/conf_ill/fetch_data.conf new file mode 100644 index 0000000000000000000000000000000000000000..dcec54c45ae82c35ff5f8a0d84f6603f376d0a45 --- /dev/null +++ b/utils/conf_ill/fetch_data.conf @@ -0,0 +1,5 @@ +{ + "data_sources": [ + ["JSON-CRYO","lyomanoirsrv02.in2p3.fr","/records"] + ] +} diff --git a/utils/conf_ill/mapping.json b/utils/conf_ill/mapping.json new file mode 100644 index 0000000000000000000000000000000000000000..690f9f177d104baff26779870e28ffd933d361d3 --- /dev/null +++ b/utils/conf_ill/mapping.json @@ -0,0 +1,3 @@ +{ + "ricochet_cpu_temp": "test_server_cpu" +} diff --git a/utils/fetch_data.py b/utils/fetch_data.py index 2773f4ba51ee492d694eb1554623a1f19e7f4556..362fbc3121f6494024fc31c98052d581c29981f8 100644 --- a/utils/fetch_data.py +++ b/utils/fetch_data.py @@ -4,6 +4,7 @@ from ricochet.monitoring.ricochetdb import Database from datetime import datetime import getopt import sys +import os import json server = None @@ -12,16 +13,19 @@ passw = None db_name = None datasource_conf = None mapping_conf = None +output_dir_name = None try: - opts, args = getopt.getopt(sys.argv[1:],"hs:u:p:n:d:m:",["server=","user=","password=","db_name=","datasource_conf=","mapping_conf="]) + opts, args = getopt.getopt(sys.argv[1:],"hs:u:p:n:d:m:o:",["server=","user=","password=","db_name=","datasource_conf=","mapping_conf=","output_dir"]) except getopt.GetoptError: print(sys.argv[0],'-s <db server name> -u <user> -p <password> -n <db_name> -d <datasources_file> -m <mapping_file>') + print(sys.argv[0],'-o <output dir name> -d <datasources_file> -m <mapping_file>') sys.exit(2) for opt, arg in opts: if opt == '-h': print(sys.argv[0],'-s <db server name> -u <user> -p <password> -n <db_name> -d <datasources_file> -m <mapping_file>') + print(sys.argv[0],'-o <output dir name> -d <datasources_file> -m <mapping_file>') sys.exit(2) elif opt in ("-s", "--server"): server = str(arg) @@ -31,12 +35,14 @@ for opt, arg in opts: passw = str(arg) elif opt in ("-n", "--db_name"): db_name = str(arg) + elif opt in ("-o", "--output_dir"): + output_dir_name = str(arg) elif opt in ("-d", "--datasource_conf"): datasource_conf = str(arg) elif opt in ("-m", "--mapping_conf"): mapping_conf = str(arg) -if(server==None or user==None or passw==None or db_name==None): +if(output_dir_name==None and (server==None or user==None or passw==None or db_name==None)): print(sys.argv[0],'-s <db server name> -u <user> -p <password> -n <db_name> -d <datasources_file> -m <mapping_file>') sys.exit(2) @@ -53,11 +59,14 @@ with open(datasource_conf) as f: except UnicodeDecodeError: raise RuntimeError("Can't read configuration file "+str(datasource_conf)+"!") -db = Database.get_database() -db.set_address("mongodb://"+user+":"+passw+"@"+server) -db.set_db_name(db_name) +if(output_dir_name is None): + db = Database.get_database() + db.set_address("mongodb://"+user+":"+passw+"@"+server) + db.set_db_name(db_name) year = datetime.utcnow().year +month = datetime.utcnow().month +day = datetime.utcnow().day try: fetcher = DataFetcher(mapping_file=mapping_conf) @@ -65,9 +74,15 @@ try: if(len(ds)==3): fetcher.add_datasource(ds[0],ds[1],ds[2]) fetcher.fetch("imacrt") - fetcher.upload("mmr3-"+str(year)) + if(output_dir_name is None): + fetcher.upload("mmr3-"+str(year)) + else: + fetcher.move_to_file(os.path.join(output_dir_name,"mmr3-"+str(year)+"_"+str(month)+"_"+str(day)+".json")) fetcher.fetch("cryostat") - fetcher.upload("cryo-"+str(year)) + if(output_dir_name is None): + fetcher.upload("cryo-"+str(year)) + else: + fetcher.move_to_file(os.path.join(output_dir_name,"cryo-"+str(year)+"_"+str(month)+"_"+str(day)+".json")) except RuntimeError as e: print("Error in fetch_data : ",e) except SyntaxError as e: