{"id":8238,"date":"2024-02-20T10:55:29","date_gmt":"2024-02-20T09:55:29","guid":{"rendered":"https:\/\/pandorafms.com\/library\/?p=8238"},"modified":"2024-03-05T16:04:25","modified_gmt":"2024-03-05T15:04:25","slug":"connects-to-a-vmware-vcenter-server-to-count-the-paths-associated-with-a-specified-hba-on-an-esxi-server","status":"publish","type":"post","link":"https:\/\/pandorafms.com\/library\/connects-to-a-vmware-vcenter-server-to-count-the-paths-associated-with-a-specified-hba-on-an-esxi-server\/","title":{"rendered":"Connects to a VMware vCenter server to count the paths associated with a specified HBA on an ESXi server"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.16&#8243; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.16&#8243; background_size=&#8221;initial&#8221; background_position=&#8221;top_left&#8221; background_repeat=&#8221;repeat&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.16&#8243; custom_padding=&#8221;|||&#8221; global_colors_info=&#8221;{}&#8221; custom_padding__hover=&#8221;|||&#8221;][et_pb_text _builder_version=&#8221;4.16&#8243; background_size=&#8221;initial&#8221; background_position=&#8221;top_left&#8221; background_repeat=&#8221;repeat&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<div class=\"maint-error\">\n  <img decoding=\"async\" src=\"http:\/\/pandorafms.com\/library\/wp-content\/uploads\/2024\/02\/Plugin-out-of-maintenance-alt.png\"><\/p>\n<p><strong>Important Notice:<\/strong>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.<\/p>\n<\/div>\n<p><\/p>\n<h1>get_vcenter_vmhba_total_paths<\/h1>\n<p>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.<\/p>\n<div><\/div>\n<pre>#!\/usr\/bin\/env python3\r\n\"\"\"\r\nAuthor      : Christian\r\nDate        : 16.02.2024\r\nVersion     : 2.5\r\n\r\nDescription:\r\n    Connects to a VMware vCenter server to count the paths associated with a specified HBA on an ESXi server.\r\n    Outputs the total count of matching paths. Includes an option for advanced debugging information.\r\n\r\nUsage:\r\n    python3 \/usr\/share\/pandora_server\/util\/plugin\/get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number\r\n    python3 get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number\r\n    \r\n    Pandora Plugin :\r\n        Plugin command : \r\n            python3 \/usr\/share\/pandora_server\/util\/plugin\/get_vcenter_vmhba_total_paths.py\r\n        Plugin parameters :\r\n            _agentalias_ _field1_ _field2_ _field3_ _field4_\r\n\r\nParameters:\r\n    esx_host         : The hostname of the ESXi server to query.\r\n    vcenter_name     : The IP address or hostname of the vCenter server.\r\n    vcenter_username : Username for authentication with the vCenter server.\r\n    vcenter_password : Password for authentication with the vCenter server.\r\n    vmhba_number     : The HBA identifier to filter paths by.\r\n                       Example : vmhba4\r\n\"\"\"\r\n\r\nimport sys\r\nfrom pyVim.connect import SmartConnectNoSSL, Disconnect\r\nfrom pyVmomi import vim\r\nimport atexit\r\n\r\n# Enabling debug mode based on the command line argument\r\nisDebugMode = False\r\n\r\n# Assigning command-line arguments to variables for easier access\r\nesxHost = sys.argv[1]\r\nvCenterName = sys.argv[2]\r\nvCenterUsername = sys.argv[3]\r\nvCenterPassword = sys.argv[4]\r\nvmhbaNumber = sys.argv[5]\r\n\r\ndef printDebugMessage(message):\r\n    \"\"\"Prints a debug message if debug mode is enabled.\"\"\"\r\n    if isDebugMode:\r\n        print(f\"DEBUG: {message}\")\r\n\r\ndef main():\r\n    if len(sys.argv) &lt; 6:\r\n        print(\"Error: Missing parameters : Usage: get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number [debug]\")\r\n        sys.exit(1)\r\n\r\n    try:\r\n        printDebugMessage(\"Attempting to connect to vCenter...\")\r\n        vCenterConnection = SmartConnectNoSSL(host=vCenterName, user=vCenterUsername, pwd=vCenterPassword, port=443)\r\n        atexit.register(Disconnect, vCenterConnection)\r\n        printDebugMessage(\"Successfully connected to vCenter.\")\r\n\r\n        totalPaths = retrievePathInfo(vCenterConnection, esxHost, vmhbaNumber)\r\n        printDebugMessage(f\"Total paths matching '{vmhbaNumber}': {totalPaths}\")\r\n        print(totalPaths)\r\n        sys.exit(0)\r\n\r\n    except Exception as error:\r\n        printDebugMessage(f\"Error connecting to {vCenterName}: {error}\")\r\n        print(-1)\r\n        sys.exit(1)\r\n\r\ndef retrievePathInfo(vCenterInstance, esxHost, hbaNameFilter):\r\n    content = vCenterInstance.RetrieveContent()\r\n    searchIndex = content.searchIndex\r\n    host = searchIndex.FindByDnsName(dnsName=esxHost, vmSearch=False)\r\n\r\n    if not host:\r\n        printDebugMessage(\"ESXi host not found.\")\r\n        print(-1)\r\n        sys.exit(1)\r\n\r\n    printDebugMessage(f\"Retrieving storage path information for {esxHost}...\")\r\n    pathCount = 0\r\n    storageSystem = host.configManager.storageSystem\r\n\r\n    if storageSystem.storageDeviceInfo.multipathInfo:\r\n        for lun in storageSystem.storageDeviceInfo.multipathInfo.lun:\r\n            for path in lun.path:\r\n                if hbaNameFilter in path.name:\r\n                    pathCount += 1\r\n                    printDebugMessage(f\"Found matching path: {path.name}\")\r\n\r\n    printDebugMessage(f\"Completed path retrieval. Total matching paths: {pathCount}\")\r\n    return pathCount\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n\t\r\n<\/pre>\n<div><\/div>\n<div>&lt;\/pre&gt;<\/div>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":21008,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"<div class=\"maint-error\">\r\n  <img src=\"http:\/\/pandorafms.com\/library\/wp-content\/uploads\/2024\/02\/Plugin-out-of-maintenance-alt.png\">\r\n  <p><strong>Important Notice:<\/strong>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.<p>\r\n<\/div>\r\n\r\n<br>\r\n\r\n<h1>get_vcenter_vmhba_total_paths<\/h1>\r\nThis 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.\r\n<div><\/div>\r\n<pre>#!\/usr\/bin\/env python3\r\n\"\"\"\r\nAuthor      : Christian\r\nDate        : 16.02.2024\r\nVersion     : 2.5\r\n\r\nDescription:\r\n    Connects to a VMware vCenter server to count the paths associated with a specified HBA on an ESXi server.\r\n    Outputs the total count of matching paths. Includes an option for advanced debugging information.\r\n\r\nUsage:\r\n    python3 \/usr\/share\/pandora_server\/util\/plugin\/get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number\r\n    python3 get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number\r\n    \r\n    Pandora Plugin :\r\n        Plugin command : \r\n            python3 \/usr\/share\/pandora_server\/util\/plugin\/get_vcenter_vmhba_total_paths.py\r\n        Plugin parameters :\r\n            _agentalias_ _field1_ _field2_ _field3_ _field4_\r\n\r\nParameters:\r\n    esx_host         : The hostname of the ESXi server to query.\r\n    vcenter_name     : The IP address or hostname of the vCenter server.\r\n    vcenter_username : Username for authentication with the vCenter server.\r\n    vcenter_password : Password for authentication with the vCenter server.\r\n    vmhba_number     : The HBA identifier to filter paths by.\r\n                       Example : vmhba4\r\n\"\"\"\r\n\r\nimport sys\r\nfrom pyVim.connect import SmartConnectNoSSL, Disconnect\r\nfrom pyVmomi import vim\r\nimport atexit\r\n\r\n# Enabling debug mode based on the command line argument\r\nisDebugMode = False\r\n\r\n# Assigning command-line arguments to variables for easier access\r\nesxHost = sys.argv[1]\r\nvCenterName = sys.argv[2]\r\nvCenterUsername = sys.argv[3]\r\nvCenterPassword = sys.argv[4]\r\nvmhbaNumber = sys.argv[5]\r\n\r\ndef printDebugMessage(message):\r\n    \"\"\"Prints a debug message if debug mode is enabled.\"\"\"\r\n    if isDebugMode:\r\n        print(f\"DEBUG: {message}\")\r\n\r\ndef main():\r\n    if len(sys.argv) < 6:\r\n        print(\"Error: Missing parameters : Usage: get_vcenter_vmhba_total_paths.py esx_host vcenter_name vcenter_username vcenter_password vmhba_number [debug]\")\r\n        sys.exit(1)\r\n\r\n    try:\r\n        printDebugMessage(\"Attempting to connect to vCenter...\")\r\n        vCenterConnection = SmartConnectNoSSL(host=vCenterName, user=vCenterUsername, pwd=vCenterPassword, port=443)\r\n        atexit.register(Disconnect, vCenterConnection)\r\n        printDebugMessage(\"Successfully connected to vCenter.\")\r\n\r\n        totalPaths = retrievePathInfo(vCenterConnection, esxHost, vmhbaNumber)\r\n        printDebugMessage(f\"Total paths matching '{vmhbaNumber}': {totalPaths}\")\r\n        print(totalPaths)\r\n        sys.exit(0)\r\n\r\n    except Exception as error:\r\n        printDebugMessage(f\"Error connecting to {vCenterName}: {error}\")\r\n        print(-1)\r\n        sys.exit(1)\r\n\r\ndef retrievePathInfo(vCenterInstance, esxHost, hbaNameFilter):\r\n    content = vCenterInstance.RetrieveContent()\r\n    searchIndex = content.searchIndex\r\n    host = searchIndex.FindByDnsName(dnsName=esxHost, vmSearch=False)\r\n\r\n    if not host:\r\n        printDebugMessage(\"ESXi host not found.\")\r\n        print(-1)\r\n        sys.exit(1)\r\n\r\n    printDebugMessage(f\"Retrieving storage path information for {esxHost}...\")\r\n    pathCount = 0\r\n    storageSystem = host.configManager.storageSystem\r\n\r\n    if storageSystem.storageDeviceInfo.multipathInfo:\r\n        for lun in storageSystem.storageDeviceInfo.multipathInfo.lun:\r\n            for path in lun.path:\r\n                if hbaNameFilter in path.name:\r\n                    pathCount += 1\r\n                    printDebugMessage(f\"Found matching path: {path.name}\")\r\n\r\n    printDebugMessage(f\"Completed path retrieval. Total matching paths: {pathCount}\")\r\n    return pathCount\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n\t\r\n<\/pre>\r\n<div><\/div>\r\n<div><\/pre><\/div>","_et_gb_content_width":"","footnotes":""},"categories":[20],"tags":[742,1174,1172,1173],"_links":{"self":[{"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/posts\/8238"}],"collection":[{"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/users\/21008"}],"replies":[{"embeddable":true,"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/comments?post=8238"}],"version-history":[{"count":3,"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/posts\/8238\/revisions"}],"predecessor-version":[{"id":8465,"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/posts\/8238\/revisions\/8465"}],"wp:attachment":[{"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/media?parent=8238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/categories?post=8238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pandorafms.com\/library\/wp-json\/wp\/v2\/tags?post=8238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}