cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
777
Views
2
Helpful
11
Replies

webex_bot package to be installed on Linux OS systems

o1
Cisco Employee
Cisco Employee

Hi Team,

I am using a webex_bot package with python3.11 on my personal system from where I can connect to the bot & send notifications based on the requirements.

But the same code if I try to execute from UCS servers where I have CentOS7/Redhat installed, I am getting webex_bot package not available error. I tried different ways to install webex_bot on my UCS systems with Python 3.6 or Python3.11, but it doesn't work.

Though it's working on my local system, I cant use it for 24X7 health check of the devices. I want to trigger the python job from either m UCS or ESXi hosts to take care of required notification 24X7, but the problem is with the webex_bot package installation. Can someone please help here or share a wiki which could guide to have a proper installation of webex_bot>

Local Machine:

etc % python3.11
Python 3.11.4 (v3.11.4:d2340ef257, Jun 6 2023, 19:15:51) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import webex_bot

 

UCS server:

[root@<server_name> library]# python3.11
Python 3.11.5 (main, Oct 21 2024, 17:26:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import webex_bot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'webex_bot'
>>>

11 Replies 11

mparra.fusionet
Level 1
Level 1

Hi @o1 ,

Without looking at the main.py where the bot.run() is it is hard to guess but please remove all restrictions, like, there was another one where you can restrict it to specific users, if you have it also remove it from the instantiation of the Webex_bot object

approved_rooms=['06586d8d-6aad-4201-9a69-0bf9eeb5766e']

Or any other restriction to user defined in the webex_bot library, we make extensive use of bots an the beauty is that they can be shared with anyone by default as long as they talk directly to the bot in 1:1 message,

Thanks! It worked! Though not in room, but the users could use it for 1:1 purpose. Now 2 users are using this bot (I + one more user). I see that if any input provided, I am getting the response twice which is equal to the current number of users currently opened the bot window. Has it something to do with the code? 

Yes this has to be related to the code, I’m guessing you might be also using the standard webexpythonsdk to get via a for statement who this bot is talking to and from there send a message to that list of spaces 

Natively 1:1 messages stay within that 1:1 space, only via code you could be achieving that behavior 

mparra.fusionet
Level 1
Level 1

Hi 1o,

pip install webex-bot would be the way to go in the python terminal of your UCS Linux, in this way you get the library and it should. Come up.

A couple of disclaimers about this solution:

* Not sure about your code structure/organization but in the most default  case, you had your commands defined in the Webex_bot folder in your CentOS, if you do this solution, you will bring a clean copy of webex_bot without your custom code and basically you have to code a lot again on your UCS or copy the custom commands from the centOS to the UCS Linux.

* If you copy pasted the Webex_bot folder on your centOS, where again I am assuming you did all your custom code to meet the requirements, instead of doing pip install and did all you coding on that folder you could copy paste that Webex_bot folder  from CentOS into the path of the where the main.py exists in the UCS, fix any the import statements to match the new folder structure and that will work.

Both of the approaches above are McGivers/Jimmy Rigging to get you back up quick after a las minute move  but they are not for sure the best practice at all, the right way to go is to containerize your code with Docker, test it in your PC to make sure it works and finally you install docker on your UCS Linux, load up the fully tested container with you code and you have a hassle free server migration. 

Hope this helps

Thanks! As mentioned in my post, my code works on my local environment with python3.11 virtual environment & I get the expected notifications inside the webex room I created.

While commenting, it doesn't work on my UCS with pip install or yum, it's installed without any error  

Let me try to run the code from my UCS now. Thanks! (I might have tried pip install 10 times before generating this post , but it dint work.) Now it worked.

o1
Cisco Employee
Cisco Employee

Hi Team,

I was able to install the required packages & triggered the script, but getting following error:

 

2024-11-03 23:08:48 [INFO] [webex_bot.webex_bot.webex_bot.get_me_info]:102 Running as bot 'Device_Hardware_Info' with email ['abc@webex.bot']
2024-11-03 23:08:49 [INFO] [webex_websocket_client.webex_bot.websockets.webex_websocket_client._connect_and_listen]:213 Opening websocket connection to wss://mercury-connection-partition2-a.wbx2.com/v1/apps/wx2/registrations/be9d3f99-5a4c-4529-8aa9-9b857901ee2c/messages
2024-11-03 23:08:59 [ERROR] [webex_websocket_client.webex_bot.websockets.webex_websocket_client.run]:241 runException:
2024-11-03 23:09:00 [INFO] [webex_websocket_client.webex_bot.websockets.webex_websocket_client._connect_and_listen]:213 Opening websocket connection to wss://mercury-connection-partition2-a.wbx2.com/v1/apps/wx2/registrations/ce566a33-a905-4f24-8d73-76b46b172c9e/messages
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 655, in __await_impl_timeout__
return await self.__await_impl__()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 659, in __await_impl__
_transport, _protocol = await self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
return await fut
^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/webex_bot/websockets/webex_websocket_client.py", line 239, in run
asyncio.get_event_loop().run_until_complete(_connect_and_listen())
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Previous line repeated 1 more time]
File "/usr/local/lib/python3.11/site-packages/webex_bot/websockets/webex_websocket_client.py", line 227, in _connect_and_listen
async with connect as _websocket:
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 637, in __aenter__
return await self
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 654, in __await_impl_timeout__
async with asyncio_timeout(self.open_timeout):
File "/usr/local/lib/python3.11/asyncio/timeouts.py", line 111, in __aexit__
raise TimeoutError from exc_val
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 655, in __await_impl_timeout__
return await self.__await_impl__()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 659, in __await_impl__
_transport, _protocol = await self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
return await fut
^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/root/Device_Hardware_Details/bot.py", line 24, in <module>
bot.run()
File "/usr/local/lib/python3.11/site-packages/webex_bot/websockets/webex_websocket_client.py", line 246, in run
asyncio.get_event_loop().run_until_complete(_connect_and_listen())
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/backoff/_async.py", line 151, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Previous line repeated 1 more time]
File "/usr/local/lib/python3.11/site-packages/webex_bot/websockets/webex_websocket_client.py", line 227, in _connect_and_listen
async with connect as _websocket:
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 637, in __aenter__
return await self
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/websockets/legacy/client.py", line 654, in __await_impl_timeout__
async with asyncio_timeout(self.open_timeout):
File "/usr/local/lib/python3.11/asyncio/timeouts.py", line 111, in __aexit__
raise TimeoutError from exc_val
TimeoutError

Can someone please help here? When executed from my local machine, I dont see this error.

Seems there is some basic network connection issue - the connection is timing out when trying to connect to the websocket service at wss://mercury-connection-partition2-a.wbx2.com/v1/apps/wx2/registrations/be9d3f99-5a4c-4529-8aa9-9b857901ee2c/messages
Perhaps a DNS or firewall issue..?

I have added a proxy to the server. Using the proxy, I can connect to google.com, but couldn't connect to WebSocket. Is there any way to resolve this?

Hi @o1 ,

In the past 7 months the webex_bot library added proxy support by changing the underlying websocket library from websockets to websockets_proxy, before that there was no proxy support (this reminds me to update some previous old posts when I told people that it wasn't supported).

So,  if your UCS linux server is behind a proxy for internet access, besides setting up the proxy on the UCS Linux as you did already, you need to add via code (assuming you have webex_bot == 0.5.2 which is where support for proxies was added 7 months ago) the following lines:


import os

from webex_bot.commands.echo import EchoCommand
from webex_bot.webex_bot import WebexBot

# (Optional) Proxy configuration
# Supports https or wss proxy, wss prioritized.
proxies = {
    'https': 'http://proxy.esl.example.com:80',  #Proxy port and proxy would need to be set here!
    'wss': 'socks5://proxy.esl.example.com:1080'
}

# Create a Bot Object
bot = WebexBot(teams_bot_token=os.getenv("WEBEX_TEAMS_ACCESS_TOKEN"),
               approved_rooms=['06586d8d-6aad-4201-9a69-0bf9eeb5766e'],
               bot_name="My Teams Ops Bot",
               include_demo_commands=True,
               proxies=proxies)

 

Key Take-aways:

1- Make sure you have webex_bot 0.5.2

2- Make sure you populate the proxies dictionary and pass it as a parameter when instantiating the WebexBot object as depicted above

 

Thanks a lot! This worked as expected. Now the Websocket is opened from my UCS server & I can generate the required o/p on my bot based on the inputs. Now to use this bot for multiple users, I added the bot in the webex room. In the approved_rooms parameter, I mentioned the id of the room. But I dont see any response inside the room based on my input. Getting the response in the room is important where I can add multiple users. Am I missing any parameter to add here to get the response in the webex room where I already added my bot?

o1
Cisco Employee
Cisco Employee

Here is one more question : how can I make other users to use the bot? While testing with the other users, I found out that, other users are not able to receive the required output based on the input they provide. Do I need to add the users anywhere in the bot or the room?