Skip to content

Instantly share code, notes, and snippets.

@BumpeiShimada
Created August 28, 2018 09:53
Show Gist options
  • Save BumpeiShimada/9633a604d792ecd03d9454e804e6ceac to your computer and use it in GitHub Desktop.
Save BumpeiShimada/9633a604d792ecd03d9454e804e6ceac to your computer and use it in GitHub Desktop.
How to notify errors through td-agent immediately, only sending counts of certain acknowledged errors daily.
# Retrieve Error Log
<source>
type tail
path {{ path }}
format multiline
format_firstline /^\d{4}-\d{2}-\d{2}/
format1 /^(?<text>.*)/
tag raw.app.errorlog.{{ hostname }}
pos_file /var/tmp/app_log.pos.slack
</source>
# Filter Acknowledged Error
<match raw.app.errorlog.{{ hostname }}>
type rewrite
add_prefix filtered
<rule>
key text
pattern FileNotFoundException
append_to_tag true
tag FileNotFoundException
</rule>
</match>
# Notify Error to the Slack channel
<match filtered.raw.app.errorlog.{{ hostname }}>
type slack
webhook_url {{ webhook_url }}
channel {{ channel }}
username ERROR_NOTIFIER
message '{{ td_agent_app_errorlog_mention }}```[host] {{ hostname }} [Path] {{ errorlog_path }}``` %s'
message_keys text
color warning
flush_interval 10s
</match>
# Notify the count of Acknowledged Errors filtered above
<match filtered.raw.app.errorlog.{{ hostname }}.FileNotFoundException>
type grepcounter
count_interval 86400 # = 24 hours
input_key text
threshold 1
add_tag_prefix count
</match>
<match count.filtered.raw.app.errorlog.{{ hostname }}.FileNotFoundException>
type slack
webhook_url {{ webhook_url }}
channel {{ channel }}
username EXISTING_ERROR_NOTIFIER
icon_emoji :admission_tickets:
message_keys count
message '```FileNotFoundException occured %s times within this 24 hours at {{ hostname }}```'
color #FFB6C1
flush_interval 10
</match>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment