1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Update in: 5 March 2024


:

Important Notice:This plugin is not official nor created by PandoraFMS. This plugin is no longer actively maintained or updated. We strongly advise you to explore alternative plugins available in our library for the latest features and support.

get_vcenter_vmhba_total_paths

This plugin connects to a VMware vCenter server to count the paths associated with a specified HBA on an ESXi server. Outputs the total count of matching paths. Includes an option for advanced debugging information.

#!/usr/bin/env python3
"""
Author      : Christian
Date        : 16.02.2024
Version     : 2.5

Description:
    Connects to a VMware vCenter server to count the paths associated with a specified HBA on an ESXi server.
    Outputs the total count of matching paths. Includes an option for advanced debugging information.

Usage:
    python3 /usr/share/pandora_server/util/plugin/get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number
    python3 get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number
    
    Pandora Plugin :
        Plugin command : 
            python3 /usr/share/pandora_server/util/plugin/get_vcenter_vmhba_total_paths.py
        Plugin parameters :
            _agentalias_ _field1_ _field2_ _field3_ _field4_

Parameters:
    esx_host         : The hostname of the ESXi server to query.
    vcenter_name     : The IP address or hostname of the vCenter server.
    vcenter_username : Username for authentication with the vCenter server.
    vcenter_password : Password for authentication with the vCenter server.
    vmhba_number     : The HBA identifier to filter paths by.
                       Example : vmhba4
"""

import sys
from pyVim.connect import SmartConnectNoSSL, Disconnect
from pyVmomi import vim
import atexit

# Enabling debug mode based on the command line argument
isDebugMode = False

# Assigning command-line arguments to variables for easier access
esxHost = sys.argv[1]
vCenterName = sys.argv[2]
vCenterUsername = sys.argv[3]
vCenterPassword = sys.argv[4]
vmhbaNumber = sys.argv[5]

def printDebugMessage(message):
    """Prints a debug message if debug mode is enabled."""
    if isDebugMode:
        print(f"DEBUG: {message}")

def main():
    if len(sys.argv) < 6:
        print("Error: Missing parameters : Usage: get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number [debug]")
        sys.exit(1)

    try:
        printDebugMessage("Attempting to connect to vCenter...")
        vCenterConnection = SmartConnectNoSSL(host=vCenterName, user=vCenterUsername, pwd=vCenterPassword, port=443)
        atexit.register(Disconnect, vCenterConnection)
        printDebugMessage("Successfully connected to vCenter.")

        totalPaths = retrievePathInfo(vCenterConnection, esxHost, vmhbaNumber)
        printDebugMessage(f"Total paths matching '{vmhbaNumber}': {totalPaths}")
        print(totalPaths)
        sys.exit(0)

    except Exception as error:
        printDebugMessage(f"Error connecting to {vCenterName}: {error}")
        print(-1)
        sys.exit(1)

def retrievePathInfo(vCenterInstance, esxHost, hbaNameFilter):
    content = vCenterInstance.RetrieveContent()
    searchIndex = content.searchIndex
    host = searchIndex.FindByDnsName(dnsName=esxHost, vmSearch=False)

    if not host:
        printDebugMessage("ESXi host not found.")
        print(-1)
        sys.exit(1)

    printDebugMessage(f"Retrieving storage path information for {esxHost}...")
    pathCount = 0
    storageSystem = host.configManager.storageSystem

    if storageSystem.storageDeviceInfo.multipathInfo:
        for lun in storageSystem.storageDeviceInfo.multipathInfo.lun:
            for path in lun.path:
                if hbaNameFilter in path.name:
                    pathCount += 1
                    printDebugMessage(f"Found matching path: {path.name}")

    printDebugMessage(f"Completed path retrieval. Total matching paths: {pathCount}")
    return pathCount

if __name__ == "__main__":
    main()
	
</pre>
(Visited 87 times, 1 visits today)

For correct visualization of the Pandora FMS library extension, you must have installed version NG 760 or superior

X