Ad Widget

Collapse

Zabbix 3.4 Agent grabbing data from a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jbgoheels
    Junior Member
    • May 2017
    • 9

    #1

    Zabbix 3.4 Agent grabbing data from a text file

    Hello,

    I have Zabbix Agent version 3.4 running on a Server 2012R2 machine. The machine runs a DFS backlog report every day at 9am. The report is a simple text file that contains the date and the backlog count. I would like for Zabbix to pull the count from the text file and alert me if the count goes above 100.

    The text file is located at C:\DFSLog.txt

    This file contains the following:
    3/14/2018 9:00:10 AM servername 0
    So I need to get this 0 value on my zabbix server.

    So I created an item in Zabbix under the host where the report is located Named "DFS", type "Zabbix Agent", key vfs.file.regexp["C:\DFSLog.txt",], text.

    Is this possible with regexp?

    Thanks!
  • jbgoheels
    Junior Member
    • May 2017
    • 9

    #2
    I am able to grab the first character of the txt file, but cannot grab the whole string.

    Here is what I am using to grab the info from the txt file.

    vfs.file.regexp[C:\DFSLog.txt,"([0-9]+)$",,1,1,\1]

    Any particular reason why it will only grab the first character of the txt file?

    Comment

    • sancho
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Mar 2015
      • 295

      #3
      Hello jbgoheels,
      Try downloading the unixtools on the server windows http://unxutils.sourceforge.net/ and add the folder where you have unzipped to windows environment variables or copying gawk.exe to your windows folder.

      Then create an item zabbix agent
      Key: system.run [type C: \ DFSLog.txt | gawk "{print $ 5}"]
      Type of information: Numeric (float)

      I hope it helps you.

      A greeting.

      Comment

      • jbgoheels
        Junior Member
        • May 2017
        • 9

        #4
        Thanks for the reply sancho. Here's what I'm getting when trying to add the item into Zabbix.
        • Invalid key "system.run [type C:\DFSLog.txt | gawk "{print $ 5}"]" for item "DFS Log" on "Server": incorrect syntax near " [type C:\DFSLog.txt | gawk "{print $ 5}"]".

        Comment

        • sancho
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Mar 2015
          • 295

          #5
          jbgoheels copy the file gawk.exe that you should have downloaded with the unixutils in C:\Windows\System32
          The error seems to be because the system can not find the program gawk.exe

          Comment

          • jbgoheels
            Junior Member
            • May 2017
            • 9

            #6
            Got it working! Thanks for your help sancho!

            The key that I used was:

            system.run[type C:\DFSLog.txt | gawk "{print $ 5}",wait]

            Type of information: Text

            Comment

            • sancho
              Senior Member
              Zabbix Certified SpecialistZabbix Certified Professional
              • Mar 2015
              • 295

              #7
              I'm glad you it worked

              Comment

              • jbgoheels
                Junior Member
                • May 2017
                • 9

                #8
                I need Zabbix to read another text file. This file has 3 lines.

                4/19/2018 11:09:43 AM
                server
                500

                Is there a way to get the key to use gawk to read from the 3rd line only?

                Comment

                • jbgoheels
                  Junior Member
                  • May 2017
                  • 9

                  #9
                  Got it.

                  Use this Key:

                  system.run[type C:\DFSR-BACKLOG\REPORTS\server-TOTAL-Backlog-Report.txt | gawk "FNR == 3 {print $ 1}",wait]

                  Comment

                  • jbgoheels
                    Junior Member
                    • May 2017
                    • 9

                    #10
                    If anyone wants to monitor DFSR Backlogs on Server 2012 R2 using Zabbix 3.4 this is one method that works.

                    Use the Powershell script located at: https://gallery.technet.microsoft.co...e18d5b#content

                    Add these lines (change path accordingly) to the script near the beginning:

                    ### ENSURE REPORTS FILE EMPTY ###
                    Clear-Content C:\DFSR-BACKLOG\REPORTS\server1-TOTAL-Backlog-Report.txt
                    Clear-Content C:\DFSR-BACKLOG\REPORTS\server2-TOTAL-Backlog-Report.txt

                    This will clear out the report each time it is run.

                    Automate the script to run on a schedule.

                    This will output a txt file with the following contents:

                    4/19/2018 11:09:43 AM
                    server
                    0

                    The 3rd line is the backlog count.

                    On the server running the powershell script, follow sancho's advice from above and download UnxUtils.

                    In Zabbix, create an item for the server running the powershell script.

                    Use this key: (change path accordingly)

                    system.run[type C:\DFSR-BACKLOG\REPORTS\server-TOTAL-Backlog-Report.txt | gawk "FNR == 3 {print $ 1}",wait]

                    Comment

                    • sancho
                      Senior Member
                      Zabbix Certified SpecialistZabbix Certified Professional
                      • Mar 2015
                      • 295

                      #11
                      Thanks jbgoheels

                      Comment

                      Working...