-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
health checker: add missing check for oversized mails
the health checker endpoint only reported unprocessable mails, but not oversized mails that made custom monitoring solutions necessary, or - if not present - could lead to undetected operational issues this adds a check if (and how many) oversized mails are present in the OVERSIZED_MAIL directory with mails present in the oversized mails directory, the health check output now looks like: {"healthy":false,"message":"oversized mails: 4","issues":["oversized mails: 4"],"actions":[]} see also https://community.zammad.org/t/new-unprocessable-mail-directory-does-not-exist-on-zammad-6/11787
- Loading branch information
1 parent
e90ca68
commit 96fd140
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (C) 2023-2023 Intevation GmbH, https://intevation.de/ | ||
|
||
module MonitoringHelper | ||
class HealthChecker | ||
class OversizedMail < Backend | ||
|
||
def run_health_check | ||
return if !File.exist?(Channel::EmailParser::OVERSIZED_MAIL_DIRECTORY) | ||
|
||
count = Dir.glob("#{Channel::EmailParser::OVERSIZED_MAIL_DIRECTORY}/*.eml").count | ||
|
||
return if count.zero? | ||
|
||
response.issues.push "oversized mails: #{count}" | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
spec/lib/monitoring_helper/health_checker/oversized_mail_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (C) 2023-2023 Intevation GmbH, https://intevation.de/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe MonitoringHelper::HealthChecker::OversizedMail do | ||
let(:instance) { described_class.new } | ||
let(:folder) { SecureRandom.hex } | ||
let(:directory) { Rails.root.join('tmp', folder) } | ||
|
||
before { stub_const('Channel::EmailParser::OVERSIZED_MAIL_DIRECTORY', directory) } | ||
after { FileUtils.rm_r(directory) if File.exist?(directory) } | ||
|
||
describe '#check_health' do | ||
it 'does nothing if directory missing' do | ||
expect(instance.check_health.issues).to be_blank | ||
end | ||
|
||
it 'does nothing if no matching files' do | ||
FileUtils.mkdir_p directory | ||
FileUtils.touch("#{directory}/test.not.email") | ||
|
||
expect(instance.check_health.issues).to be_blank | ||
end | ||
|
||
it 'adds issue if oversized mails found' do | ||
FileUtils.mkdir_p directory | ||
FileUtils.touch("#{directory}/test.not.email") | ||
FileUtils.touch("#{directory}/test.eml") | ||
|
||
expect(instance.check_health.issues.first).to eq 'oversized mails: 1' | ||
end | ||
end | ||
end |