small fixes. when-then-style
This commit is contained in:
parent
80b13f9d3c
commit
29a9205508
2 changed files with 112 additions and 158 deletions
|
@ -37,16 +37,11 @@ class Collector::Dovecot
|
||||||
|
|
||||||
def collect entry, msg
|
def collect entry, msg
|
||||||
case msg
|
case msg
|
||||||
when /\AConnect from /
|
when /\AConnect from / then @connect.increment
|
||||||
@connect.increment
|
when /\ADisconnect from / then @disconnect.increment
|
||||||
when /\ADisconnect from /
|
when /saved mail to / then @saved_mail_to_mailbox.increment labels: {process: @process}
|
||||||
@disconnect.increment
|
when /\Asieve: (.*)/ then @sieve.collect entry, @process, $1
|
||||||
when /saved mail to /
|
else STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} delivery| #{entry.message}"
|
||||||
@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}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -109,7 +104,7 @@ class Collector::Dovecot
|
||||||
case msg
|
case msg
|
||||||
when /\ALogin: user=/
|
when /\ALogin: user=/
|
||||||
@logged_in.increment
|
@logged_in.increment
|
||||||
when /\ADisconnected \((.*?)\): user=</
|
when /\ADisconnected:? \((.*?)\): user=</
|
||||||
case $1
|
case $1
|
||||||
when /\Ano auth attempts/
|
when /\Ano auth attempts/
|
||||||
@disconnected.increment labels: {reason: 'no auth attempts'}
|
@disconnected.increment labels: {reason: 'no auth attempts'}
|
||||||
|
@ -136,36 +131,31 @@ class Collector::Dovecot
|
||||||
def initialize store, prometheus
|
def initialize store, prometheus
|
||||||
@store = store
|
@store = store
|
||||||
@sieve = Sieve.new store, Collector::PrefixProxy.new( prometheus, :sieve)
|
@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
|
@lmtp = Delivery.new store, prometheus, @sieve, @saved_mail_to_mailbox, :lmtp
|
||||||
@deliver = Delivery.new store, prometheus, @sieve, @saved_mail_to_mailbox, :deliver
|
@deliver = Delivery.new store, prometheus, @sieve, @saved_mail_to_mailbox, :deliver
|
||||||
@imap_login = ImapLogin.new store, prometheus
|
@imap_login = ImapLogin.new store, prometheus
|
||||||
@imap = Imap.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
|
end
|
||||||
|
|
||||||
def collect entry
|
def collect entry
|
||||||
# STDERR.puts "dovecot| #{entry.message}"
|
# STDERR.puts "dovecot| #{entry.message}"
|
||||||
case entry.message
|
case entry.message
|
||||||
when /\Aimap-login: (.*)/
|
when /\Aimap-login: (.*)/ then @imap_login.collect entry, $1
|
||||||
@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: (.*)/
|
when /\Aauth: Error: (.*)/
|
||||||
case $1
|
case $1
|
||||||
when /\ALDAP: Connection lost to LDAP server, /
|
when /\ALDAP: Connection lost to LDAP server, /
|
||||||
@auth_ldap_connection_lost.increment
|
@auth_errors.increment labels: {error: "ldap connection lost"}
|
||||||
else
|
else
|
||||||
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}| #{entry.message}"
|
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}| #{entry.message}"
|
||||||
@auth_errors.increment
|
@auth_errors.increment labels: {error: "<any>"}
|
||||||
end
|
end
|
||||||
when /\Aimap\([^)]+\)(?:<[^ ]+>)?: (.*)/
|
else STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}| #{entry.message}"
|
||||||
@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}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,30 +69,30 @@ class Collector::Postfix
|
||||||
@pregreet = prometheus.counter :pregreet_total, docstring: 'A counter of PREGREET to postscreen'
|
@pregreet = prometheus.counter :pregreet_total, docstring: 'A counter of PREGREET to postscreen'
|
||||||
@disconnect = prometheus.counter :disconnect_total, docstring: 'A counter of DISCONNECT 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'
|
@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]
|
@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.'
|
@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'
|
@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'
|
@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'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect entry
|
def collect entry
|
||||||
#STDERR.puts "postscreen: #{entry.message}"
|
#STDERR.puts "postscreen: #{entry.message}"
|
||||||
case entry.message
|
case entry.message
|
||||||
when /\ACONNECT from /
|
when /\ACONNECT from / then @connect_from.increment
|
||||||
@connect_from.increment
|
when /\AWHITELISTED / then @whitelisted.increment
|
||||||
when /\AWHITELISTED /
|
when /\APASS OLD / then @pass_old.increment
|
||||||
@whitelisted.increment
|
when /\APASS NEW / then @pass_new.increment
|
||||||
when /\APASS OLD /
|
when /\ADISCONNECT / then @disconnect.increment
|
||||||
@pass_old.increment
|
when /\APREGREET / then @pregreet.increment
|
||||||
when /\APASS NEW /
|
when /\ABDAT / then @bdat.increment
|
||||||
@pass_new.increment
|
when /\AHANGUP / then @hangup.increment
|
||||||
when /\ADISCONNECT /
|
when /\ADNSBL rank / then @dnsbl.increment
|
||||||
@disconnect.increment
|
when /\ABARE NEWLINE / then @bare_newline.increment
|
||||||
when /\APREGREET /
|
when /\ACOMMAND PIPELINING / then @command_pipelining.increment
|
||||||
@pregreet.increment
|
when /\ACOMMAND TIME LIMIT / then @command_time_limit.increment
|
||||||
when /\ABDAT /
|
when /\ADATA without valid RCPT / then @data_without_valid_rcpt.increment
|
||||||
@bdat.increment
|
when /\Acache / then @cache.collect entry
|
||||||
when /\ANOQUEUE: (.*)/
|
when /\ANOQUEUE: (.*)/
|
||||||
case msg = $1
|
case msg = $1
|
||||||
when /\Areject: RCPT from [^ ]+: 450 4.3.2 Service currently unavailable; /
|
when /\Areject: RCPT from [^ ]+: 450 4.3.2 Service currently unavailable; /
|
||||||
|
@ -100,18 +100,6 @@ class Collector::Postfix
|
||||||
else
|
else
|
||||||
@noqueue.collect entry
|
@noqueue.collect entry
|
||||||
end
|
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: (.*)/
|
when /\Awarning: (.*)/
|
||||||
@warnings.increment
|
@warnings.increment
|
||||||
case $1
|
case $1
|
||||||
|
@ -123,8 +111,6 @@ class Collector::Postfix
|
||||||
else
|
else
|
||||||
STDERR.puts "# postscreen warnings: #{entry.message}"
|
STDERR.puts "# postscreen warnings: #{entry.message}"
|
||||||
end
|
end
|
||||||
when /\Acache /
|
|
||||||
@cache.collect entry
|
|
||||||
else
|
else
|
||||||
STDERR.puts "# postscreen: #{entry.message}"
|
STDERR.puts "# postscreen: #{entry.message}"
|
||||||
@unknown.increment
|
@unknown.increment
|
||||||
|
@ -164,10 +150,8 @@ class Collector::Postfix
|
||||||
case entry.message
|
case entry.message
|
||||||
when /\Aconnect to /
|
when /\Aconnect to /
|
||||||
case entry.message
|
case entry.message
|
||||||
when / Connection refused\z/
|
when / Connection refused\z/ then @connection_refused.increment
|
||||||
@connection_refused.increment
|
when / Connection timed out\z/ then @connection_timed_out.increment
|
||||||
when / Connection timed out\z/
|
|
||||||
@connection_timed_out.increment
|
|
||||||
else
|
else
|
||||||
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} connect to: #{entry.message}"
|
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} connect to: #{entry.message}"
|
||||||
end
|
end
|
||||||
|
@ -178,16 +162,11 @@ class Collector::Postfix
|
||||||
delay, status = $1.to_f, $2.downcase
|
delay, status = $1.to_f, $2.downcase
|
||||||
@status.observe delay, labels: {status: status}
|
@status.observe delay, labels: {status: status}
|
||||||
case status
|
case status
|
||||||
when 'sent'
|
when 'sent' then @sent.increment
|
||||||
@sent.increment
|
when 'deferred' then @deferred.increment
|
||||||
when 'deferred'
|
when 'bounced' then @bounced.increment
|
||||||
@deferred.increment
|
when 'deliverable' then @deliverable.increment
|
||||||
when 'bounced'
|
when 'undeliverable' then @undeliverable.increment
|
||||||
@bounced.increment
|
|
||||||
when 'deliverable'
|
|
||||||
@deliverable.increment
|
|
||||||
when 'undeliverable'
|
|
||||||
@undeliverable.increment
|
|
||||||
else
|
else
|
||||||
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} status: #{entry.message}"
|
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier} status: #{entry.message}"
|
||||||
@status_unknown.increment
|
@status_unknown.increment
|
||||||
|
@ -288,10 +267,8 @@ class Collector::Postfix
|
||||||
|
|
||||||
def collect entry
|
def collect entry
|
||||||
case entry.message
|
case entry.message
|
||||||
when /\ADISCONNECT /
|
when /\ADISCONNECT / then @disconnect.increment
|
||||||
@disconnect.increment
|
when /\ACONNECT / then @connect.increment
|
||||||
when /\ACONNECT /
|
|
||||||
@connect.increment
|
|
||||||
when /\A([^ ]+) TLS connection established from .*: ([^ ]+) with cipher ([^ ]+) /
|
when /\A([^ ]+) TLS connection established from .*: ([^ ]+) with cipher ([^ ]+) /
|
||||||
@tls.increment labels: {trust: $1, tls: $2, cipher: $3}
|
@tls.increment labels: {trust: $1, tls: $2, cipher: $3}
|
||||||
else
|
else
|
||||||
|
@ -358,8 +335,7 @@ class Collector::Postfix
|
||||||
|
|
||||||
def collect entry
|
def collect entry
|
||||||
case entry.message
|
case entry.message
|
||||||
when /\Acache /
|
when /\Acache / then @cache.collect entry
|
||||||
@cache.collect entry
|
|
||||||
else
|
else
|
||||||
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
|
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
|
||||||
end
|
end
|
||||||
|
@ -379,11 +355,11 @@ class Collector::Postfix
|
||||||
@cleanup = prometheus.counter :cleanup_total, docstring: 'A counter of cleanup actions'
|
@cleanup = prometheus.counter :cleanup_total, docstring: 'A counter of cleanup actions'
|
||||||
@lmtp = prometheus.counter :lmtp_total, docstring: 'A counter of ltmp actions'
|
@lmtp = prometheus.counter :lmtp_total, docstring: 'A counter of ltmp actions'
|
||||||
@pickup = prometheus.counter :pickup_total, docstring: 'A counter of pickup 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]
|
@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_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"
|
@anvil_max_cache_size = prometheus.gauge :anvil_max_cache_size, docstring: "Current max cache size"
|
||||||
end
|
end
|
||||||
|
@ -391,38 +367,18 @@ class Collector::Postfix
|
||||||
def collect entry
|
def collect entry
|
||||||
#STDERR.puts "postfix: #{entry.syslog_identifier}: #{entry.message}"
|
#STDERR.puts "postfix: #{entry.syslog_identifier}: #{entry.message}"
|
||||||
case entry.syslog_identifier
|
case entry.syslog_identifier
|
||||||
when 'postfix/tlsproxy/tlsproxy'
|
when 'postfix/tlsproxy', 'postfix/tlsproxy/tlsproxy' then @tlsproxy.collect entry
|
||||||
@tlsproxy.collect entry
|
when 'postfix/postscreen', 'postfix/smtp/postscreen' then @postscreen.collect entry
|
||||||
when 'postfix/smtp/postscreen', 'postfix/smtp/postscreen'
|
when 'postfix/smtp', 'postfix/smtp/smtp' then @smtp.collect entry
|
||||||
@postscreen.collect entry
|
when 'postfix/smtpd', 'postfix/smtpd/smtpd' then @smtpd.collect entry
|
||||||
when 'postfix/smtp', 'postfix/smtp/smtp'
|
when 'postfix/submission/smtpd' then @submission.collect entry
|
||||||
@smtp.collect entry
|
when 'postfix/bounce', 'postfix/bounce/bounce' then @bounce.collect entry
|
||||||
when 'postfix/smtpd', 'postfix/smtpd/smtpd'
|
when 'postifx/verify', 'postfix/verify/verify' then @verify.collect entry
|
||||||
@smtpd.collect entry
|
when 'postfix/cleanup', 'postfix/cleanup/cleanup' then @cleanup.increment
|
||||||
when 'postfix/submission/smtpd'
|
when 'postfix/qmgr', 'postfix/qmgr/qmgr' then @qmgr.increment
|
||||||
@submission.collect entry
|
when 'postfix/lmtp', 'postfix/lmtp/lmtp' then @lmtp.increment
|
||||||
when 'postfix/bounce', 'postfix/bounce/bounce'
|
when 'postfix/pickup', 'postfix/pickup/pickup' then @pickup.increment
|
||||||
@bounce.collect entry
|
when 'postfix/scache', 'postfix/scache/scache' then @scache.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/dnsblog', 'postfix/dnsblog/dnsblog'
|
when 'postfix/dnsblog', 'postfix/dnsblog/dnsblog'
|
||||||
case entry.message
|
case entry.message
|
||||||
when /\Aaddr [^ ]+ listed by domain ([^ ]+) as /
|
when /\Aaddr [^ ]+ listed by domain ([^ ]+) as /
|
||||||
|
@ -441,8 +397,16 @@ class Collector::Postfix
|
||||||
else
|
else
|
||||||
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
|
STDERR.puts "# #{entry._systemd_unit} #{entry.syslog_identifier}: #{entry.message}"
|
||||||
end
|
end
|
||||||
when 'postfix/scache', 'postfix/scache/scache'
|
when 'policyd-spf'
|
||||||
@scache.collect entry
|
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
|
else
|
||||||
STDERR.puts "# #{entry._systemd_unit}: #{entry.syslog_identifier} #{entry.message}"
|
STDERR.puts "# #{entry._systemd_unit}: #{entry.syslog_identifier} #{entry.message}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue