Ad Widget

Collapse

Zabbix_get and powershell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • topcek
    Junior Member
    • Jun 2010
    • 17

    #1

    Zabbix_get and powershell

    Hi,

    i have a qustion. I'm trying to achieve monitoring Hyper-V replication with zabbix but nothing what i have tried didn't work.

    i did:

    write in zabbix_agentd.conf
    Userparameter=vm.state,powershell,c:\test.ps1

    and contecnt in script is:

    $Health = Get-VMReplication
    foreach($State in $Health){

    if($state.Health -match "Normal"){
    $output = 1
    }else{

    $output = 1
    }

    }
    write-host $output

    i get ZBX_NOTSUPPORTED when running zabbix_get -s IP -k vm.state from zabbix server

    for testing purposes i have tried to modify last line to write-host "1"

    and i get value. after digging in i noticed that i'm unable to run any powershell get- command.

    i have tried this:
    $Health = "BLABLABLA"
    write-host $output
    i got
    BLABLABLA

    so i'm i missing something or is just a bug. version of server and zabbix agent is 2.2.2


    any userful hints?
  • aib
    Senior Member
    • Jan 2014
    • 1615

    #2
    1) Check your UserParameter= string. It can contain only(!) one comma.
    Code:
    UserParameter=vm.state,powershell "c:\test.ps1"
    2) Use the full path and name of powershell.exe and some additional keys to reduce non important output. (link to thread)
    Code:
    UserParameter=service.discovery,powershell.exe -NoProfile -ExecutionPolicy Bypass -file "C:\Program Files\Zabbix\Service_Discovery.ps1"
    Sincerely yours,
    Aleksey

    Comment

    • topcek
      Junior Member
      • Jun 2010
      • 17

      #3
      Oh, sorry i have mistyped. my user parameter was:

      UserParameter=vm.state,powershell.exe -NoProfile -ExecutionPolicy Bypass -file "c:\test.ps1"

      so after calling from server with zabbix_get i recieve ZBX_NOTSUPPORTED.

      However if i only change in script the main cmdlet GET-VMReplication to something more simple everything works without changing anything in zabbix.

      $Health = Get-VMReplication <== Changing this to "BLABLA"
      foreach($State in $Health){

      if($state.Health -match "Normal"){
      $output = 44
      }else{

      $output = 2
      }

      }

      write-host $output

      i would get result 2.

      it seems that powershell returns something to zabbix that agent can't handle like null or some value.

      I have also tried to convert result to string with | out-string because powershell returns smth. like PSCustomObject type


      any other ideas?

      Comment

      • aib
        Senior Member
        • Jan 2014
        • 1615

        #4
        Do you mind to do some debugging?
        1) On the server, where the Zabbix Agent installed, run the command
        powershell.exe -NoProfile -ExecutionPolicy Bypass -file "c:\test.ps1"

        and check the result.
        May be it is something like " 2 " (with leading and trailing spaces)
        It will be more simple to convert it to simple Internal number before output.
        Code:
        write-host [int]$output
        Sorry if you already try it - it's just from top of my head.
        Sincerely yours,
        Aleksey

        Comment

        • topcek
          Junior Member
          • Jun 2010
          • 17

          #5
          thank you for your information but it doesn't work. i did try also to run batch script and within call powershell with this file test.ps1 to isolate if windows are causing this error. also if i try to call another cmdlet within script instead get-vm and doesn't work either but if i put any random calculation or some st.ring and write it out it works. just like get commands would return some "strange" type because function get- returns type system.pscustomobject and not string. mybe agent doesnt fetch his output and script when agent runs script recieves null which acording to zabbix poor documentation means zbx_notsupported.

          any other mybe hints?

          Comment

          • topcek
            Junior Member
            • Jun 2010
            • 17

            #6
            around debugging i did try to enable logging of remote commands and put on debug level but i only get running script and zbx_notsupported are there any ohter possibiliteies for debug mode?

            Comment

            • topcek
              Junior Member
              • Jun 2010
              • 17

              #7
              OK,

              firstly thank you all for participation. I found solution.

              The problem was in timeout. So default settings are telling zabbix_agent to wait for script for 3 seconds. But apparently powershell needs more than 3 seconds. so i have increased timeout timer and i can pull informations from powershell.

              thank you all.

              Regards!

              Comment

              Working...