Policies
ucmdb_rest.policies.Policies(server)
Initialize the service with a reference to the main level UCMDB server
Source code in ucmdb_rest\policies.py
calculateComplianceView(myDict)
Calculates compliance based on provided data.
This method makes a POST request to the UCMDB server to calculate compliance based on the provided data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
myDict
|
dict
|
Data to be used for compliance calculation. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
Response object from the UCMDB server. |
Example
my_dict = {'data': 'example_data'} response = calculateComplianceView(my_dict) print(response.status_code) 200
Source code in ucmdb_rest\policies.py
calculateView(view)
Calculates a compliance view based on policies that exist in a UCMDB system.
This method makes a POST request to the UCMDB server to calculate a compliance view. The results are a list of dictionaries containing the COMPLIANT, NON-COMPLIANT, and NON-APPLICABLE values. The view must be from the list created by getComplainceViews.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
str
|
The name of the view to request. The view name will be URL-encoded, so it can contain spaces or special characters. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
A JSON object containing a list of dictionaries with the compliance status and their counts: - ciType: str ("COMPLIANT", "NON-COMPLIANT", "NON-APPLICABLE") - count: int |
Example
view = 'Node Compliance View' compliance_results = calculateView(view) for result in compliance_results: print(result['ciType'], result['count'])
COMPLIANT 484 NON-COMPLIANT 310
Source code in ucmdb_rest\policies.py
getAllResultsForPath(execution_id, status_type=ComplianceStatus.NON_COMPLIANT)
Automatically iterates through all chunks for a specific status and returns one flat list of results.
This method handles the pagination logic of the UCMDB server by first determining the number of chunks and then sequentially retrieving and aggregating them into a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
execution_id
|
str
|
The ID of the view execution (viewResultId). |
required |
status_type
|
ComplianceStatus or str
|
The compliance status to retrieve ("COMPLIANT", "NON-COMPLIANT", "NON-APPLICABLE"). Default is ComplianceStatus.NON_COMPLIANT. |
NON_COMPLIANT
|
Returns:
| Type | Description |
|---|---|
list
|
A flat list of dictionaries representing the compliance results, aggregated from all available chunks. |
Example
from ucmdb_rest.policies import ComplianceStatus exec_id = 'eyJ0eXAiOiJKV1...' results = getAllResultsForPath(exec_id, ComplianceStatus.NON_COMPLIANT) print(len(results)) 450
Source code in ucmdb_rest\policies.py
getChunkForPath(execution_id, chunk, status_type=ComplianceStatus.NON_COMPLIANT)
Retrieves a specific data chunk for a given path (status) from the UCMDB server.
This method makes a POST request to the UCMDB server to retrieve a specific chunk of compliance data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
execution_id
|
str
|
The ID of the view execution. |
required |
chunk
|
int
|
The number of the chunk to retrieve. |
required |
status_type
|
ComplianceStatus or str
|
The compliance status ("COMPLIANT", "NON-COMPLIANT", "NON-APPLICABLE"). Default is ComplianceStatus.NON_COMPLIANT. |
NON_COMPLIANT
|
Returns:
| Type | Description |
|---|---|
Response
|
Response object containing the requested compliance data chunk. |
Example
from ucmdb_rest.policies import ComplianceStatus execution_id = 'example_execution_id' chunk = 1 response = getChunkForPath(execution_id, chunk, ComplianceStatus.NON_COMPLIANT) print(response.status_code) 200
Source code in ucmdb_rest\policies.py
getComplainceViews()
Retrieves the valid compliance views based on policies that exist in a UCMDB system.
This method makes a GET request to the UCMDB server to fetch a list of compliance views.
Returns:
| Type | Description |
|---|---|
Response
|
A JSON object containing a list of dictionaries, each representing a compliance view with the following keys: - name: str - baseViewName: str - policyQueries: list of str |
Example
compliance_views = getComplainceViews() for view in compliance_views: print(view['name'], view['baseViewName'], view['policyQueries'])
Certificates must use https Node with WebServer ['Certificates must use https'] Kubernetes statefulset must have pod Kubernetes StatefulSet ['Kubernetes statefulset']
Source code in ucmdb_rest\policies.py
getNumberOfElements(payload)
Retrieves the number of elements for a specified path from the UCMDB server.
This method makes a POST request to the UCMDB server to retrieve the number of elements for a specified path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict
|
The payload containing the necessary data for the request. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
Response object containing the number of elements for the specified path. |
Example
payload = {'data': 'example_data'} response = getNumberOfElements(payload) print(response.status_code) 200
Source code in ucmdb_rest\policies.py
getPolicies()
Retrieves the valid policies that exist in a UCMDB system.
This method makes a GET request to the UCMDB server to fetch a list of valid policies.
Returns:
| Type | Description |
|---|---|
Response
|
A JSON object containing a list of dictionaries, each representing a policy with the following keys: - name: str - path: str - simplePolicy: bool |
Example
policies = getPolicies() for policy in policies: ... print(policy['name'], policy['path'], policy['simplePolicy']) ... Certificates must use https Query/Policy/Security True Kubernetes must have pod Query/Policy/Cloud Compliance/Kubernetes False
Source code in ucmdb_rest\policies.py
getSpecificComplianceView(cv)
Retrieves the result of a specific compliance report.
This method makes a GET request to the UCMDB server to fetch the details of a specific compliance view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cv
|
str
|
The name of the compliance view. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
A JSON object containing details of the specified compliance view, including: - name: str - baseViewName: str - policyQueries: list of str |
Example
cv = 'Nodes with Discovery Probe' compliance_view = getSpecificComplianceView(cv) print(compliance_view['name']) 'Nodes with Discovery Probe'
Notes
The quote function is used to properly encode the compliance view name, ensuring that it can be safely used as part of a URL.