DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Cloud Migration: How To Overcome Fears and Capitalize on Opportunities
  • Modern Data Backup Strategies for Safeguarding Your Information
  • Performance Optimization Strategies in Highly Scalable Systems
  • A Guide to Data-Driven Design and Architecture

Trending

  • Building AI Applications With Java and Gradle
  • Database Monitoring: Key Metrics and Considerations
  • Unleashing the Power of Microservices With Spring Cloud
  • Exploring Sorting Algorithms: A Comprehensive Guide
  1. DZone
  2. Data Engineering
  3. Data
  4. Notify on Errors in a Log File with Zabbix 1.8

Notify on Errors in a Log File with Zabbix 1.8

Jakub Holý user avatar by
Jakub Holý
·
Jul. 15, 12 · Tutorial
Like (1)
Save
Tweet
Share
24.19K Views

Join the DZone community and get the full member experience.

Join For Free

Situation: You want to get notified when a log entry marked ERROR appears in a log file. You want the corresponding trigger to reset back to the OK state if there are no more errors for 10 minutes. (This post assumes certain familiarity with Zabbix UI.)


Solution

Create log item sending error log lines

Create a new item with

  • Type: Zabbix agent (active)
    • It must be “Zabbix agent (active)” because it isn’t pulled by the server in regular intervals but pushed by the agent whenever there is a new (matching) log line.
  • Key: log["/tmp/ada/hive.log","ERROR",,20]
    • You could also use logrt if you have rotating logs (zabbix would only read the latest or all, as you want)
    • Here we specify that we only want to send lines that contain the regular expression ERROR, we could also have a more complex pattern such as “(ERRORS|WARNINGS)”. We assume that there are many uninteresting log lines and don’t want to send those unnecessarily over the network.
  • Type of information: Log
  • Log time format: Optional, a pattern matching date+time info at the beginning of each line, f.ex. “yyyy-MM-dd hh:mm:ss” (you could use also any other character, f.ex. ‘x’, as a placeholder for timestamp-unrelated data preceeding the timestamp)

Troubleshooting:

If your item isn’t receiving any data even though there are error entries in the log then enable detailed logging in Zabbix to verify that the agent and server haven’t a problem. (If they do then the status of the item will be changed to “Not supported” by Zabbix.)

To enable logging, make sure there is DebugLevel=5 and LogFile=/var/log/zabbix-agent/zabbix_agentd.log (without a leading #)  in /etc/zabbix/zabbix_agentd.conf.

One possible cause of problem is if Hostname in /etc/zabbix/zabbix_agentd.conf and in the Zabbix UI differ, f.ex. if one of them is fully qualified and the other isn’t.

If everything is OK then you should see a log like this:

14187:20120626:085459.706 refresh_active_checks('10.2.0.83',10051)
 ...
 14187:20120626:085459.869 Got [{
        "response":"success",
        "data":[
                {
                        "key":"log[\"\/tmp\/ada\/hive.log\",\"ERROR\",,20]",
                        "delay":"30",
                        "lastlogsize":"127180",
                        "mtime":"0"}]}]
 14187:20120626:085459.869 In parse_list_of_checks()
 14187:20120626:085459.869 In disable_all_metrics()
 14187:20120626:085459.869 In add_check('log["/tmp/ada/hive.log","ERROR",,20]', 30, 127180, 0)
...

 14187:20120626:085530.156 In process_active_checks('10.2.0.83',10051)
 14187:20120626:085530.156 In process_log() filename:'/tmp/ada/hive.log' lastlogsize:186157

Create a trigger that fires if it receives any data from the item

The item only has data if there are any error logs. Therefore the trigger needs fire if it receives any data and get off if there hasn’t been any new (error) data in a period, such as 600 sec. We would therefore create a trigger using the nodata(period) function that returns 1 if there indeed has been no new data in the period:

  • Expression: {myserver.example.com:log["/tmp/ada/hive.log","ERROR",,20].nodata(600)}=0

Create an action to send an e-mail

This is described well enough in Zabbix documentation. Basically you’d create an action with the condition Trigger = <the name of the trigger created above>. (And perhaps with “and Trigger value = PROBLEM”.) You might also want to set up escalation to get reminder emails – perhaps after a growing delay – if the problem persists, i.e. if there is an error every 10 min or more often.

Key points

  • Make sure to use Zabbix agent (active)
  • If you aren’t getting any data, enable and check the log. Make sure hostname in agent config and server match.
  • Data are only sent when there is an error => use nodata(aPeriod) to automatically reset the trigger (if this is what you want)

 

Data (computing)

Published at DZone with permission of Jakub Holý, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Cloud Migration: How To Overcome Fears and Capitalize on Opportunities
  • Modern Data Backup Strategies for Safeguarding Your Information
  • Performance Optimization Strategies in Highly Scalable Systems
  • A Guide to Data-Driven Design and Architecture

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: