Comments (13)
Hello,
There are two packages:
- fp-NGFW-SMC-python
- fp-NGFW-SMC-python-monitoring
So in your case if you do want to do log Browning then you need in both. See
Why in your case it does not complains that looks strange. Could it be because you still have the old library installed? Just a guess.
BR,
/Greg.
from fp-ngfw-smc-python.
Does not work with the newest version either. I use jupyterhub for testing. I installed the package from git with
pip install git+https://github.com/Forcepoint/fp-NGFW-SMC-python.git
...
Successfully installed fp-NGFW-SMC-python-1.0.21
My script looks like this:
from smc import session
import smc_monitoring
from smc_monitoring.monitors.blacklist import BlacklistQuery
from smc import set_file_logger
from smc.core.engine import Engine
session.login(url='https://firewall:8082', api_key='xxxxxxxxxxxxxxxxxxxxxx',verify='ca.pem')
if not session.session or not session.session.cookies:
print("Test")
engine = Engine('xxx')
print(list(engine.nodes))
query = BlacklistQuery('xxx')
query.format.timezone('CST')
for entry in query.fetch_batch():
print(entry)
sess.logout()
I can see the output Test and the nodes given the engine ID. So there is a session available. After that I got the error:
---------------------------------------------------------------------------
SessionNotFound Traceback (most recent call last)
Cell In[18], line 8
6 query = BlacklistQuery('xxx')
7 query.format.timezone('CST')
----> 8 for entry in query.fetch_batch():
9 print(entry)
10 sess.logout()
File /opt/conda/lib/python3.10/site-packages/smc_monitoring/models/query.py:316, in Query.fetch_batch(self, formatter, **kw)
301 def fetch_batch(self, formatter=TableFormat, **kw):
302 """
303 Fetch and return in the specified format. Output format is a formatter
304 class in :py:mod:`smc_monitoring.models.formatters`. This fetch type will
(...)
314 see :py:mod:`smc_monitoring.models.formatters` for more info.
315 """
--> 316 fmt = formatter(self)
317 if "max_recv" not in kw:
318 kw.update(max_recv=1)
File /opt/conda/lib/python3.10/site-packages/smc_monitoring/models/formatters.py:147, in TableFormat.__init__(self, query)
146 def __init__(self, query):
--> 147 super(TableFormat, self).__init__(query)
148 # Calculate starting column width
149 self.column_width = [(header, len(header)) for header in self.headers]
File /opt/conda/lib/python3.10/site-packages/smc_monitoring/models/formatters.py:86, in _Header.__init__(self, query)
82 field_ids = query.field_ids
84 # Ask for the field parameters so we can create the
85 # headers based on the field_format (pretty, name, id)
---> 86 fields = query.resolve_field_ids(field_ids, **query.sockopt)
88 if not fields:
89 raise ValueError(
90 "Unable to resolve field IDs. Call query.format.field_ids() "
91 "and set valid fields."
92 )
File /opt/conda/lib/python3.10/site-packages/smc_monitoring/models/query.py:240, in Query.resolve_field_ids(ids, **kw)
238 query.location = "/monitoring/log/socket"
239 query.request = request
--> 240 for fields in query.execute():
241 if "fields" in fields:
242 return fields["fields"]
File /opt/conda/lib/python3.10/site-packages/smc_monitoring/models/query.py:274, in Query.execute(self)
260 def execute(self):
261 """
262 Execute the query with optional timeout. The response to the execute
263 query is the raw payload received from the websocket and will contain
(...)
272 :rtype: dict(list)
273 """
--> 274 with SMCSocketProtocol(self, **self.sockopt) as protocol:
275 for result in protocol.receive():
276 yield result
File /opt/conda/lib/python3.10/site-packages/smc_monitoring/wsocket.py:77, in SMCSocketProtocol.__init__(self, query, query_timeout, sock_timeout, **kw)
55 """
56 Initialize the web socket.
57
(...)
74 'verify' setting has been provided with a path to the root CA file.
75 """
76 if not session.session or not session.session.cookies:
---> 77 raise SessionNotFound(
78 "No SMC session found. You must first "
79 "obtain an SMC session through session.login before making "
80 "a web socket connection."
81 )
83 sslopt = {}
84 if session.is_ssl:
85 # SSL verification is based on the session settings since the
86 # session must be made before calling this class. If verify=True,
(...)
90 # and would have already validated this when the session was set
91 # up. This can still be overridden by setting check_hostname=True.
SessionNotFound: No SMC session found. You must first obtain an SMC session through session.login before making a web socket connection.
It seems the two packages can not share the session.
from fp-ngfw-smc-python.
Here is what I do have
(venv) gregory@goueg ~/greg/clone/playground $ pip3 list | grep -i ngfw
fp-NGFW-SMC-python 1.0.19
fp-NGFW-SMC-python-monitoring 1.4.0
Output:
[Node(name=Algiers node 1), Node(name=Algiers node 2)]
Exception ignored in: <generator object SMCSocketProtocol.receive at 0x7fe05263b610>
Traceback (most recent call last):
File "/home/gregory/greg/clone/playground/venv/lib/python3.10/site-packages/smc_monitoring/wsocket.py", line 245, in receive
while self.thread.isAlive():
AttributeError: 'Thread' object has no attribute 'isAlive'
IMO if we do have TEST printed then it means your login has failed.
/Greg.
from fp-ngfw-smc-python.
When I try the script in a new 3.11 venv with PyCharm I get the following error:
Traceback (most recent call last):
File "C:\Users\user\FW-API\main.py", line 4, in <module>
session.login(alt_filepath='.smcrc')
File "C:\Users\user\FW-API\venv\Lib\site-packages\smc\api\session.py", line 558, in login
self._session = self._get_session(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\FW-API\venv\Lib\site-packages\smc\api\session.py", line 622, in _get_session
retry = Retry(
^^^^^^
TypeError: Retry.__init__() got an unexpected keyword argument 'method_whitelist'
Tried it on my Windows machine and on my Macbook
from fp-ngfw-smc-python.
ok, this issue will be fixed in next release. For now please try to use one of following python version
- 3.10.11
- 3.8.10
- 3.9.16
We has similar discussions in previous issue:
from fp-ngfw-smc-python.
Hello Greg,
There are two packages:
* fp-NGFW-SMC-python * fp-NGFW-SMC-python-monitoring
So in your case if you do want to do log Browning then you need in both. See
* https://github.com/Forcepoint/fp-NGFW-SMC-python#extensions
Why in your case it does not complains that looks strange. Could it be because you still have the old library installed? Just a guess.
I'm pretty sure I uninstalled the old (deprecated [?] smc-python and smc-python-monitoring) via pip3 before installing fp-NGFW-SMC-python-monitoring; I still wonder why pip3 list
doesn't list the latter.
The next I'll try is to purge ~/.local/lib/python3.11/, check for any distributed packages and reinstall both via pip3 with one of the older versions you have mentioned.
BR
/sam
from fp-ngfw-smc-python.
Seems smc-python-monitoring is not uptodate when installing using pip, I suggest to retrieve manualy the files directly from github and to past into the python library folder
from fp-ngfw-smc-python.
Hello Greg,
sadly python3.9 isn't available anymore in Ubuntu 22 and using the deadsnakes repo cascades into other errors.
I seem to have broken something or I'm missing some path now when using virtualenv:
$ rm -rf ~/.local/lib/python3*
$ mkvirtualenv test-venv -p python3.10
$ pip3 install fp-NGFW-SMC-python fp-NGFW-SMC-python-monitoring
When I try to run the script I get:
Traceback (most recent call last):
File "/home/user/script.py", line 11, in <module>
import smc.elements
ModuleNotFoundError: No module named 'smc'
Best regards, Sam
from fp-ngfw-smc-python.
Hello,
Please check example we have in smc-python:
- https://github.com/Forcepoint/fp-NGFW-SMC-python/blob/master/smc/examples/README.md
** https://github.com/Forcepoint/fp-NGFW-SMC-python/blob/master/smc/examples/run_example.sh
/Greg
from fp-ngfw-smc-python.
Hi again,
Just because I'm curious I did check your command by following:
I can see in prompt that I'm in a venv
gregory@goueg ~ $ mkvirtualenv -p python3.10 smc-python_venv
created virtual environment CPython3.10.6.final.0-64 in 133ms
creator CPython3Posix(dest=/home/gregory/.virtualenvs/smc-python_venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/gregory/.local/share/virtualenv)
added seed packages: pip==23.1.2, setuptools==67.7.2, wheel==0.40.0
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
virtualenvwrapper.user_scripts creating /home/gregory/.virtualenvs/smc-python_venv/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/gregory/.virtualenvs/smc-python_venv/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/gregory/.virtualenvs/smc-python_venv/bin/preactivate
virtualenvwrapper.user_scripts creating /home/gregory/.virtualenvs/smc-python_venv/bin/postactivate
virtualenvwrapper.user_scripts creating /home/gregory/.virtualenvs/smc-python_venv/bin/get_env_details
(smc-python_venv) gregory@goueg ~ $
(smc-python_venv) gregory@goueg ~ $
Is it your case too ?
/Greg.
from fp-ngfw-smc-python.
Is it your case too ?
Yes, see below:
user@host:~$ mkvirtualenv -p python3.10 smc-python_venv
created virtual environment CPython3.10.7.final.0-64 in 310ms
creator CPython3Posix(dest=/home/user/.virtualenvs/smc-python_venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/user/.local/share/virtualenv)
added seed packages: pip==22.2, setuptools==59.6.0, wheel==0.37.1
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
In the meantime I found it helps to have the git repo in the environment before running the script (like in run_example.sh):
(smc-python_venv) user@host:~$ cat test.py
#!/usr/bin/env python3.9
import smc
(smc-python_venv) user@host:~$ PYTHONPATH=$HOME/fp-NGFW-SMC-python ./test.py
(smc-python_venv) user@host:~$
While without PYTHONPATH has been set the module won't be found:
(smc-python_venv) user@host:~$ ./test.py
Traceback (most recent call last):
File "/home/user/test.py", line 2, in <module>
import smc
ModuleNotFoundError: No module named 'smc'
I assumed PYTHONPATH gets set/modified by virtualenv resp. mkvirtualenv, after all this is one of the purposes of using virtual environments, but it seems not to be the case on my system although the python docs regarding venv also just mentions VIRTUAL_ENV.
It works also fine when copying the respective directory (i.e. smc or smc-monitoring) like @thomasdevulder suggested.
ok, this issue will be fixed in next release. For now please try to use one of following python version
Is there any plan for when this might be?
from fp-ngfw-smc-python.
Works nice for me:
tdevulder@LT-040391:~$ python3 -m venv smc-python_venv
tdevulder@LT-040391:~$ source smc-python_venv/bin/activate
(smc-python_venv) tdevulder@LT-040391:~$
(smc-python_venv) tdevulder@LT-040391:~/smc-python_venv$ python3 --version
Python 3.8.10
(smc-python_venv) tdevulder@LT-040391:~$ python3 -m pip install fp-NGFW-SMC-python
Successfully installed certifi-2023.5.7 charset-normalizer-3.1.0 fp-NGFW-SMC-python-1.0.22 idna-3.4 pytz-2023.3 requests-2.31.0 urllib3-2.0.2
(smc-python_venv) tdevulder@LT-040391:~$ python3 -m pip install fp-NGFW-SMC-python-monitoring
Successfully installed fp-NGFW-SMC-python-monitoring-1.5.0 websocket-client-1.5.2
(smc-python_venv) tdevulder@LT-040391:~$ python3 -m pip list
Package Version
----------------------------- --------
certifi 2023.5.7
charset-normalizer 3.1.0
fp-NGFW-SMC-python 1.0.22
fp-NGFW-SMC-python-monitoring 1.5.0
idna 3.4
pip 20.0.2
pkg-resources 0.0.0
pytz 2023.3
requests 2.31.0
setuptools 44.0.0
urllib3 2.0.2
websocket-client 1.5.2
(smc-python_venv) tdevulder@LT-040391:~/smc-python_venv$ cat log.py
import os
from smc_monitoring.wsocket import session
from smc_monitoring.monitors.logs import LogQuery
try:
session.login(url=os.environ['SMC_ADDRESS'], api_key=os.environ['SMC_API_KEY'], verify=False, timeout=120)
query = LogQuery()
print(list(query.fetch_batch()))
finally: session.logout()
(smc-python_venv) tdevulder@LT-040391:~/smc-python_venv$ python3 log.py
['Creation Time Severity Action Sender Src Addr Src Port Dst Addr Dst Port IP Protocol Event Information Message \n------------------- -------- ------ ----------------- -------- -------- -------- -------- ----------- ----- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n2023-06-05 13:56:01 - - Management Server - - - - - - Login succeeded for user APIDemo in domain Shared Domain
from fp-ngfw-smc-python.
a remark about your test,
1-seems it is needed to activate the virtual env using $ workon venv_name
in your case ..
2-I think #!/usr/bin/env python3.11 definition may interfere with python you would like to use inside your virtual env
from fp-ngfw-smc-python.
Related Issues (20)
- How to communicate HTTPS to SMC API using SMC-Python? HOT 1
- Enable/Disable sites in Policy Based VPN Topology HOT 8
- How to collect logs of specific access rule on SMC? HOT 1
- Unable to install other dependancy because of pytz fixed version HOT 4
- Library versioning HOT 1
- Create fw_ipv4_access_rules with "AND" combination in source HOT 2
- VPN Gateway expiration date HOT 3
- Lock an smc element HOT 1
- Create users with password in InternalDomain HOT 11
- Wrong version number in "smc/__version__" HOT 1
- certificate verification warnings using the INI file for session creation HOT 2
- add an IP configuration on a tunnel interface without IP HOT 1
- ServerBackupTask fails HOT 2
- Viewing an Alias' references does not show the element referenced in the Alias, only the address. HOT 1
- Setting standby mode on a TunnelInterface HOT 5
- AttributeError when importing smc module HOT 9
- AttributeError: 'NoneType' object has no attribute 'href' HOT 4
- session.login: Failed to get username HOT 4
- role 'Manage Administrator' mandatory for read only API clients HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fp-ngfw-smc-python.