def start_bot_for_monitoring(update, context): user_data = context.user_data # This takes care to check if user ip address is there in memory or not. if 'ip_address' not in user_data: update.message.reply_text( "Ip not set. Please user /setIp to set the Ip of the system to monitor" ) return ConversationHandler.END else: ip_address = user_data['ip_address'] # Checking if Ip address is a valid regex, and setting up initial parameters if check_ip(ip_address): # Making arrangements to store parameters asked by bot initialize_variables_for_bot(update, context) # Variables initialized in memory, preparing to send welcome message to user update.message.reply_text( "Cool, You chose to start monitoring system {}".format( ip_address)) update.message.reply_text("Please enter your choice based on the above instructions", \ reply_markup = monitor_markup) return CHOOSING_BOT_PARAMS else: update.message.reply_text( "You set up an improper Ip, please setup a proper one at /setIp" ) return ConversationHandler.END
def start_monitoring_new(update, context): user_data = context.user_data if 'ip_address' not in user_data: update.message.reply_text( "Ip not set. Please user /setIp to set the Ip of the system to monitor" ) return ConversationHandler.END else: if 'monitor' not in user_data: step = 1 user_data['monitor'] = {} user_data['monitor']['step'] = step else: step = user_data['monitor']['step'] ip_address = user_data['ip_address'] if check_ip(ip_address): if step == 1: update.message.reply_text( "Cool, You chose to start monitoring system {}".format( ip_address)) update.message.reply_text(bot_response_for_new_monitoring_start) update.message.reply_text( "Please enter your choice based on the above instructions") return USER_RESPONSE else: update.message.reply_text( "You set up an improper Ip, please setup a proper one at /setIp" ) return ConversationHandler.END
def storing_or_modifying_ip(update, context): user_data = context.user_data text = update.message.text category = user_data['choice'] if check_ip(text): update.message.reply_text("Your Ip Address is set to {}".format(text), reply_markup=markup) user_data['ip_address'] = text del user_data['choice'] else: update.message.reply_text( "You set up an improper Ip, Please change it.") return CHOOSING
def probe_server_from_bot(update, context): user_data = context.user_data if 'ip_address' not in user_data: update.message.reply_text( "Your Ip address is not set. Set it up at /setIp") elif check_ip(user_data['ip_address']): ip_address = user_data['ip_address'] if probe_server(ip_address): update.message.reply_text("Server is up and running") else: update.message.reply_text( "Server seems down, Is the client side part working or is your server up ? Please check" ) else: update.message.reply_text( "You set up an improper Ip, please setup a proper one")
def start_deleting_scheduled_update(update, context): user_data = context.user_data if 'ip_address' not in user_data: update.message.reply_text( "Ip not set. Please user /setIp to set the Ip of the system to delete scheduled monitoring" ) else: ip_address = user_data['ip_address'] if check_ip(ip_address): update.message.reply_text( "You chose to delete a scheduler for the system {}. Please enter the name of the scheduler" .format(ip_address)) return CHOOSING else: update.message.reply_text( "You set up an improper Ip, please setup a proper one at /setIp" )
def start_monitoring(update, context): user_data = context.user_data if 'ip_address' not in user_data: update.message.reply_text( "Ip not set. Please user /setIp to set the Ip of the system to monitor" ) else: ip_address = user_data['ip_address'] if check_ip(ip_address): update.message.reply_text( "You chose to start monitoring system {}".format(ip_address), reply_markup=monitor_markup) return CHOOSING else: update.message.reply_text( "You set up an improper Ip, please setup a proper one at /setIp" )
def choose_options_for_monitoring(update, context): user_data = context.user_data print(user_data) if 'ip_address' not in user_data: update.message.reply_text( "Ip not set. Please user /setIp to set the Ip of the system to monitor" ) return ConversationHandler.END else: if 'monitor' not in user_data: print(1) state = 'initial' user_data['monitor'] = {} user_data['monitor']['state'] = state else: state = user_data['monitor']['state'] ip_address = user_data['ip_address'] if check_ip(ip_address): if user_data['monitor']['state'] == 'initial': update.message.reply_text( "Cool, You chose to start monitoring system {}".format( ip_address)) elif state == 'Exit': update.message.reply_text('Already defined values for monitoring. Do you want to reset things?',\ reply_markup = ReplyKeyboardMarkup([['Yes'], ['No']], one_time_keyboard=True)) return USER_RESPONSE # update.message.reply_text('Choose from the below value') update.message.reply_text("Please enter your choice based on the above instructions", \ reply_markup = monitor_markup) return USER_RESPONSE else: update.message.reply_text( "You set up an improper Ip, please setup a proper one at /setIp" ) return ConversationHandler.END