add new files.
This commit is contained in:
BIN
py_src/__pycache__/tsg_diagnose.cpython-36.pyc
Normal file
BIN
py_src/__pycache__/tsg_diagnose.cpython-36.pyc
Normal file
Binary file not shown.
BIN
py_src/__pycache__/tsg_hardware_reboot.cpython-36.pyc
Normal file
BIN
py_src/__pycache__/tsg_hardware_reboot.cpython-36.pyc
Normal file
Binary file not shown.
BIN
py_src/__pycache__/tsg_software_reboot.cpython-36.pyc
Normal file
BIN
py_src/__pycache__/tsg_software_reboot.cpython-36.pyc
Normal file
Binary file not shown.
135
py_src/tsg_diagnose.py
Normal file
135
py_src/tsg_diagnose.py
Normal file
@@ -0,0 +1,135 @@
|
||||
import sys
|
||||
import syslog
|
||||
import random
|
||||
|
||||
#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_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)
|
||||
25
py_src/tsg_hardware_reboot.py
Normal file
25
py_src/tsg_hardware_reboot.py
Normal file
@@ -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)
|
||||
24
py_src/tsg_software_reboot.py
Normal file
24
py_src/tsg_software_reboot.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user