Ad Widget

Collapse

PowerCli + Zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sergey Serov
    Junior Member
    • Oct 2018
    • 24

    #1

    PowerCli + Zabbix

    Всем привет. Захотел я метрики через PowerCli, написал простой скрипт.



    Code:
    param(
    [Parameter()]
    [String]$server
    )
    Import-Module VMware.VimAutomation.Core
    $vCenter='vcaIP'
    $username='[email protected]'
    $password='readOnly'
    Connect-VIServer -Server $vCenter -User $username -Password $password -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
    Get-Stat -Entity "$server" -Realtime -MaxSamples 1 -Stat virtualDisk.writeOIO.latest | Select @{L='{#HDDLOCATION}';E={$_.Instance}} | ConvertTo-Json
    В консоле работает, отдает как было задуманно (под заббиксом конечно)


    Ну а если я хочу сделать item, то выдает что-то не внятно про модули.

    Code:
    [91mImport-Module:
    [96mLine |
    [96m 14 | [0m [96mImport-Module VMware.VimAutomation.Core[0m
    [96m | [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [91m[96m | [91mThe type initializer for 'VMware.VimAutomation.ViCore.Util10.SettingsManage r' threw an exception.[0m
    [91mConnect-VIServer:
    [96mLine |
    [96m 25 | [0m [96mConnect-VIServer[0m -Server $vCenter -User $username -Password $passwo …
    [96m | [91m ~~~~~~~~~~~~~~~~
    [91m[96m | [91mThe 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.[0m
    [91mGet-Stat:
    [96mLine |
    [96m 29 | [0m [96mGet-Stat[0m -Entity "$server" -Realtime -MaxSamples 1 -Stat virtualDisk. …
    [96m | [91m ~~~~~~~~
    [91m[96m | [91mThe 'Get-Stat' command was found in the module 'VMware.VimAutomation.Core', but the module could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.[0m
    Думаю ладно добавлю с крипт "Import-Module VMware.VimAutomation.Core", не помогло.

    Решил сделать через юзерпарамы на виндовой машине.
    Code:
    UserParameter=hdd.discovery[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Zabbix\scripts\pw_getHDD.ps1"
    Но с заббикса ответ такой

    Code:
    788:20220124:203100.013 execute_str() command:'powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Zabbix\scripts\pw_getHDD.ps1"' len:617 cmd_result:'Get-Stat : 24.01.202'
    788:20220124:203100.013 Sending back [Get-Stat : 24.01.2022 20:30:59 Get-Stat VIObject parameter: Could not find any of the objects specified by name.
    C:\Zabbix\scripts\pw_getHDD.ps1:20 знак:1
    + Get-Stat -Entity $server
    Сможет кто-нибудь помочь ?
  • Alex G
    Junior Member
    • Jan 2020
    • 3

    #2
    У меня такая же проблема.
    Скрипт:

    #! /bin/pwsh
    param($vc, $user, $pass)
    $Z=Connect-VIServer -Server $vc -user $user -pass $pass -Force | Out-Null
    $u=Get-Datastore -Server $vc
    Disconnect-VIServer -Server * -Force -Confirm:$false
    $u|ConvertTo-Json


    Вывод при тестировании элемента данных:

    [91mConnect-VIServer: [0m/usr/lib/zabbix/externalscripts/vc_dsc.ps1:4
    [96mLine |
    [96m 4 | [0m $Z=[96mConnect-VIServer[0m -Server $vc -user $user -pass $pass -Force | Out- …
    [96m | [91m ~~~~~~~~~~~~~~~~
    [91m[96m | [91mThe 'Connect-VIServer' command was found in the module
    [96m | [91m'VMware.VimAutomation.Core', but the module could not be
    [96m | [91mloaded. For more information, run 'Import-Module
    [96m | [91mVMware.VimAutomation.Core'.
    [0m
    [91mGet-DatastoreCluster: [0m/usr/lib/zabbix/externalscripts/vc_dsc.ps1:5
    [96mLine |
    [96m 5 | [0m $u=[96mGet-DatastoreCluster[0m -Server $vc
    [96m | [91m ~~~~~~~~~~~~~~~~~~~~
    [91m[96m | [91mThe 'Get-DatastoreCluster' command was found in the module
    [96m | [91m'VMware.VimAutomation.Core', but the module could not be
    [96m | [91mloaded. For more information, run 'Import-Module
    [96m | [91mVMware.VimAutomation.Core'.
    [0m
    [91mDisconnect-VIServer: [0m/usr/lib/zabbix/externalscripts/vc_dsc.ps1:6
    [96mLine |
    [96m 6 | [0m [96mDisconnect-VIServer[0m -Server * -Force -Confirm:$false
    [96m | [91m ~~~~~~~~~~~~~~~~~~~
    [91m[96m | [91mThe 'Disconnect-VIServer' command was found in the module
    [96m | [91m'VMware.VimAutomation.Core', but the module could not be
    [96m | [91mloaded. For more information, run 'Import-Module
    [96m | [91mVMware.VimAutomation.Core'.
    [0m
    null

    Вам удалось как-то решить вашу?

    Comment

    Working...