Simple monitoring – Chương trình monitor mạng đơn giản.

Chương trình được viết bằng python

Hướng dẫn cài đặt:

Cài đặt python3, và các gói cần thiết
yum install epel-release -y & yum install python36 python36-pip.noarch -y && pip3 install requests

Cách chạy app, sau khi thay cấu hình trong file config.py
cd <đường dẫn thư mục app>
python3 monitor_simple.py

Cách thiết lập chạy mỗi phút 1 lần:
crontab -l
Thêm vào dòng sau:
* * * * * /usr/bin/python3 <đường dẫn file monitor_simple.py>

Download:

https://github.com/khachuy2705/monitor_simple

Regular Expressions cơ bản

Cú pháp cơ bản:

.             1 ký tự bất kỳ, ngoại trừ xuống dòng
\.            dấu chấm (\ thể hiện escape)
\d            Một ký tự số
\D            Một ký tự không phải là số
\w            Một chữ hoặc số
\W            Một ký tự không phải là chữ
\s            một Dấu cách
\S            Một ký tự không phải dấu cách
\b            1 từ nguyên vẹn
\n            Xuống dòng
\t            Tab

Modifiers

$             Bắt đầu chuỗi
^             bắt đầu chuỗi
ab|cd         Matches ab hoặc cd.
[ab-d]	      Match a và match các ký tự từ b --> d = bcd
[^ab-d]	      One character except: a, b, c, d
()            Items within parenthesis are retrieved
(a(bc))       Items within the sub-parenthesis are retrieved

Repetitions

[ab]{2}       Exactly 2 continuous occurrences of a or b
[ab]{2,5}     2 to 5 continuous occurrences of a or b
[ab]{2,}      2 or more continuous occurrences of a or b
+             One or more
*             Zero or more
?             0 or 1

 

Xử lý lỗi KeyError khi ghép chuỗi python

Case:
chat_id=428519060
noidung='test'
body='''{"chat_id":"{}","text":"{}"}'''.format(chat_id,noi_dung)
KeyError: '"chat_id"'

Nguyên nhân: do sử dụng hàm format, nên trong chuỗi có dấu { hoặc } sẽ bị lỗi.
Xử lý: bằng cách thay { bằng {{ và } bằng }}
body='''{{"chat_id":"{}","text":"{}"}}'''.format(chat_id,noidung)
'{"chat_id":"428519060","text":"test"}'


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/devopsvn/public_html/wp-includes/functions.php on line 5427