次のコマンドを使用して、snmp で負荷平均をチェックするボットを作成しました: snmpwalk -v3 -l authNoPriv -u admin -a SHA -A "admin" ' + server + ' .1.3.6.1.4.1.2021.10.1.3.1
また、stop コマンドで while ループを抜けられません。
bot = telebot.TeleBot('xxxxx')
@bot.message_handler(commands=['start'])
def start(message):
sent = bot.send_message(message.chat.id, 'Please input server (example 192.168.0.1)')
bot.register_next_step_handler(sent, cores)
def cores(message):
global server
server = (message.text)
sent2 = bot.send_message(message.chat.id, 'Input number of cores')
bot.register_next_step_handler(sent2, botstarted)
def botstarted(message):
global core
global bye
core = (message.text)
cores = float(core)
bot.send_message(message.chat.id, 'Check started, if load average more then number of cores you get Warning message to stop enter /stop')
while (True):
b = os.popen('snmpwalk -v3 -l authNoPriv -u admin -a SHA -A "admin" ' + server + ' .1.3.6.1.4.1.2021.10.1.3.1').read()
d = (b[39:43])
c = float(b[39:43])
if c > cores:
bot.send_message(message.chat.id, 'Warning, huge load average: ' + d)
print(c)
time.sleep(10)
@bot.message_handler(commands=['stop'])
def stop(message):
sent3 = bot.send_message(message.chat.id, 'bye')
print(sent3)
bot.polling(none_stop=True)