mirror of
https://github.com/recklessop/Zerto_Exporter.git
synced 2026-07-06 09:13:14 -04:00
make vcenter optional
If vcenter hostname isnt set dont try to get vra cpu and memory
This commit is contained in:
@@ -30,7 +30,6 @@ vcenter_host = os.environ.get('VCENTER_HOST', 'vcenter.local')
|
|||||||
vcenter_user = os.environ.get('VCENTER_USER', 'administrator@vsphere.local')
|
vcenter_user = os.environ.get('VCENTER_USER', 'administrator@vsphere.local')
|
||||||
vcenter_pwd = os.environ.get('VCENTER_PASSWORD', 'supersecret')
|
vcenter_pwd = os.environ.get('VCENTER_PASSWORD', 'supersecret')
|
||||||
|
|
||||||
|
|
||||||
# Get the hostname of the machine
|
# Get the hostname of the machine
|
||||||
container_id = str(socket.gethostname())
|
container_id = str(socket.gethostname())
|
||||||
|
|
||||||
@@ -53,6 +52,13 @@ siteId = "NotSet"
|
|||||||
siteName = "NotSet"
|
siteName = "NotSet"
|
||||||
lastStats = CaseInsensitiveDict()
|
lastStats = CaseInsensitiveDict()
|
||||||
|
|
||||||
|
# Check if vCenter is set, if not disable VRA metrics
|
||||||
|
is_vcenter_set = True
|
||||||
|
if vcenter_host == "vcenter.local":
|
||||||
|
log.error("vCenter Host not set. Please set the environment variable VCENTER_HOST, turning off VRA CPU and Memory metrics")
|
||||||
|
is_vcenter_set = False
|
||||||
|
log.debug("vCenter data collection is enabled")
|
||||||
|
|
||||||
# Authentication Thread which handles authentication and token refresh for ZVM API
|
# Authentication Thread which handles authentication and token refresh for ZVM API
|
||||||
def ZvmAuthHandler():
|
def ZvmAuthHandler():
|
||||||
log.debug("ZVMAuthHandler Thread Started")
|
log.debug("ZVMAuthHandler Thread Started")
|
||||||
@@ -483,6 +489,7 @@ def GetVraMetrics():
|
|||||||
log.debug("Response from GET /v1/vras: %s", response.text)
|
log.debug("Response from GET /v1/vras: %s", response.text)
|
||||||
# parse JSON response and get the name of each VRA
|
# parse JSON response and get the name of each VRA
|
||||||
|
|
||||||
|
if is_vcenter_set:
|
||||||
# Disable SSL certificate verification
|
# Disable SSL certificate verification
|
||||||
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
||||||
context.verify_mode = ssl.CERT_NONE
|
context.verify_mode = ssl.CERT_NONE
|
||||||
@@ -508,6 +515,7 @@ def GetVraMetrics():
|
|||||||
|
|
||||||
|
|
||||||
vras = response.json()
|
vras = response.json()
|
||||||
|
|
||||||
log.debug("VRA names: %s", vras)
|
log.debug("VRA names: %s", vras)
|
||||||
log.debug(type(vras))
|
log.debug(type(vras))
|
||||||
for vra in vras :
|
for vra in vras :
|
||||||
@@ -529,7 +537,7 @@ def GetVraMetrics():
|
|||||||
|
|
||||||
|
|
||||||
# get the CPU and memory usage for each VRA
|
# get the CPU and memory usage for each VRA
|
||||||
|
if is_vcenter_set:
|
||||||
vm = None
|
vm = None
|
||||||
for vm_obj in vm_view.view:
|
for vm_obj in vm_view.view:
|
||||||
if vm_obj.name == vra['VraName']:
|
if vm_obj.name == vra['VraName']:
|
||||||
|
|||||||
Reference in New Issue
Block a user