Skip to content

Commit

Permalink
feat(attributes_tags): Adding attributes and tags
Browse files Browse the repository at this point in the history
* Added the metric standby_mode

* Added the metric standby_mode

* vscode ignore

* vscode ignore

* vmware_exporter with standby_mode metric and unit tests

* vscode gone

* removed trailing whitespace on 852

* changed codecov from 2.0.15 to 2.0.17 as suggested by snyk

* requirements.txt badge from snyk

* usage of vmware python sdk

* fetch tags and custom attributes

* Flaked code :)

* cannot install vmware-automation-sdk by setup.py install. use pip install instead

* Annoying messages about imports

* Commented and flake8ed

* typo on .travis.yml

* travis ci

* travis ci

* Flake8d

* Unit tests

* Unit tests

* Fixed problem with hosts custom attributes

* Dockerfile update to include vsphere-automation-sdk

* Dockerfile: installing dependencies to vsphere-automation-sdk

* get_bool_env to new envs FETCH_TAGS and FETCH_CUSTOM_ATTRIBUTES

* Replacing vmware SDK for Python by direct REST API requests

Replacing vmware SDK for Python by direct REST API requests

Replacing vmware SDK for Python by direct REST API requests

Dockerfile :)

Update Dockerfile

Global type custom attributes are coded with None so I cant exclude this for obj type

if return value is coerced to boolean, the function hangs and do not return values as empty lists, empty string, and so on

Minor stetics adjustments

Edited Readme as requested

Set FETCH_CUSTOM_ATTRIBUTES and FETCH_TAGS default to False

Test modified to new envs default values
  • Loading branch information
rmontenegroo committed May 6, 2020
1 parent d2df6f0 commit 237693e
Show file tree
Hide file tree
Showing 7 changed files with 850 additions and 100 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[flake8]
ignore = E402
max-line-length = 120
58 changes: 34 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ default:
vsphere_password: "password"
ignore_ssl: False
specs_size: 5000
fetch_custom_attributes: True
fetch_tags: True
collect_only:
vms: True
vmguests: True
Expand All @@ -68,6 +70,8 @@ esx:
vsphere_password: 'password'
ignore_ssl: True
specs_size: 5000
fetch_custom_attributes: True
fetch_tags: True
collect_only:
vms: False
vmguests: True
Expand All @@ -81,6 +85,8 @@ limited:
vsphere_password: 'password'
ignore_ssl: True
specs_size: 5000
fetch_custom_attributes: True
fetch_tags: True
collect_only:
vms: False
vmguests: False
Expand All @@ -92,33 +98,37 @@ limited:
Switching sections can be done by adding ?section=limited to the URL.

#### Environment Variables
| Variable | Precedence | Defaults | Description |
| ---------------------------- | ---------------------- | -------- | --------------------------------------- |
| `VSPHERE_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |
| Variable | Precedence | Defaults | Description |
| --------------------------------------| ---------------------- | -------- | --------------------------------------------------------------------------|
| `VSPHERE_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_FETCH_CUSTOM_ATTRIBUTES` | config, env | False | Set to true to collect objects custom attributes as metric labels |
| `VSPHERE_FETCH_TAGS` | config, env | False | Set to true to collect objects tags as metric labels |
| `VSPHERE_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |

You can create new sections as well, with very similiar variables. For example, to create a `limited` section you can set:

| Variable | Precedence | Defaults | Description |
| ---------------------------- | ---------------------- | -------- | --------------------------------------- |
| `VSPHERE_LIMITED_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_LIMITED_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_LIMITED_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_LIMITED_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_LIMITED_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_LIMITED_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_LIMITED_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_LIMITED_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_LIMITED_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_LIMITED_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |
| Variable | Precedence | Defaults | Description |
| ----------------------------------------------| ---------------------- | -------- | --------------------------------------------------------------------------|
| `VSPHERE_LIMITED_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_LIMITED_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_LIMITED_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_LIMITED_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_LIMITED_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_LIMITED_FETCH_CUSTOM_ATTRIBUTES` | config, env | False | Set to true to collect objects custom attributes as metric labels |
| `VSPHERE_LIMITED_FETCH_TAGS` | config, env | False | Set to true to collect objects tags as metric labels |
| `VSPHERE_LIMITED_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_LIMITED_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_LIMITED_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_LIMITED_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_LIMITED_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |

You need to set at least `VSPHERE_SECTIONNAME_USER` for the section to be detected.

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ def test_batch_fetch_properties():
# but the real return value has methods with side effects. So we need to use a fake.
content.viewManager.CreateContainerView.return_value = FakeView()

mockCustomField1 = mock.Mock()
mockCustomField1.key = 1
mockCustomField1.name = 'customAttribute1'
mockCustomField1.managedObjectType = vim.Datastore

mockCustomField2 = mock.Mock()
mockCustomField2.key = 2
mockCustomField2.name = 'customAttribute2'
mockCustomField1.managedObjectType = vim.VirtualMachine

content.customFieldsManager.field = [
mockCustomField1,
mockCustomField2,
]

prop1 = mock.Mock()
prop1.name = 'someprop'
prop1.val = 1
Expand Down
Loading

0 comments on commit 237693e

Please sign in to comment.