vCenter

 View Only
  • 1.  vcenter alarm environment variables

    Posted May 24, 2017 03:03 PM

    vSphere 6.0 Documentation Center

    The documentation above makes it seem like vCenter will create environment variables when specific alerts/alarms are triggered. I'm assuming, since the documentation doesn't make it clear, that on a Windows-based vCenter server these are environment variables that I can access in CMD via "set" or in Powershell via Get-ChildItem Env:, is this correct or do i have to look somewhere else or run a different command to actually see them once they've been triggered? Right now  when i trigger an alert, I'm not finding these variables in either CMD or PS. Regardless of an alert being active, I am able to see other VMware environment variables like VMWARE_OPENSSL_BIN or VMWARE_VAPI_HOME or VMWARE_CFG_DIR, I just never see any VMWARE_ALERT_(anything) variables show up at all.

    I'm essentially trying to duplicate this post, http://www.virtuallyghetto.com/2016/06/how-to-run-a-script-from-a-vcenter-alarm-action-in-the-vcsa.html , but it's not clear where command the author used to take the screenshot of his environment variables. Are they in a specific user context or is there a different command i need to run in order to see them, other than Set or Get-ChildItem Env:?



  • 2.  RE: vcenter alarm environment variables

    Posted Dec 22, 2017 07:53 PM

    Guys,


    I am having the EXACT same issue.


    vCenter 5.5 running on Server 2008R2. I am DESPERATELY trying to write some Powershell scripts to kick off on an alarm trigger and send notification to a slack channel for our admin boys, however, no environment variables I can see anywhere in Windows.

    Can someone PLEASE take a second and respond to this, its driving me crazy. Am I doing something really stupid?

    My scripts are failing as the JSON Payload I am sending is has a blank alarm description field, which is supposed to be taken from the $env:insert_vcenter_alarm field, yet as the poster above found, I do not see these variables in powershell or command prompt.

    What is going on, it is making me lose my mind!



  • 3.  RE: vcenter alarm environment variables

    Posted Dec 26, 2017 09:43 PM

    I found this: https://stackoverflow.com/questions/40430785/how-can-i-run-pyvmomi-scripts-based-on-vsphere-alarms-on-the-vcsa.  This is perl based but might get you in the right direction.  It appears at the bottom it'll list all of the environmental settings when the alarm is fired off.  Hope this helps.

    #!/usr/bin/python
    #   Copyright 2016 Michael Rice <michael@michaelrice.org>
    #
    #   Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    #   You may obtain a copy of the License at
    #
    #       http://www.apache.org/licenses/LICENSE-2.0
    #
    #   Unless required by applicable law or agreed to in writing, software
    #   distributed under the License is distributed on an "AS IS" BASIS,
    #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    #   See the License for the specific language governing permissions and
    #   limitations under the License.

    from __future__ import print_function
    import os
    import ssl
    import sys
    import requests

    # This is where VMWare keeps the pyVmomi and other libraries
    sys
    .path.extend(os.environ['VMWARE_PYTHON_PATH'].split(';'))

    from pyVim import connect
    from pyVmomi import vim
    requests
    .packages.urllib3.disable_warnings()
    # this is to ignore SSL verification which is helpful for self signed certs
    try:
        _create_unverified_https_context
    = ssl._create_unverified_context
    except AttributeError:
       
    # Legacy Python that doesn't verify HTTPS certificates by default
       
    pass
    else:
       
    # Handle target environment that doesn't support HTTPS verification
        ssl
    ._create_default_https_context = _create_unverified_https_context
    USER_NAME
    = "YOUR USER"
    PASSWORD
    = "YOUR PASS"
    HOST
    = "YOUR HOST"
    PORT
    = "443"
    service_instance
    = connect.SmartConnect(host=HOST,
                                            user
    =USER_NAME,
                                            pwd
    =PASSWORD,
                                            port
    =int(PORT))

    root_folder
    = service_instance.content.rootFolder
    # again crude example here. use the logging module instead
    with open("/var/log/my_script_log_file.txt", 'a') as f:
       
    print(root_folder.name, file=f)
       
    for var, val in os.environ.items():
           
    # When an alarm is triggered and run a lot of environment variables are set.
           
    # This will list them all with their values.
           
    if var.startswith("VMWARE_ALARM"):
               
    print("{} = {}".format(var, val), file=f)
       
    print("##########", file=f)
    connect
    .Disconnect(service_instance)