Script to fetchAuditRecords
How to use pyVmomi SDK for vSphere 7.0U3 to fetchAuditRecords
- OSS pyVmomi is hosted in GitHub: https://github.com/vmware/pyvmomi
The project's main page contains pointers to general instructions for public releases of pyVmomi SDK. - Attached is the sample code, audit.py, that will fetch audit records from ESXi using the OSS pyVmomi SDK.
Install pyVmomi SDK
First, you'll need a functioning Python environment. This may differ by operating system and distribution.
- Inspect your system and determine if Python 3.5 or later is installed. If not, get the latest Python 3.x
- get pip (Note: see the package manager section)
You need the pyVmomi SDK module inside your pypath and then import the module in your Python code.
To install the pyVmomi PyPI package:
% pip3 install pyvmomi
(pip3 is for Python 3 or higher)
Or if there is an older version already installed:
% pip3 install pyvmomi -upgrade
Please check the pyVmomi samples for usage examples: https://gitlab.eng.vmware.com/api-platform/pyvmomi-community-samples
Run audit.py
Make audit.py file executable (chmod +x audit.py).
To get info on audit.py input parms:
% ~/tmp$ ./audit.py --help
usage: Display locally stored audit records. [-h] --host HOST --password PASSWORD --user USER
optional arguments:
-h, --help show this help message and exit
--host HOST The IP address of the ESXi host
--password PASSWORD Password to log in with
--user USER User name to log in with
Run to talk to ESXi box:
% ./audit.py --host IP_addr --user root --password ""