small fixes. when-then-style

master
Denis Knauf 2022-05-23 14:17:11 +02:00
parent 80b13f9d3c
commit 29a9205508
2 changed files with 112 additions and 158 deletions

View File

@ -37,16 +37,11 @@ class Collector::Dovecot
def collect entry, msg
case msg
when /\AConnect from /
@connect.increment
when /\ADisconnect from /
@disconnect.increment
when /saved mail to /
@saved_mail_to_mailbox.increment labels: {process: @process}
when /\Asieve: (.*)/
@sieve.collect entry, @process, $1
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} delivery| #{entry.message}"
when /\AConnect from / then @connect.increment
when /\ADisconnect from / then @disconnect.increment
when /saved mail to / then @saved_mail_to_mailbox.increment labels: {process: @process}
when /\Asieve: (.*)/ then @sieve.collect entry, @process, $1
else STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} delivery| #{entry.message}"
end
end
end
@ -109,7 +104,7 @@ class Collector::Dovecot
case msg
when /\ALogin: user=/
@logged_in.increment
when /\ADisconnected \((.*?)\): user=</
when /\ADisconnected:? \((.*?)\): user=</
case $1
when /\Ano auth attempts/
@disconnected.increment labels: {reason: 'no auth attempts'}
@ -136,36 +131,31 @@ class Collector::Dovecot
def initialize store, prometheus
@store = store
@sieve = Sieve.new store, Collector::PrefixProxy.new( prometheus, :sieve)
@saved_mail_to_mailbox = prometheus.counter :saved_mail_to_mailbox_total, docstring: "A counter of saved mails to mailbox directly", labels: %i[process]
@lmtp = Delivery.new store, prometheus, @sieve, @saved_mail_to_mailbox, :lmtp
@deliver = Delivery.new store, prometheus, @sieve, @saved_mail_to_mailbox, :deliver
@imap_login = ImapLogin.new store, prometheus
@imap = Imap.new store, prometheus
@saved_mail_to_mailbox = prometheus.counter :saved_mail_to_mailbox_total, docstring: "A counter of saved mails to mailbox directly", labels: %i[process]
@auth_errors = prometheus.counter :auth_errors_total, docstring: "A counter of dovecot auth errors by type.", labels: %i[error]
end
def collect entry
# STDERR.puts "dovecot| #{entry.message}"
case entry.message
when /\Aimap-login: (.*)/
@imap_login.collect entry, $1
when /\Aimap-login: (.*)/ then @imap_login.collect entry, $1
when /\Aimap\([^)]+\)(?:<[^ ]+>)?: (.*)/ then @imap.collect entry, $1
when /\Almtp\([^ ]+\)<[^ ]+>: (.*)/ then @lmtp.collect entry, $1
when /\Almtp\([^ ]+\): (.*)/ then @lmtp.collect entry, $1
when /\Adeliver(?:[^:]+): (.*)/ then @deliver.collect entry, $1
when /\Aauth: Error: (.*)/
case $1
when /\ALDAP: Connection lost to LDAP server, /
@auth_ldap_connection_lost.increment
@auth_errors.increment labels: {error: "ldap connection lost"}
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}| #{entry.message}"
@auth_errors.increment
@auth_errors.increment labels: {error: "<any>"}
end
when /\Aimap\([^)]+\)(?:<[^ ]+>)?: (.*)/
@imap.collect entry, $1
when /\Almtp\([^ ]+\)<[^ ]+>: (.*)/
@lmtp.collect entry, $1
when /\Almtp\([^ ]+\): (.*)/
@lmtp.collect entry, $1
when /\Adeliver(?:[^:]+): (.*)/
@deliver.collect entry, $1
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}| #{entry.message}"
else STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}| #{entry.message}"
end
end
end

View File

@ -69,30 +69,30 @@ class Collector::Postfix
@pregreet = prometheus.counter :pregreet_total, docstring: 'A counter of PREGREET to postscreen'
@disconnect = prometheus.counter :disconnect_total, docstring: 'A counter of DISCONNECT to postscreen'
@unknown = prometheus.counter :unknown_total, docstring: 'A counter of unknown loglines by postscreen'
@warnings = prometheus.counter :warnings_total, docstring: 'A counter of any warnings'
@psc_cache_update_delay = prometheus.summary :psc_cache_update_delay_total, docstring: 'A counter of PSC cache update delays by file', labels: %i[file]
@curr_unavailable = prometheus.counter :service_currently_unavailable_total, docstring: 'A counter for rejected mails, because service currently unavailable - so greylisted.'
@dnsblog_reply_timeout = prometheus.counter :dnsblog_reply_timeout_total, docstring: 'Total timedout requests for dnsblog'
@data_without_valid_rcpt= prometheus.counter :data_without_valid_rcpt_total, docstring: 'A counter of DATA without valid RCPT events'
@warnings = prometheus.counter :warnings_total, docstring: 'A counter of any warnings'
@data_without_valid_rcpt = prometheus.counter :data_without_valid_rcpt_total, docstring: 'A counter of DATA without valid RCPT events'
end
def collect entry
#STDERR.puts "postscreen: #{entry.message}"
case entry.message
when /\ACONNECT from /
@connect_from.increment
when /\AWHITELISTED /
@whitelisted.increment
when /\APASS OLD /
@pass_old.increment
when /\APASS NEW /
@pass_new.increment
when /\ADISCONNECT /
@disconnect.increment
when /\APREGREET /
@pregreet.increment
when /\ABDAT /
@bdat.increment
when /\ACONNECT from / then @connect_from.increment
when /\AWHITELISTED / then @whitelisted.increment
when /\APASS OLD / then @pass_old.increment
when /\APASS NEW / then @pass_new.increment
when /\ADISCONNECT / then @disconnect.increment
when /\APREGREET / then @pregreet.increment
when /\ABDAT / then @bdat.increment
when /\AHANGUP / then @hangup.increment
when /\ADNSBL rank / then @dnsbl.increment
when /\ABARE NEWLINE / then @bare_newline.increment
when /\ACOMMAND PIPELINING / then @command_pipelining.increment
when /\ACOMMAND TIME LIMIT / then @command_time_limit.increment
when /\ADATA without valid RCPT / then @data_without_valid_rcpt.increment
when /\Acache / then @cache.collect entry
when /\ANOQUEUE: (.*)/
case msg = $1
when /\Areject: RCPT from [^ ]+: 450 4.3.2 Service currently unavailable; /
@ -100,18 +100,6 @@ class Collector::Postfix
else
@noqueue.collect entry
end
when /\AHANGUP /
@hangup.increment
when /\ADNSBL rank /
@dnsbl.increment
when /\ABARE NEWLINE /
@bare_newline.increment
when /\ACOMMAND PIPELINING /
@command_pipelining.increment
when /\ACOMMAND TIME LIMIT /
@command_time_limit.increment
when /\ADATA without valid RCPT /
@data_without_valid_rcpt.increment
when /\Awarning: (.*)/
@warnings.increment
case $1
@ -123,8 +111,6 @@ class Collector::Postfix
else
STDERR.puts "# postscreen warnings: #{entry.message}"
end
when /\Acache /
@cache.collect entry
else
STDERR.puts "# postscreen: #{entry.message}"
@unknown.increment
@ -164,10 +150,8 @@ class Collector::Postfix
case entry.message
when /\Aconnect to /
case entry.message
when / Connection refused\z/
@connection_refused.increment
when / Connection timed out\z/
@connection_timed_out.increment
when / Connection refused\z/ then @connection_refused.increment
when / Connection timed out\z/ then @connection_timed_out.increment
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} connect to: #{entry.message}"
end
@ -178,16 +162,11 @@ class Collector::Postfix
delay, status = $1.to_f, $2.downcase
@status.observe delay, labels: {status: status}
case status
when 'sent'
@sent.increment
when 'deferred'
@deferred.increment
when 'bounced'
@bounced.increment
when 'deliverable'
@deliverable.increment
when 'undeliverable'
@undeliverable.increment
when 'sent' then @sent.increment
when 'deferred' then @deferred.increment
when 'bounced' then @bounced.increment
when 'deliverable' then @deliverable.increment
when 'undeliverable' then @undeliverable.increment
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} status: #{entry.message}"
@status_unknown.increment
@ -288,10 +267,8 @@ class Collector::Postfix
def collect entry
case entry.message
when /\ADISCONNECT /
@disconnect.increment
when /\ACONNECT /
@connect.increment
when /\ADISCONNECT / then @disconnect.increment
when /\ACONNECT / then @connect.increment
when /\A([^ ]+) TLS connection established from .*: ([^ ]+) with cipher ([^ ]+) /
@tls.increment labels: {trust: $1, tls: $2, cipher: $3}
else
@ -358,8 +335,7 @@ class Collector::Postfix
def collect entry
case entry.message
when /\Acache /
@cache.collect entry
when /\Acache / then @cache.collect entry
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
end
@ -379,11 +355,11 @@ class Collector::Postfix
@cleanup = prometheus.counter :cleanup_total, docstring: 'A counter of cleanup actions'
@lmtp = prometheus.counter :lmtp_total, docstring: 'A counter of ltmp actions'
@pickup = prometheus.counter :pickup_total, docstring: 'A counter of pickup actions'
@spf = prometheus.counter :spf_total, docstring: 'A counter of prepended SPF header-lines with state', labels: %i[status]
@spf_fail = prometheus.counter :spf_fail_total, docstring: 'A counter of policyd-SPF failed SPF'
%w[pass none].each {|s| @spf.increment by: 0, labels: {status: s} }
@dnsblog = prometheus.counter :dnsblog_total, docstring: 'A counter for DNS-Blacklisted IP by DNSBL', labels: %i[dnsbl]
@anvil_max_connection_rate_per_minute = prometheus.gauge :anvil_max_connection_per_minute_tate, docstring: "Rate of max connections per minute to listener", labels: %i{listener}
@spf_fail = prometheus.counter :spf_fail_total, docstring: 'A counter of policyd-SPF failed SPF'
@spf = prometheus.counter :spf_total, docstring: 'A counter of prepended SPF header-lines with state', labels: %i[status]
%w[pass none].each {|s| @spf.increment by: 0, labels: {status: s} }
@anvil_max_connection_rate_per_minute = prometheus.gauge :anvil_max_connection_per_minute_rate, docstring: "Rate of max connections per minute to listener", labels: %i{listener}
@anvil_max_connection_count = prometheus.gauge :anvil_max_connection_count, docstring: "Count of max connections to listener", labels: %i{listener}
@anvil_max_cache_size = prometheus.gauge :anvil_max_cache_size, docstring: "Current max cache size"
end
@ -391,38 +367,18 @@ class Collector::Postfix
def collect entry
#STDERR.puts "postfix: #{entry.syslog_identifier}: #{entry.message}"
case entry.syslog_identifier
when 'postfix/tlsproxy/tlsproxy'
@tlsproxy.collect entry
when 'postfix/smtp/postscreen', 'postfix/smtp/postscreen'
@postscreen.collect entry
when 'postfix/smtp', 'postfix/smtp/smtp'
@smtp.collect entry
when 'postfix/smtpd', 'postfix/smtpd/smtpd'
@smtpd.collect entry
when 'postfix/submission/smtpd'
@submission.collect entry
when 'postfix/bounce', 'postfix/bounce/bounce'
@bounce.collect entry
when 'postifx/verify', 'postfix/verify/verify'
@verify.collect entry
when 'policyd-spf'
case entry.message
when /\Aprepend Received-SPF: (\w+) /
@spf.increment labels: {status: $1.downcase}
when /\A[^ ]+ [^ ]+ Message rejected due to: SPF fail /
# postfix@-.service policyd-spf: 550 5.7.23 Message rejected due to: SPF fail - not authorized.
@spf_fail.increment
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
end
when 'postfix/cleanup', 'postfix/cleanup/cleanup'
@cleanup.increment
when 'postfix/qmgr', 'postfix/qmgr/qmgr'
@qmgr.increment
when 'postfix/lmtp', 'postfix/lmtp/lmtp'
@lmtp.increment
when 'postfix/pickup', 'postfix/pickup/pickup'
@pickup.increment
when 'postfix/tlsproxy', 'postfix/tlsproxy/tlsproxy' then @tlsproxy.collect entry
when 'postfix/postscreen', 'postfix/smtp/postscreen' then @postscreen.collect entry
when 'postfix/smtp', 'postfix/smtp/smtp' then @smtp.collect entry
when 'postfix/smtpd', 'postfix/smtpd/smtpd' then @smtpd.collect entry
when 'postfix/submission/smtpd' then @submission.collect entry
when 'postfix/bounce', 'postfix/bounce/bounce' then @bounce.collect entry
when 'postifx/verify', 'postfix/verify/verify' then @verify.collect entry
when 'postfix/cleanup', 'postfix/cleanup/cleanup' then @cleanup.increment
when 'postfix/qmgr', 'postfix/qmgr/qmgr' then @qmgr.increment
when 'postfix/lmtp', 'postfix/lmtp/lmtp' then @lmtp.increment
when 'postfix/pickup', 'postfix/pickup/pickup' then @pickup.increment
when 'postfix/scache', 'postfix/scache/scache' then @scache.collect entry
when 'postfix/dnsblog', 'postfix/dnsblog/dnsblog'
case entry.message
when /\Aaddr [^ ]+ listed by domain ([^ ]+) as /
@ -441,8 +397,16 @@ class Collector::Postfix
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
end
when 'postfix/scache', 'postfix/scache/scache'
@scache.collect entry
when 'policyd-spf'
case entry.message
when /\Aprepend Received-SPF: (\w+) /
@spf.increment labels: {status: $1.downcase}
when /\A[^ ]+ [^ ]+ Message rejected due to: SPF fail /
# postfix@-.service policyd-spf: 550 5.7.23 Message rejected due to: SPF fail - not authorized.
@spf_fail.increment
else
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
end
else
STDERR.puts "# #{entry._systemd_unit}: #{entry.syslog_identifier} #{entry.message}"
end