Ad Widget

Collapse

UserParameter script returnig empty string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #1

    UserParameter script returnig empty string

    I'm trying to execute a script using UserParameters but Zabbix server is receiving an empty string.
    Click image for larger version  Name:	empty_string.PNG Views:	0 Size:	3.5 KB ID:	426708

    Zabbix Server 4.4.4 in CentOS 7
    Host Windows 2012

    Code:
    UserParameter=log_dcsp_urs_p,powershell -ExecutionPolicy bypass -Command (Get-Item E:\DIR\PATH).LastWriteTime.ToString('dd-MM-yyyy HH:mm:ss')
    When I try to execute the custom key using Zabbix_Get, it also receives an empty string.
    Code:
    $ zabbix_get -s 172.24.168.24 -k log_dcsp_urs_p
    But, when I test the item within the server itself using the zabbix agent, it shows me the expected result.
    Code:
    C:\zabbix\bin>zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.conf -t log_dcsp_urs_p
    log_dcsp_urs_p [t|17-06-2021 10:34:22]
    There is no error message related to this key in the agent's log neither in the server's log.
    And I can't seem to find the root cause for this behavior.

    Any ideas?
    Thanks
    Last edited by markfree; 18-06-2021, 18:05.
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #2
    Sorry, I forgot to mention the Server version and host OS information. Edited the post above.

    It seems the issue is in between the host and zabbix server.
    But I still haven't found it yet.

    Comment

    • markfree
      Senior Member
      • Apr 2019
      • 868

      #3
      I'm returning to this issue only now. It is still happening occasionally..
      I've captured Zabbix Agent log and it reports an empty string as well.
      Code:
      9304:20211124:090825.833 Requested [log_dcsp_urs_p]
      9304:20211124:090825.872 EXECUTE_STR() command:'powershell -ExecutionPolicy bypass -Command (Get-Item E:\DIR\PATH).LastWriteTim e.ToString('dd-MM-yyyy HH:mm:ss')' len:0 cmd_result:''
      9304:20211124:090825.873 Sending back []
      I've also tried changing the item's key to "system.run", but the outcome is the same.
      Code:
      system.run[powershell -ExecutionPolicy bypass -Command "(Get-Item E:\DIR\PATH).LastWriteTim e.ToString('dd-MM-yyyy HH:mm:ss')"]
      Last edited by markfree; 25-11-2021, 13:24.

      Comment

      • tim.mooney
        Senior Member
        • Dec 2012
        • 1427

        #4
        How long does this command typically take to run? Is it possible it's exceeding the agent item timeout?

        Comment

        • markfree
          Senior Member
          • Apr 2019
          • 868

          #5
          Originally posted by tim.mooney
          How long does this command typically take to run? Is it possible it's exceeding the agent item timeout?
          It runs almost instantly. It's very fast.

          Comment

          • splitek
            Senior Member
            • Dec 2018
            • 101

            #6
            Originally posted by markfree
            [SIZE=16px][FONT=Arial]I'm returning to this issue only now. It is still happening occasionally..
            "occasionally" - so I think it may be something related to powershell.
            I suggest you to put this command in "ps1" file and run this file from userparameter, like:
            Code:
            system.run[C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file C:\path_to_script\some.ps1]
            Also add logging what is returned from command to some log file.
            Maybe this way you will find where is a problem.

            Comment

            • markfree
              Senior Member
              • Apr 2019
              • 868

              #7
              Originally posted by splitek
              "occasionally" - so I think it may be something related to powershell.
              I suggest you to put this command in "ps1" file and run this file from userparameter, like:
              Code:
              system.run[C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file C:\path_to_script\some.ps1]
              Also add logging what is returned from command to some log file.
              Maybe this way you will find where is a problem.
              It seems like a PS issue but it only occurs with Zabbix server.
              If I execute it directly from cli, it always outputs the correct result.
              Anyhow, I'll follow your suggestion and place that PS command whitin a script.

              Comment

              • cyber
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • Dec 2006
                • 4807

                #8
                Tried to replicate... Same userparameter (just different directory/file).. No issues whatsoever. Getting values with test, with zabbix_get and also by normal polling..

                Comment

                • cyber
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Dec 2006
                  • 4807

                  #9
                  My test was with 4.4.10 and 2012R2...

                  Comment

                  Working...