Ad Widget

Collapse

External Powershell script - FailoverCluster

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wajzy
    Junior Member
    • Mar 2018
    • 7

    #1

    External Powershell script - FailoverCluster

    Hi,

    I am trying get some info about FailoverCluster Storage from one of the servers. I made a simple script to read percentage free space of shared volumes. I setup UserParameter in config file, restart agent, let agent run under user which can control failover cluster.
    But when I try zabbix_get i get Error that I cant load FailoverCluster module. So is my script ok or am I missing something? Also when I want get this key from Zabbix it self i go error "Value Should be a JSON object".

    Script:
    Import-Module FailoverClusters
    $obj =
    $objs = @()
    $csvs = Get-ClusterSharedVolume


    foreach ( $csv in $csvs )
    {
    $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo


    $obj = New-Object PSObject -Property @{
    '{#Name}' = $csvinfos.Name
    '{#PercentFree}' = $csvinfos.Partition.PercentFree
    }

    $objs += $obj
    }

    write-host "{"
    write-host " `"data`":"
    $objs | ConvertTo-Json
    write-host
    write-host "}"



    + Import-Module FailoverClusters
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (FailoverClusters:String) [
    Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
    ands.ImportModuleCommand

    Get-ClusterSharedVolume : The term 'Get-ClusterSharedVolume' is not recognized
    as the name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is correc
    t and try again.
    At C:\Zabbix\scripts\get_volperc.ps1:4 char:9
    + $csvs = Get-ClusterSharedVolume
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-ClusterSharedVolume:String)
    [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    {
    "data":

    }

    UserParameter:
    UserParameter=volperc.discovery,powershell -NoProfile -executionPolicy Bypass -File C:\Zabbix\scripts\get_volperc.ps1


    Error:
    + Import-Module FailoverClusters
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (FailoverClusters:String) [
    Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
    ands.ImportModuleCommand

    Get-ClusterSharedVolume : The term 'Get-ClusterSharedVolume' is not recognized
    as the name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is correc
    t and try again.
    At C:\Zabbix\scripts\get_volperc.ps1:4 char:9
    + $csvs = Get-ClusterSharedVolume
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-ClusterSharedVolume:String)
    [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    {
    "data":

    }

  • dkp0h
    Junior Member
    • Mar 2018
    • 8

    #2
    Hello Wajzy, what about your problem ? do you find the solution ?

    I try to check the CSVs too and your script seems to be good to do this....

    I try to put this PS script on zabbix folder, put UserParameter in CONF file and try zabbix_get.exe :

    .\zabbix_get.exe -s X.X.X.X -p10050 -k volperc.discovery ==>> SUCCESS ( On my host i don't need to Import-Module )

    But after multiple try on ZABBIX Template, i fail to get data...

    Can you tell me how you do on zabbix ? Discovery ? Check[*].....i lost my brain....

    SeeU

    Thank You

    Comment

    • Wajzy
      Junior Member
      • Mar 2018
      • 7

      #3
      Hi, No i didnt find a solution yet.

      I try use zabbix_get on localhost but still no success.

      On zabbix server I try to use this as discovery, but without success.

      Comment

      • aigars.kadikis
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Mar 2018
        • 208

        #4
        Hi, Wajzy!

        You must create two different scripts:

        - first script will discover all possible options which hosts under $csvinfos.Name
        UserParameter=volperc.discovery,powershell -NoProfile -executionPolicy Bypass -File C:\Zabbix\scripts\discover_volumes.ps1
        The syntax of output must be just exact:
        {"data":[{"{#Name}":"vol1"},{"{#Name}":"vol2"},{"{#Name}":" vol3"}]}
        Please test the key on windows machine before moving forward:
        zabbix_agentd.exe -c zabbix_agentd.conf -t "volperc.discovery"

        In the frontend please open [Create discovery rule] section and set discovery key as volperc.discovery

        - second script will pass variable "vol1" to get.volperc[*]
        UserParameter=get.volperc[*],powershell -NoProfile -executionPolicy Bypass -File C:\Zabbix\scripts\get_volperc.ps1 $1
        Note the asterisk and $1. The output of this script should be one numer in single line
        In the frontend please open [Create item protoptype] section, select item type: Zabbix agent (active) and set item key as get.volperc[{#Name}]

        Comment

        • Wajzy
          Junior Member
          • Mar 2018
          • 7

          #5
          So first script discover N volumes and the second will get values to this Volumes?

          How about Item prototrypes or Trigger prototypes?

          What i want to generate warning when there will be 5% or less free space.

          Thanks

          Comment

          • aigars.kadikis
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Mar 2018
            • 208

            #6
            Yes! 1) Discover volumes; 2) Get values one by one using "Item prototypes";

            The next step would be to create trigger prototype. Assuming you are doing this in template level and if the PowerShell script prints the number already in percentage then the trigger in template would look like:
            {template name:get.volperc[{#Name}].last(0)}<5

            Comment

            • Wajzy
              Junior Member
              • Mar 2018
              • 7

              #7
              So I try your advice but I did something wrong i guess in item prototype creation.

              I now get error Cannot create item: item with the same key "get.voltperc[{#Name}]" already exists

              Comment

              • dkp0h
                Junior Member
                • Mar 2018
                • 8

                #8
                Hello Guys, i hope we found our solution for this powershell script....i try to get similar informations about my CSVs volumes....let me explain.....

                I try with this script :


                PS C:\Program Files\Zabbix Agent\scripts> .\WinDrives_Status.ps1
                {
                "data":[
                { "{#FSNAME}":"C:/" , "{#FSTYPE}":"NTFS" },
                { "{#FSNAME}":"Volume-99da8c5d-5120-4e93-b2fa-0f1d3cf6c26c+" , "{#FSTYPE}":"NTFS" },
                { "{#FSNAME}":"C:/ClusterStorage/Volume9/" , "{#FSTYPE}":"CSVFS" },

                (.....)

                ]
                }

                With parameters available ($1 = FreeSpace / Capacity) : $2 (#FSNAME)

                PS C:\Program Files\Zabbix Agent\scripts> .\WinDrives_Status.ps1 Capacity C:/ClusterStorage/Volume6/
                2147609411584
                PS C:\Program Files\Zabbix Agent\scripts> .\WinDrives_Status.ps1 FreeSpace C:/ClusterStorage/Volume6/
                1288841396224


                In my .conf :

                UserParameter=csvvol.discovery,powershell -NoProfile -executionPolicy Bypass -File "C:\Program Files\Zabbix Agent\scripts\WinDrives_Status.ps1"
                UserParameter=get.csvvol[*],powershell -NoProfile -executionPolicy Bypass -File "C:\Program Files\Zabbix Agent\scripts\WinDrives_Status.ps1" $1 $2

                I know that i can test the disco thing with this :

                PS C:\Program Files\Zabbix Agent> .\zabbix_agentd.exe -c zabbix_agentd.conf -t "csvvol.discovery"
                csvvol.discovery [t|{
                "data":[

                { "{#FSNAME}":"C:/" , "{#FSTYPE}":"NTFS" },
                { "{#FSNAME}":"Volume-99da8c5d-5120-4e93-b2fa-0f1d3cf6c26c+" , "{#FSTYPE}":"NTFS" },
                { "{#FSNAME}":"C:/ClusterStorage/Volume9/" , "{#FSTYPE}":"CSVFS" },

                (....)

                ]
                }]

                Can i test the result for an item with zabbix_get.exe ???

                .\zabbix_get.exe -s 10.x.X.x -p 10050 -k get.csvvol["FreeSpace":"C:/ClusterStorage/Volume7/"] .... I get 'Incorrect Command given"


                For ZABBIX Template creation, i first create 'Discovery Rule' :

                Name : DiscoCSVs
                Type : Zabbix Agent
                Key : csvvol.discovery
                Filter : A {#FSTYPE} matches CSVFS (Is that the way that i can use this ?)


                Then from this 'Discovery Rule' i create 2 'Items Prototype' : FreeSpace_CSV / TotalSpace_CSV

                Type : Zabbix Agent ( Active)
                Key : get.csvvol["FreeSpace" {#FSNAME}]
                Application : CSVs ... is it mandatory ? (to be available in 'Latest Data')

                How can i specify my Key : get.csvvol["FreeSpace",{#FSNAME}] , get.csvvol[FreeSpace,{#FSNAME}]

                Maybe if i found how i can test with zabbix_get.exe, i will find the Key i need....

                Thanks Guys...see you

                Comment

                • dkp0h
                  Junior Member
                  • Mar 2018
                  • 8

                  #9
                  Ok for the "zabbix_get.exe" it's ok :

                  .\zabbix_get.exe -s 10.x.X.x -p 10050 -k get.csvvol["FreeSpace C:/ClusterStorage/Volume7/"]
                  1228467994624

                  So i suppose my 'Item Prototype' should be :
                  get.csvvol["FreeSpace {#FSNAME}"]

                  To be continued...

                  Comment

                  • dkp0h
                    Junior Member
                    • Mar 2018
                    • 8

                    #10
                    Hello, today nothing more in DATAS from my host with this new template created....
                    I suppose that when the template is not well configured, there's no new datas in the "LATEST DATA".....the template name doesn't appear...

                    Is it important to create an APPLICATION in template to see in LATEST DATA ??
                    Thanks

                    Comment

                    • aigars.kadikis
                      Senior Member
                      Zabbix Certified SpecialistZabbix Certified Professional
                      • Mar 2018
                      • 208

                      #11
                      Originally posted by Wajzy
                      So I try your advice but I did something wrong i guess in item prototype creation.

                      I now get error Cannot create item: item with the same key "get.voltperc[{#Name}]" already exists
                      This type of error message can appear when there is no real value for macro {#Name}. Please test the discovery key from command line:
                      zabbix_agentd.exe -c zabbix_agentd.conf -t "volperc.discovery"

                      Does the output contains macros name "{#Name}" in it + all your volume names? Can you share some output?

                      Comment

                      • aigars.kadikis
                        Senior Member
                        Zabbix Certified SpecialistZabbix Certified Professional
                        • Mar 2018
                        • 208

                        #12
                        Originally posted by dkp0h
                        Hello, today nothing more in DATAS from my host with this new template created....
                        I suppose that when the template is not well configured, there's no new datas in the "LATEST DATA".....the template name doesn't appear...

                        Is it important to create an APPLICATION in template to see in LATEST DATA ??
                        Thanks
                        Filing "Application" field It is not mandatory. But if you fill this field then.. Application gives you quite handy functionality for instance if you assign template to multiple hosts and you want to later compare gathered information for all hosts together then..
                        Open latest data section. Remove all filters and search only by application name.

                        Comment

                        • Wajzy
                          Junior Member
                          • Mar 2018
                          • 7

                          #13
                          Originally posted by aigars.kadikis

                          This type of error message can appear when there is no real value for macro {#Name}. Please test the discovery key from command line:
                          zabbix_agentd.exe -c zabbix_agentd.conf -t "volperc.discovery"

                          Does the output contains macros name "{#Name}" in it + all your volume names? Can you share some output?
                          My output, when voltperc.dicovery used script above is like this:
                          {
                          "data":
                          [
                          "{#Name}": "Volume 1"
                          },
                          {
                          "{#Name}": "Volume 2"
                          },
                          ]
                          ​​​​​​​}

                          Comment

                          • dkp0h
                            Junior Member
                            • Mar 2018
                            • 8

                            #14
                            Originally posted by aigars.kadikis

                            Filing "Application" field It is not mandatory. But if you fill this field then.. Application gives you quite handy functionality for instance if you assign template to multiple hosts and you want to later compare gathered information for all hosts together then..
                            Open latest data section. Remove all filters and search only by application name.
                            Nothing appear in 'Latest Datas' even with a this only filter 'Application = CSVs'.....

                            Comment

                            • dkp0h
                              Junior Member
                              • Mar 2018
                              • 8

                              #15
                              Is that ok that my 'Discovey Rule' and 'Item Prototypes' need to be in 'Zabbix Agent (Active)" ?

                              Comment

                              Working...