Ad Widget

Collapse

How to print previous and following lines of a matched log line ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gongaro
    Junior Member
    • Sep 2019
    • 1

    #1

    How to print previous and following lines of a matched log line ???

    Hello,
    I'd like to create an Item and a trigger that monitor a log file with a regexp that if matched print that line, the 5 previous lines and the 5 following lines.

    Is this possible?

    Thanks!

    Gianluca
  • 1berto
    Senior Member
    • Sep 2018
    • 182

    #2
    I don't think you can do this with the 'native' log item, but you can create a system.run[ ] ( in the server ) or a UserParameter (in the agent conf). grep have the -A and -B options to do what you want:
    1) key: system.run[ grep -A 5 -B 5 'SEARCH_STRING' /log/file/name.log
    2) UserParameter:get_search_string[ * ] , grep -A 5 -B 5 '$1' /log/file/name.log
    The second option is prefereable
    key: get_search_string[ SEARCH_STRING ]
    Please check the exact syntax... Those are just ideas
    http://zabbix.com/documentation/3.0/...userparameters
    http://zabbix.com/documentation/3.0/...s/zabbix_agent

    Comment

    Working...