Ad Widget

Collapse

Zabbix log logrt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murdoua
    Junior Member
    • Dec 2024
    • 8

    #1

    Zabbix log logrt

    Hi. First i tried to use modified version of all search results for similar topics. None of them works. im trying to tel log or logrt item to work with my dynamic logs in /opt/something/2025/03/24/myfile.log , but to no avail. Please help. Am i missing something or is this basic functionality for date structure in folder tree really completely missing?
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Logrt works with regex ONLY in logfile name... it does not work with regex in path

    logrt[file regexp,<regexp>,<encoding>,<maxlines>,<mode>,<outp ut>,<maxdelay>,<options>,<persistent dir>]
    • file regexp - the absolute path to file, with the file name specified using a regular expression. Note that the regular expression applies only to the file name and does not need to match the entire name (e.g., /path/to/agent will match zabbix_agentd.log).

    You can work around this with a discovery (vfs.dir.get https://www.zabbix.com/documentation...nt#vfs.dir.get )
    Which returns your required files and creates items/triggers.

    Comment

    • doren765
      Junior Member
      • Apr 2025
      • 2

      #3
      Hello,

      You're encountering a common challenge when trying to use tel or logrt with dynamic log file paths that include date-based directory structures. The issue likely stems from how these tools handle file paths and their inability to directly interpret date patterns for dynamic expansion.

      Let's break down the problem and explore solutions:

      Understanding the Problem

      Dynamic Paths: Your log files are organized with a date-based directory structure (/opt/something/YYYY/MM/DD/myfile.log). This structure changes daily, making it difficult to specify a static file path.
      tel and logrt Limitations: These tools typically work with static file paths or simple glob patterns. They don't inherently possess the ability to interpret and expand date patterns.
      Solutions

      Here's a breakdown of approaches, ranging from simple to more robust:

      Using find and tail -f (Recommended for Simplicity):

      This is often the most straightforward and reliable method.
      find locates the latest log file based on the date structure.
      tail -f follows the file for real-time updates.
      Bash

      find /opt/something/$(date +%Y)/$(date +%m)/$(date +%d)/ -name myfile.log -print0 | xargs -0 tail -f
      Explanation:
      date +%Y, date +%m, and date +%d generate the current year, month, and day, respectively.
      find searches the specified directory for files named myfile.log.
      -print0 and xargs -0 handle filenames with spaces or special characters safely.
      tail -f follows the output of find.
      Creating a Symbolic Link (If Applicable):

      If you only need to monitor the latest log file, create a symbolic link that always points to the current day's log.
      You can then use tel or logrt on the symbolic link.
      Create a cron job that updates the symlink daily.
      Bash

      # Daily cron job:
      ln -sf /opt/something/$(date +%Y)/$(date +%m)/$(date +%d)/myfile.log /opt/something/latest.log
      Then you can use:

      Bash

      tail -f /opt/something/latest.log
      or if your monitoring tool is configured to monitor files, you can configure it to watch /opt/something/latest.log

      Scripting (For More Complex Scenarios):

      If you need more advanced logic (e.g., monitoring multiple days or handling log rotation), write a script that:
      Dynamically generates the file paths.
      Uses tail -f or another appropriate tool to monitor the files.
      Handles log rotation and other requirements.



      Best Regards
      doren765

      Comment

      Working...