Ad Widget

Collapse

Zabbix Agent Windows, system.run powershell select multiple arguments/properties

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rosselur
    Junior Member
    • Jul 2021
    • 1

    #1

    Zabbix Agent Windows, system.run powershell select multiple arguments/properties

    I am trying to get agents to report in powershell commands with multiple select arguments. I am starting to think it is impossible, I am at the end of my wits here.
    In a template for my client computers, I have an item with the following keys (for example):

    Code:
    system.run[powershell.exe -c "get-localuser"]
    system.run[powershell.exe -c "get-localuser | select name"]
    system.run[powershell.exe -c "get-localuser | select name | fl"]
    system.run[powershell.exe -c "get-localuser | select *"]

    All of them works fine, both from a powershell locally, and the zabbix client reports in.
    But the moment I try to select more properties like so:

    Code:
    system.run[powershell.exe -c "get-localuser | select name,lastlogon"]
    .. I get an error message stating that the command "is not supported: Invalid second parameter."
    I have also tried:

    Code:
    system.run[powershell.exe -c "& {get-localuser | select-object -property "name,lastlogon"}"]
    .. With the same result, Invalid second parameter.
    All of the above works fine directly from a powershell, obviously without the system.run-wrapper.

    This is a complete error message from the zabbix agent:

    Code:
    10620:20210708:131005.770 active check "system.run[powershell.exe -c "& {get-localuser | select-object -property "name,lastlogon"}"]" is not supported: Invalid second parameter.
    I suspect the comma somehow borks things and need to be escaped somehow, I just don't know how.

    Any black belts out there with any ideas ?
  • LdeB
    Junior Member
    • Jul 2021
    • 7

    #2
    Generally the format for multiple commands as per the manual is ... there is no use of commas
    Command A & Command B
    Execute Command A, then execute Command B (no evaluation of anything)

    Command A | Command B
    Execute Command A, and redirect all its output into the input of Command B

    Command A && Command B
    Execute Command A, evaluate the errorlevel after running and if the exit code (errorlevel) is 0, only then execute Command B

    Command A || Command B
    Execute Command A, evaluate the exit code of this command and if it's anything but 0, only then execute Command B

    Comment

    • Markku
      Senior Member
      Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
      • Sep 2018
      • 1781

      #3
      In the documentation https://www.zabbix.com/documentation...s/zabbix_agent it shows comma as a separator for the system.run mode argument. Try to quote your full powershell command so that the comma stays inside of the quotation. You likely need some escaping for your quotes in the command, or use single-quotes instead.

      Markku

      Comment

      Working...