From b4672b5a6d5e07a85b2f97338db9b55df9fdaa85 Mon Sep 17 00:00:00 2001 From: "n.brusnika" Date: Wed, 26 May 2021 14:46:34 +0400 Subject: [PATCH] with fail --- connect.py | 27 +++++++++++++++++++++++++++ filename.txt | 1 + get_json.py | 27 +++++++++++++++------------ test.py | 14 ++++++++++++++ 4 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 connect.py create mode 100644 filename.txt create mode 100644 test.py diff --git a/connect.py b/connect.py new file mode 100644 index 0000000..c8bf3a5 --- /dev/null +++ b/connect.py @@ -0,0 +1,27 @@ +import paramiko, sys + + +def connect_device(): + + + host = "10.16.50.61" + port = 22 + username = "root" + password = "ya_lublu_delat_karasa_311" + + command = "tail -n 10 /userdata/log/ace_device.log" + + print() + + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(host, port, username, password) + + with open('filename.txt', 'w') as f: + sys.stdout = f + stdin, stdout, stderr = ssh.exec_command(command) + lines = stdout.readlines() + print(lines) + +if __name__ == "__main__": + connect_device() diff --git a/filename.txt b/filename.txt new file mode 100644 index 0000000..6b30c43 --- /dev/null +++ b/filename.txt @@ -0,0 +1 @@ +['2021-05-26 09:40:05.932 DEBUG [10614] [BestShotObserver::estimateFrame@70] RGB Frame id: 329941, Track id: 35, size: 384x640\n', '2021-05-26 09:40:05.945 DEBUG [10614] [FaceSizeEstimator::estimate@32] Frame id: 329941, face size: 34 >= 80, FAIL\n', '2021-05-26 09:40:05.993 DEBUG [10614] [BestShotObserver::bestShot@42] BestShotObserver::bestShot Track id: 35, Frame id:329942, bbox: {x:160,y:359,w:34,h:47}\n', '2021-05-26 09:40:05.994 DEBUG [10614] [BestShotObserver::estimateFrame@70] RGB Frame id: 329942, Track id: 35, size: 384x640\n', '2021-05-26 09:40:06.009 DEBUG [10614] [FaceSizeEstimator::estimate@32] Frame id: 329942, face size: 34 >= 80, FAIL\n', '2021-05-26 09:40:06.009 DEBUG [10614] [BestShotObserver::bestShot@42] BestShotObserver::bestShot Track id: 35, Frame id:329943, bbox: {x:160,y:359,w:34,h:46}\n', '2021-05-26 09:40:06.009 DEBUG [10614] [BestShotObserver::estimateFrame@70] RGB Frame id: 329943, Track id: 35, size: 384x640\n', '2021-05-26 09:40:06.029 DEBUG [10614] [FaceSizeEstimator::estimate@32] Frame id: 329943, face size: 34 >= 80, FAIL\n', '2021-05-26 09:40:06.029 DEBUG [10614] [BestShotObserver::bestShot@42] BestShotObserver::bestShot Track id: 35, Frame id:329944, bbox: {x:160,y:361,w:34,h:44}\n', '2021-05-26 09:40:06.030 DEBUG [10614] [BestShotObserver::estimateFrame@70] RGB Frame id: 329944, Track id: 35, size: 384x640\n'] diff --git a/get_json.py b/get_json.py index c8951e8..2eee87d 100644 --- a/get_json.py +++ b/get_json.py @@ -1,10 +1,10 @@ import requests, json, time - +from connect import connect_device def check_status(): while True: try: - content = requests.get("https://10.16.8.90/monitoring/", verify=False, timeout=10) + content = requests.get("https://10.16.8.87/monitoring/", verify=False, timeout=20) except: telegram_bot_sendtext('server not resolve') @@ -19,24 +19,27 @@ def check_status(): service_name = service_status[0] srv_status = service_status[1]['status'] - if srv_status != 1: - telegram_bot_sendtext('Service Down - {0}'.format(service_name)) - + telegram_bot_sendtext('Service Core Down - {0}'.format(service_name)) for device in devices_list.items(): dvc_name = device[0] - #print(dvc_name) dvc_status = device[1]['status'] - dvc_services = device[1]['subservices'] + print(device[1]['status']) + dvc_services = json.dumps(device[1]['subservices']).replace("_", "") + print(dvc_services) + + #тут изменить обратно на правильный статус 2 + if dvc_status == 1: + #save log to file + connect_device() + print(telegram_bot_sendtext('Device services has Problem - {0} {1}'.format(dvc_name, dvc_services))) - if dvc_status == 2: - telegram_bot_sendtext('Device services has Problem - {0}-{1}'.format(dvc_name, dvc_services)) elif dvc_status == 0: - telegram_bot_sendtext('Device Down - {0}'.format(dvc_name)) + telegram_bot_sendtext('Device Down - {0}'.format(dvc_name)) else: - pass + pass time.sleep(10) @@ -52,4 +55,4 @@ def telegram_bot_sendtext(bot_message): if __name__ == "__main__": - check_status() + check_status() \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..9d29885 --- /dev/null +++ b/test.py @@ -0,0 +1,14 @@ +import telegram + +def send_msg(text): + token = '1400084494:AAGJX-WtbA6eJy0PAwe7u2Jtsnzp7bpSuXU' + chat_id = '-381749129' + bot = telegram.Bot(token=token) + for i in text: + bot.sendMessage(chat_id=chat_id, text=i) + +new_list = [] +with open("filename.txt", 'r', encoding="utf-8") as file: + new_list = file.read() +for i in new_list: + send_msg(i) \ No newline at end of file