From 6d477839ae0a1a91f993ecbcd8a430f8b11ec6a0 Mon Sep 17 00:00:00 2001 From: lijia Date: Tue, 23 Jul 2019 11:56:52 +0800 Subject: [PATCH] add new files. --- cp.sh | 1 + pkg.sh | 4 + py_bin/.gitignore | 0 .../__pycache__/tsg_diagnose.cpython-36.pyc | Bin 0 -> 2666 bytes .../tsg_hardware_reboot.cpython-36.pyc | Bin 0 -> 625 bytes .../tsg_software_reboot.cpython-36.pyc | Bin 0 -> 588 bytes py_src/tsg_diagnose.py | 135 ++++++++++++++++++ py_src/tsg_hardware_reboot.py | 25 ++++ py_src/tsg_software_reboot.py | 24 ++++ py_temp/.gitignore | 0 readme.md | 1 + 11 files changed, 190 insertions(+) create mode 100644 cp.sh create mode 100644 pkg.sh create mode 100644 py_bin/.gitignore create mode 100644 py_src/__pycache__/tsg_diagnose.cpython-36.pyc create mode 100644 py_src/__pycache__/tsg_hardware_reboot.cpython-36.pyc create mode 100644 py_src/__pycache__/tsg_software_reboot.cpython-36.pyc create mode 100644 py_src/tsg_diagnose.py create mode 100644 py_src/tsg_hardware_reboot.py create mode 100644 py_src/tsg_software_reboot.py create mode 100644 py_temp/.gitignore create mode 100644 readme.md diff --git a/cp.sh b/cp.sh new file mode 100644 index 0000000..d603c68 --- /dev/null +++ b/cp.sh @@ -0,0 +1 @@ +scp -P 51022 py_bin/* 202.43.148.184:/opt/tsg/bin/ diff --git a/pkg.sh b/pkg.sh new file mode 100644 index 0000000..911b210 --- /dev/null +++ b/pkg.sh @@ -0,0 +1,4 @@ +rm -rf ./py_temp/* +pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_software_reboot.py +pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_hardware_reboot.py +pyinstaller -F -y --clean --noconsole --distpath ./py_bin --workpath ./py_temp --specpath ./py_temp ./py_src/tsg_diagnose.py diff --git a/py_bin/.gitignore b/py_bin/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/py_src/__pycache__/tsg_diagnose.cpython-36.pyc b/py_src/__pycache__/tsg_diagnose.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ddf5987d30a43367161b37c5ff5bfe8bfc8721c1 GIT binary patch literal 2666 zcmd5;OK&4Z5bmD0Ur9EbC*m=SWTYUL1W;fjEr@LJMwSvM@@B=#Xf>L+JI>hiuzJQ} zZ8;ar8SxvqapTHg;KIGHobneqQ8kVed!4Xa?PX`w)iqUJ{rbA=n=cB5?BBm^KL2x$ zkblV7V}brHl=uY*Mi});ZCKM9O}~|z!W5=5jp@u_CbL+kVbxTYWx1b8O=EdhfLdoW zY!+&R&9OUBn{1xlh1y~ZY!T`V&$6YKA`+e%kXnwDW}fE;l){Kl$lCG+j7}<2FYTAA zyHelYD^-uAwo@%1Nwrk1O7r{eYNcG+l}6>@sJv5>TDkK0K9zETyV=z7{6dlSA zl-LKsX!^qR8~QovlO|yr4tkT8(58Y*94P0sPnp@G;*?p5+NZ0~9_5L$M9!5&YifPk zR|X0ti4HaPhl|Kmdh>3(ZF{jDMu{ytVd#a8p)GK`$J}PzWqwp|^;R$234RLUiloP}asfL|Es-XQeG<@5k$>QNY)Iuj#q# zN6^K=_WpXi>%^kIp2Q7@d2S<&V*Y8nD;LHM&PgO3=oStci5EZ+IzzMgDtT(r1&UIv zfPDfoTu%zw87K{M2^75oYPiJ+o_b}whEYdb3Lc!!OYkfJPq55ufR_dEb`GD~o!D(~ zJ38aS-r6iq+cu_c4{m7p;D&ZzZ4^ZoRw!~P@*u`Q6a_TSpqNF0TPW_Jm)p2$ue;2PTNC$ZtJs@1!hTO10iP)& zUaM*28)0JM6#pNT#i@LTF<-wDmG{R{0i9sFPLmpDx0K|R%JAl2U)yUfy}&C|V~0HX zF%qpk=pt4?5GpCAgO#Q}~|9HaRPW|SX|ECH6uT%ctCj5V-e#q)LQ#Pbi3u^o)P=QXhO3wuH zxxfFc(%S;X9?_0nkAk+(6V5)dff?-}Vjb?swk!CEbgx+Rohm?(E4!!0c5DDStzNdfTmq(H`->9K0ktZX*o{ddZFX26{HHxKBS72K2qku zj6b#pJe|XJjiN(0;Ep5nC!G-H9Xs`iajEea-uM#I^O+t^>mly4&%eR#O!>ruxmdXc R#VS~H@XlJQ^`%7(`X9I?Se*a> literal 0 HcmV?d00001 diff --git a/py_src/__pycache__/tsg_hardware_reboot.cpython-36.pyc b/py_src/__pycache__/tsg_hardware_reboot.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b7d54d684c4a03c00d713ebac792b9d7bc6b9141 GIT binary patch literal 625 zcmZvYL2uJA6vu5RX+qk9v`t9d!eK&{fC^1;Leol@g-UCR(jum!$qId5o32SJ+ZA+T zr*h&`aOErc%4y#KapGka(hgX9f4}Ev|NXNMnoa-5_m}6tEkb^gJHx~L2t&O^0RnVE z#@m^WDKN0W1_x^3f(Q4e-k5<8^>1Ws2^$)hOdbnsL&lCE^O|rrl%m6sw3;{QMq=ZH z{V<7)(>V>3k+Hi;Z)B`6NsRlUlf=C^GPQUx>UBe7_u`X*agM_`@1sd|xEc%tfk_ub zy+YAsPJwRdH36m>R@Nf|)&+Y=t|?Yk-}*{7j1q0*T;bS=gsToO8A^g5lHc=EOj8HEalT+k{0@j4&<Tw6&^^Y+?Bp_W5#ccK@^fp!z8vg;1aFu=~`bat|xx zah|7H!FkIy79z_!uF7U5|N2Fm3(igBVpZTRicd-q#ui^PeT#TUc5fYD=OwHb;;{M% Q)j;v6SKniv=g}Jd3-Lsw?EnA( literal 0 HcmV?d00001 diff --git a/py_src/__pycache__/tsg_software_reboot.cpython-36.pyc b/py_src/__pycache__/tsg_software_reboot.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dab3160808930bfbf40b2dc205efa9170895ee4a GIT binary patch literal 588 zcmZvY%Wl&^6ozL!z6@>xYKsu;vgslVY9Um_0wF@`8cU6XoFFQrYGgc<)TuAgj3Y=z zS7F7Q@I35h%ZgWE#c`ubT`6b?Yb|29G(9n2>nKP7KQo^gn9?U5yu5e zwizdw8=P>HTioUjr~KZWCI)x;&Ucg$Ve-zUA&&*wpu`erVGC=6F*r<6zxxN=P^2w? zH3r(TMxE!@#0VDDr9Bs|mfbR4iP z^HSzj(>JsWci2T*@j_@)s`*bOcfslJGw-4-^Ucoedsi0tW5KYvA&}TFw6Fm?6h)wUZtgAOm}9h3Z^KQ m)m&&(e9fC1#5=Ng" /* system is unusable */ +#define KERN_ALERT "<1>" /* action must be taken immediately */ +#define KERN_CRIT "<2>" /* critical conditions */ +#define KERN_ERR "<3>" /* error conditions */ +#define KERN_WARNING "<4>" /* warning conditions */ +#define KERN_NOTICE "<5>" /* normal but significant condition */ +#define KERN_INFO "<6>" /* informational */ +#define KERN_DEBUG "<7>" /* debug-level messages */ + +MSG_PREFIX = ['EMERG', 'ALERT', 'CRIT', 'ERR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'] + +def tsg_diagnose_for_app(): + app_msg = ['app is not running', 'app is not running', 'app is not running', 'app maybe deadlock', 'app is reboot in 5 minute'] + app_msg.append('app is running normally') + app_msg.append('app is running normally') + app_msg.append('app is running normally') + + num = random.randint(1,7) + if num <= 4: + msg = "[%s] %s" %(MSG_PREFIX[num], app_msg[num]) + syslog.syslog(num, msg) + print(msg) + return num + +def tsg_diagnose_for_cpu(): + cpu_msg = [] + cpu_msg.append('CPU usage over 95%') + cpu_msg.append('CPU usage over 90%') + cpu_msg.append('CPU usage over 85%') + cpu_msg.append('CPU usage over 80%') + cpu_msg.append('CPU usage over 70%') + + num = random.randint(1,7) + if num <= 4: + msg = "[%s] %s" %(MSG_PREFIX[num], cpu_msg[num]) + syslog.syslog(num, msg) + print(msg) + return num + + +def tsg_diagnose_for_mem(): + mem_msg = [] + mem_msg.append('free memory less than 1%') + mem_msg.append('free memory less than 5%') + mem_msg.append('free memory less than 10%') + mem_msg.append('free memory less than 15%') + mem_msg.append('free memory less than 20%') + + num = random.randint(1,7) + if num <= 4: + msg = "[%s] %s" %(MSG_PREFIX[num], mem_msg[num]) + syslog.syslog(num, msg) + print(msg) + return num + + +def tsg_diagnose_for_disk(): + disk_msg = [] + disk_msg.append('disk usage over 99%') + disk_msg.append('disk usage over 95%') + disk_msg.append('disk usage over 90%') + disk_msg.append('disk usage over 85%') + disk_msg.append('disk usage over 80%') + + num = random.randint(1,7) + if num <= 4: + msg = "[%s] %s" %(MSG_PREFIX[num], disk_msg[num]) + syslog.syslog(num, msg) + print(msg) + return num + +def tsg_diagnose_for_network(): + return 7 + +def tsg_diagnose(): + + log_handle = syslog.openlog("TSG-MXN") + + diagnose_level = syslog.LOG_DEBUG + + #check app, not running, dead-lock + check_ret = tsg_diagnose_for_app() + if check_ret < diagnose_level: + diagnose_level = check_ret + + #error, critical return immediately + if diagnose_level <= syslog.LOG_WARNING: + return diagnose_level + + #check app, drop packet, traffic bps + check_ret = tsg_diagnose_for_network() + if check_ret < diagnose_level: + diagnose_level = check_ret + #error, critical return immediately + if diagnose_level <= syslog.LOG_WARNING: + return diagnose_level + + + #check cpu, more than 80%, 90%, 95% + check_ret = tsg_diagnose_for_cpu() + if check_ret < diagnose_level: + diagnose_level = check_ret + #error, critical return immediately + if diagnose_level <= syslog.LOG_WARNING: + return diagnose_level + + #check mem, free memory less than 10% + check_ret = tsg_diagnose_for_mem() + if check_ret < diagnose_level: + diagnose_level = check_ret + #error, critical return immediately + if diagnose_level <= syslog.LOG_WARNING: + return diagnose_level + + + #check disk, free disk space less than 5% + check_ret = tsg_diagnose_for_mem() + if check_ret < diagnose_level: + diagnose_level = check_ret + #error, critical return immediately + if diagnose_level <= syslog.LOG_WARNING: + return diagnose_level + + #if not error, output success + syslog.syslog(syslog.LOG_DEBUG, "TSG diagnose completed, all modules are running normally!") + print ("TSG diagnose completed, all modules are running normally!") + return 0 + +if __name__ == '__main__': + fun_res_code = tsg_diagnose() + sys.exit(fun_res_code) diff --git a/py_src/tsg_hardware_reboot.py b/py_src/tsg_hardware_reboot.py new file mode 100644 index 0000000..3e48c5f --- /dev/null +++ b/py_src/tsg_hardware_reboot.py @@ -0,0 +1,25 @@ +import sys +import syslog + +##define KERN_EMERG "<0>" /* system is unusable */ +##define KERN_ALERT "<1>" /* action must be taken immediately */ +##define KERN_CRIT "<2>" /* critical conditions */ +##define KERN_ERR "<3>" /* error conditions */ +##define KERN_WARNING "<4>" /* warning conditions */ +##define KERN_NOTICE "<5>" /* normal but significant condition */ +##define KERN_INFO "<6>" /* informational */ +##define KERN_DEBUG "<7>" /* debug-level messages */ + +MSG_PREFIX = ['EMERG', 'ALERT', 'CRIT', 'ERR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'] + +def tsg_hardware_reboot(): + log_handle = syslog.openlog("TSG-MXN") + msg = "[%s] %s" %(MSG_PREFIX[syslog.LOG_ERR], "hardware reboot error, cant't run this command in test period!") + + syslog.syslog(syslog.LOG_ERR, msg) + print (msg) + return 1 + +if __name__ == '__main__': + fun_res_code = tsg_hardware_reboot() + sys.exit(fun_res_code) diff --git a/py_src/tsg_software_reboot.py b/py_src/tsg_software_reboot.py new file mode 100644 index 0000000..f1c0722 --- /dev/null +++ b/py_src/tsg_software_reboot.py @@ -0,0 +1,24 @@ +import sys +import syslog + +##define KERN_EMERG "<0>" /* system is unusable */ +##define KERN_ALERT "<1>" /* action must be taken immediately */ +##define KERN_CRIT "<2>" /* critical conditions */ +##define KERN_ERR "<3>" /* error conditions */ +##define KERN_WARNING "<4>" /* warning conditions */ +##define KERN_NOTICE "<5>" /* normal but significant condition */ +##define KERN_INFO "<6>" /* informational */ +##define KERN_DEBUG "<7>" /* debug-level messages */ + +MSG_PREFIX = ['EMERG', 'ALERT', 'CRIT', 'ERR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'] + +def tsg_software_reboot(): + log_handle = syslog.openlog("TSG-MXN") + msg = "[%s] %s" %(MSG_PREFIX[syslog.LOG_INFO], "software reboot success.") + syslog.syslog(syslog.LOG_INFO, msg) + print (msg) + return 0 + +if __name__ == '__main__': + fun_res_code = tsg_software_reboot() + sys.exit(fun_res_code) diff --git a/py_temp/.gitignore b/py_temp/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..9afd39d --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +TSG CLI Command Source, such as tsg_diagnose,tsg_hardware_reboot,tsg_software_reboot. \ No newline at end of file