Ad Widget

Collapse

Zabbix 3.x system.run and powershell on windows server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dduval
    Junior Member
    • Jul 2016
    • 1

    #1

    Zabbix 3.x system.run and powershell on windows server

    I'm having problems with the syntax of the item i created for a pretty simple powershell command. If I am direclty in powershell on the server it works just find, counts the netstat numbers and sender updates the item. When I put it in the item it does not work. I know its something very simple, I just can't see the error of my ways. Another set of eyes would be great

    Item
    system.run[powershell $o=(netstat -nao |findstr "3389" |findstr "ESTABLISHED").count;c:\Program Files\Zabbix\zabbix_sender.exe -c c:\zabbix_agentd.conf -k dd_port_count_one_liner -o "$o"",nowait]
    powershell command
    $o=(netstat -nao| findstr "3389" | findstr "TIME_WAIT").count;c:"Program Files"\Zabbix\zabbix_sender.exe -c c:\zabbix_agentd.conf -k dd_port_count_one_liner -o $o
  • AdonisRiley
    Junior Member
    • Jul 2023
    • 2

    #2
    How can I configure Zabbix 3.x to use the system.run functionality on a Windows Server?

    Comment

    • asifnaveed8527
      Junior Member
      • Aug 2023
      • 1

      #3
      Originally posted by dduval
      I'm having problems with the syntax of the item i created for a pretty simple powershell command. If I am direclty in powershell on the server it works just find, counts the netstat numbers and sender updates the item. When I put it in the item it does not work. I know its something very simple, I just can't see the error of my ways. Another set of eyes would be great

      Item
      system.run[powershell $o=(netstat -nao |findstr "3389" |findstr "ESTABLISHED").count;c:\Program Files\Zabbix\zabbix_sender.exe -c c:\zabbix_agentd.conf -k dd_port_count_one_liner -o "$o"",nowait]
      powershell command
      Thop $o=(netstat -nao| findstr "3389" | findstr "TIME_WAIT").count;c:"Program Files"\Zabbix\zabbix_sender.exe -c c:\zabbix_agentd.conf -k dd_port_count_one_liner -o $o

      Enable Remote Commands


      First, ensure that remote commands are enabled in your Zabbix agent configuration file, which is typically found at C:\Program Files\Zabbix Agent\zabbix_agentd.conf on a Windows server.

      Open this file and find the following lines, then make sure they are set as follows:

      Code
      EnableRemoteCommands=1 UnsafeUserParameters=1

      Restart the Zabbix agent service to apply these changes. 2. Configure the Item


      In your Zabbix server frontend:
      • Navigate to Configuration -> Hosts.
      • Click on the Items next to the Windows host.
      • Click Create Item.
      • Enter a suitable name for the item.
      • Set the Type to "Zabbix agent" or "Zabbix agent (active)".
      • In the Key field, use the system.run[] item with the command you want to execute. For a PowerShell script, it might look something like:
      Code
      system.run[powershell -File "C:\path\to\your\script.ps1"]
      • Configure other item parameters as needed and click Add.
      3. Handling Execution Policy in PowerShell


      By default, PowerShell's execution policy might prevent scripts from running. You may need to allow the execution of scripts on the Windows server by running the following command as an administrator:

      Code
      Set-ExecutionPolicy RemoteSigned

      Or, if you want to bypass the execution policy just for this specific script, you could modify the system.run key as follows:

      Code
      system.run[powershell -ExecutionPolicy Bypass -File "C:\path\to\your\script.ps1"] 4. Monitoring and Troubleshooting


      After setting up the item, you should be able to see the results in the Monitoring -> Latest data section. If it's not working as expected, check the Zabbix agent logs on the Windows server, which might provide insight into what's going wrong.

      Keep in mind that running remote commands and scripts, especially with relaxed execution policies, can pose security risks if not handled carefully. Always follow best practices for security in your environment.

      Comment

      Working...