Ad Widget

Collapse

Zabbix Discovery rule Powershell command not working

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CristianR
    Junior Member
    • Apr 2023
    • 12

    #1

    Zabbix Discovery rule Powershell command not working

    Hello Zabbix Community,

    I am trying to create a LLD Discovery rule in Zabbix that extract the folder name and the parent folder name. It works perfectly if I run the PowerShell command in Powershell but when I test it on Zabbix I get
    Invalid second parameter.​
    error.
    Here's the code:
    Code:
    system.run[powershell.exe -NoProfile -ExecutionPolicy bypass -c "Get-ChildItem -Path c:\apps -Directory -filter tomcat-* | Get-ChildItem -Directory | select name, @{Name = 'ParentFolder'; Expression = {$_.Parent.Name}}|ConvertTo-Json"]
    Any Idea how to overcome this problem?

    Thank you.
    Attached Files
    Last edited by CristianR; 17-05-2023, 19:17.
  • Answer selected by CristianR at 18-05-2023, 08:53.
    Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    I think that the problem is with quotes in the expression. system.run takes part of your expression as its second parameter....

    try something like
    Code:
    system.run["powershell.exe -NoProfile -ExecutionPolicy bypass -c 'Get-ChildItem -Path c:\apps -Directory -filter tomcat-* | Get-ChildItem -Directory | select name, @{Name = 'ParentFolder'; Expression = {$_.Parent.Name}}|ConvertTo-Json' "]
    or
    Code:
    system.run["powershell.exe -NoProfile -ExecutionPolicy bypass -c \"Get-ChildItem -Path c:\apps -Directory -filter tomcat-* | Get-ChildItem -Directory | select name, @{Name = 'ParentFolder'; Expression = {$_.Parent.Name}}|ConvertTo-Json\" "]

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #2
      I think that the problem is with quotes in the expression. system.run takes part of your expression as its second parameter....

      try something like
      Code:
      system.run["powershell.exe -NoProfile -ExecutionPolicy bypass -c 'Get-ChildItem -Path c:\apps -Directory -filter tomcat-* | Get-ChildItem -Directory | select name, @{Name = 'ParentFolder'; Expression = {$_.Parent.Name}}|ConvertTo-Json' "]
      or
      Code:
      system.run["powershell.exe -NoProfile -ExecutionPolicy bypass -c \"Get-ChildItem -Path c:\apps -Directory -filter tomcat-* | Get-ChildItem -Directory | select name, @{Name = 'ParentFolder'; Expression = {$_.Parent.Name}}|ConvertTo-Json\" "]

      Comment

      • CristianR
        Junior Member
        • Apr 2023
        • 12

        #3
        Hamardaban , thank you so much for your quick reply. I tested and the second one works perfectly.
        Code:
        system.run["powershell.exe -NoProfile -ExecutionPolicy bypass -c \"Get-ChildItem -Path c:\apps -Directory -filter tomcat-* | Get-ChildItem -Directory | select name, @{Name = 'ParentFolder'; Expression = {$_.Parent.Name}}|ConvertTo-Json\" "]
        Cristian

        Comment

        Working...