· 2 years ago · Sep 14, 2023, 07:55 PM
1 # omissis
2
3 elif tag=='configuremonitor':
4 endpoint = f"{settings['Shinobi']['url']}:{settings['Shinobi']['port']}/{settings['Shinobi']['api_key']}/configureMonitor/{settings['Shinobi']['group_key']}/{selection}"
5 queryurl = f"{settings['Shinobi']['url']}:{settings['Shinobi']['port']}/{settings['Shinobi']['api_key']}/monitor/{settings['Shinobi']['group_key']}/{selection}"
6 response = requests.get(queryurl)
7 if response.status_code != 200:
8 print(f'Error {response.status_code} something went wrong, request error \u26A0\ufe0f')
9 await context.bot.send_message(chat_id=update.effective_chat.id, text='Error something went wrong, request error \u26A0\ufe0f')
10 return
11 else:
12 print(f'OK, server touched... \U0001F44D')
13 await context.bot.send_message(chat_id=update.effective_chat.id, text=f'OK, done \U0001F44D')
14 data=disAssebleMonitor(response.json())
15 print(f'posting data: \n {data}')
16 response = requests.post(endpoint, data=data)
17 if response.status_code != 200:
18 print(f'Error {response.status_code} something went wrong, request error \u26A0\ufe0f')
19 print(response.text)
20 await context.bot.send_message(chat_id=update.effective_chat.id, text='Error something went wrong, request error \u26A0\ufe0f')
21 return
22 else:
23 print(f'OK, done \U0001F44D')
24 print(response.text)
25 await context.bot.send_message(chat_id=update.effective_chat.id, text=f'OK, done \U0001F44D')
26
27
28def disAssebleMonitor(response):
29 print('disassembling monitor...')
30 #response = response.json()
31 monitor=response[0]
32 monitor['details']=json.loads(monitor.get('details'))
33 monitor['details']['snap'] = "1"
34 #monitor['details']=str(monitor.get('details'))
35 # monitor.pop('details')
36 print('reassembling monitor...')
37 # Needed keys to make API query
38 keys=['mode', 'mid', 'name', 'tags', 'type', 'protocol', 'host', 'port', 'path', 'height', 'width', 'ext', 'fps', 'details']
39 query={}
40 for key in keys:
41 query[key]=monitor.get(key)
42 return(json.dumps(query, indent=4))