1

我编写了一个机器人来检查 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)
4

1 回答 1

-1
bot.stop_polling()  but this = exit
于 2020-12-04T23:22:19.147 回答