Ad Widget

Collapse

Timeout on Powershell Script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slpefanis
    Member
    • Jan 2020
    • 52

    #1

    Timeout on Powershell Script

    Hi All

    I have a DHCP monitoring script that I am trying to roll out to my sites. I have successfully put this accross 6-8 machines and it is working fine.

    On one of them, I get a "Timeout occurred while gathering data" on the auto discovery.

    I've tried
    • Extending the timeout to 30 seconds
    • running the script manually (takes about 3-5 seconds)
    • Running it via the zabbix command (zabbix_agent2.exe -c zabbix_agent2.conf -t dhcp.scope.discovery)
    I'm using Zabbix Agent v7.0 and server V7.0. This works perfectly fine on other servers with the same settings (Timeout=10)

    Any suggestions on where to look next to resolve this?

    S
  • MRedbourne
    Senior Member
    • Feb 2023
    • 103

    #2
    We've noticed that script execution (especially from server -> agent) is buggy. We had scripts working in 6.4 through a passive agent. Post-upgrade (both passive and active) fail to execute. Passive (hybrid) times out, active fails to find the host interface. We were discussing it in another thread. I ultimately decided to submit a bug report.

    Issue Navigator - ZABBIX SUPPORT
    Remote commands on active agent - ZABBIX Forums​

    Comment

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

      #3
      Have you verified that this is the only item having problems on that host?

      If so, add some debug print statements in the script so that it outputs the place and time in a log file, to get an idea, which command in the script causes the time to be spent excessively.

      Markku

      Comment

      • slpefanis
        Member
        • Jan 2020
        • 52

        #4
        Originally posted by Markku
        Have you verified that this is the only item having problems on that host?

        If so, add some debug print statements in the script so that it outputs the place and time in a log file, to get an idea, which command in the script causes the time to be spent excessively.

        Markku
        I will give this a go and post back any results.

        Comment

        • slpefanis
          Member
          • Jan 2020
          • 52

          #5
          Originally posted by Markku
          Have you verified that this is the only item having problems on that host?

          If so, add some debug print statements in the script so that it outputs the place and time in a log file, to get an idea, which command in the script causes the time to be spent excessively.

          Markku
          I added a "start-transcript" to the script to log all the output. Interestinly enough, It creates the transcript file and writes the "Transcript started" but nothing else. The next step in the file is actually getting the DHCP Server Scopes. The script is below and works fine on my other DHCP servers.

          Code:
          $dateTime = (Get-Date).ToString('yyyyMMdd-HHmmss')
          $logPath = "c:\temp\dhcp.scope.discovery_$dateTime.log"
          
          Start-Transcript -path $logPath -NoClobber
          
          $obj = [PSCustomObject] @{
              data = @(Get-DhcpServerv4Scope | % {
                  [PSCustomObject] @{
                      '{#SCOPEID}' = $_.ScopeID.IPAddressToString
                      '{#SUBNETMASK}' = $_.SubnetMask.IPAddressToString
                      '{#NAME}' = $_.Name
                      '{#STATE}' =  $_.State
                      '{#STARTRANGE}' = $_.StartRange.IPAddressToString
                      '{#ENDRANGE}' = $_.EndRange.IPAddressToString
                      '{#LEASEDURATION}' = $_.LeaseDuration
                  }
              })
          }
          
          Write-Host $($obj | ConvertTo-Json)
          Stop-Transcript

          Comment

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

            #6
            Should it log any errors during the script?

            If you add -ErrorAction Ignore (or some of the other available ErrorAction options) in the Get-DhcpServerv4Scope command, how does the output change? Asking because based on what you said it sounds like an error happens in running the command.

            Have you double-checked that the Zabbix agent user has permission to see the DHCP scopes?

            Markku

            Comment

            • slpefanis
              Member
              • Jan 2020
              • 52

              #7
              Thanks., adding that still doesn't give me anything which is very strange.
              It's running as "Local System" which is the same as our other enviroments. It's really really strange why it's not doing anything.
              I no longer the the timeout in the front end but the log file has

              "2024/07/18 10:32:31.511796 check 'dhcp.scope.discovery' is not supported: Timeout occurred while gathering data"

              Comment

              • PeterZielony
                Senior Member
                • Nov 2022
                • 146

                #8
                What if you set test item on this host with type text and see if this would work with same key?

                All hosts pointing to same proxy/server? Or they are using different ones?

                Have you tried using agent 6.4 as MRedbourne suggested?

                When testing item with -t works? You said you tried but did it work?
                Last edited by PeterZielony; 18-07-2024, 10:01.

                Hiring in the UK? Drop a message

                Comment

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

                  #9
                  Based on the given information, this is not a Zabbix problem but a problem in getting all the PowerShell commands to run correctly on that one host, while on other hosts the same script runs successfully. We also saw that Zabbix agent runs the script (because the transcript log works).

                  I don't know if the DHCP service should be configured showhow specifically to allow "Local System" to view the DHCP scopes.

                  According to chatgpt, you can use PsExec (from Sysinternals) to test the script manually as Local System user:

                  C:\wherever-is-installed\PsExec.exe -i -s powershell.exe -File "C:\scripts\dhcpscript.ps1"

                  Markku

                  Comment

                  • slpefanis
                    Member
                    • Jan 2020
                    • 52

                    #10
                    Thanks. Running this via PSExec actually works fine which confuses me any more.

                    Each host uses a different Proxy based on their "local" site, I can try moving them to another proxy and will report back.

                    No luck to move over to 6.4 yet but will organise it.

                    PeterZielony - Can you expand what you mean with these?
                    • What if you set test item on this host with type text and see if this would work with same key?
                    • When testing item with -t works? You said you tried but did it work?​

                    Comment

                    • PeterZielony
                      Senior Member
                      • Nov 2022
                      • 146

                      #11
                      I mean setup new normal item with key you used in discovery as a text value - this way you will see whats returned in text and you should see exacly what PS returns - maybe there is a problem with discovery in this version?

                      -t means this:
                      "zabbix_agent2.exe -c zabbix_agent2.conf -t dhcp.scope.discovery"

                      Overall i think this is some permission issue

                      Hiring in the UK? Drop a message

                      Comment

                      • slpefanis
                        Member
                        • Jan 2020
                        • 52

                        #12
                        Thanks for the details.
                        "zabbix_agent2.exe -c zabbix_agent2.conf -t dhcp.scope.discovery" - This works and returns the DHCP scopes for the site successfully. I ran CMD as "admin"
                        I've added a new item called "dhcp.scop.dicoveryText" as a text item, added into my .conf and restarted the service. This works and returns my DHCP scope (I did notice the items were set to the global timeout which I think was 4s, so changed that)

                        I also change the global timeout on the original item and that seemed to fix it. Apologies, I hadn't realised there was an timeout for the actual item and got confused because of it working on other servers with larget scopes!

                        Comment

                        • PeterZielony
                          Senior Member
                          • Nov 2022
                          • 146

                          #13
                          Im glad this works now,

                          Sometimes setting thigs few times in different ways leads to solution

                          Hiring in the UK? Drop a message

                          Comment

                          • vbrozek
                            Junior Member
                            • Jul 2025
                            • 1

                            #14
                            Hi, I tried to deal with my error in this thread but I can't get it to work.
                            After reinstalling the server, monitoring for Hyper-V Snapshots stopped working for more than 24 hours.
                            Can you advise?

                            conf:
                            Timeout=30
                            UserParameter=hyperv.snapshot[*],PowerShell.exe -ExecutionPolicy UnRestricted -File C:\zabbix\scripts\hv_snapshot.ps1

                            log:
                            2025/11/27 10:58:56.368571 Zabbix Agent2 hostname: [HYP01]
                            2025/11/27 10:59:12.001564 check 'hyperv.snapshot' is not supported: Timeout occurred while gathering data.
                            2025/11/27 10:59:42.002717 check 'hyperv.snapshot' is not supported: Timeout occurred while gathering data.
                            2025/11/27 11:00:12.003690 check 'hyperv.snapshot' is not supported: Timeout occurred while gathering data.

                            Thank you​​

                            Comment

                            Working...