blob: 6d0d3102b6a3b81ef4c7c11beb093206f6913c4d [file] [log] [blame]
Enbo Wang6ab8b622019-04-23 13:42:21 +00001#!/usr/bin/python
2
3import time
4import json
5import jsonpath
6
7import conf
8
9
10def get_ne_info_list_from_db(ne_filter):
11 with open(conf.NE_INFO_TABLE) as f_ne_info:
12 ne_info_table = json.load(f_ne_info)
13
14 if ne_info_table:
15 ne_info_list = jsonpath.jsonpath(ne_info_table, ne_filter)
16 return ne_info_list if ne_info_list else []
17 else:
18 return []
19
20
21def get_ne_info_from_db_by_id(ne_id):
22 ne_filter = '$..[?(@.nEIdentification == "%s")]' % ne_id
23
24 ne_info_list = get_ne_info_list_from_db(ne_filter)
25
26 return ne_info_list[0] if ne_info_list else None
27
28
29def update_ne_info(ne_info):
30 with open(conf.NE_INFO_TABLE) as f_ne_info:
31 ne_info_table = json.load(f_ne_info)
32
33 ne_info["updateTime"] = time.asctime()
34
35 if ne_info_table:
36 for i in range(0, len(ne_info_table)):
37 if ne_info_table[i]["nEIdentification"] == ne_info["nEIdentification"]:
38 ne_info_table[i] = ne_info
39 break
40 else:
41 ne_info_table.append(ne_info)
42 else:
43 ne_info_table = [ne_info]
44
45 with open(conf.NE_INFO_TABLE, 'w') as f_ne_info:
46 json.dump(ne_info_table, f_ne_info, indent=2)
47
48
49def send_notification(notification, process_id):
50 notification_file = conf.NOTIFICATION_DIR + '/%s-%d' % (notification['notificationType'], process_id)
51
52 with open(notification_file, 'w') as f_notification:
53 f_notification.write(json.dumps(notification))