rename deprecated variables and functions

This commit is contained in:
Hector 2021-08-30 16:53:56 +01:00
parent 76c9dd93f4
commit 2ff6d64007

View File

@ -14,8 +14,8 @@ import (
) )
const ( const (
namespace = "fail2ban" deprecatedNamespace = "fail2ban"
sockNamespace = "f2b" namespace = "f2b"
) )
var ( var (
@ -24,64 +24,64 @@ var (
date = "unknown" date = "unknown"
builtBy = "unknown" builtBy = "unknown"
metricUp = prometheus.NewDesc( deprecatedMetricUp = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "up"), prometheus.BuildFQName(deprecatedNamespace, "", "up"),
"(Deprecated) Was the last fail2ban query successful.", "(Deprecated) Was the last fail2ban query successful.",
nil, nil, nil, nil,
) )
metricBannedIpsPerJail = prometheus.NewDesc( deprecatedMetricBannedIpsPerJail = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "banned_ips"), prometheus.BuildFQName(deprecatedNamespace, "", "banned_ips"),
"(Deprecated) Number of banned IPs stored in the database (per jail).", "(Deprecated) Number of banned IPs stored in the database (per jail).",
[]string{"jail"}, nil, []string{"jail"}, nil,
) )
metricBadIpsPerJail = prometheus.NewDesc( deprecatedMetricBadIpsPerJail = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "bad_ips"), prometheus.BuildFQName(deprecatedNamespace, "", "bad_ips"),
"(Deprecated) Number of bad IPs stored in the database (per jail).", "(Deprecated) Number of bad IPs stored in the database (per jail).",
[]string{"jail"}, nil, []string{"jail"}, nil,
) )
metricEnabledJails = prometheus.NewDesc( deprecatedMetricEnabledJails = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "enabled_jails"), prometheus.BuildFQName(deprecatedNamespace, "", "enabled_jails"),
"(Deprecated) Enabled jails.", "(Deprecated) Enabled jails.",
[]string{"jail"}, nil, []string{"jail"}, nil,
) )
metricErrorCount = prometheus.NewDesc( deprecatedMetricErrorCount = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "errors"), prometheus.BuildFQName(deprecatedNamespace, "", "errors"),
"(Deprecated) Number of errors found since startup.", "(Deprecated) Number of errors found since startup.",
[]string{"type"}, nil, []string{"type"}, nil,
) )
metricErrorCountNew = prometheus.NewDesc( metricErrorCount = prometheus.NewDesc(
prometheus.BuildFQName(sockNamespace, "", "errors"), prometheus.BuildFQName(namespace, "", "errors"),
"Number of errors found since startup", "Number of errors found since startup",
[]string{"type"}, nil, []string{"type"}, nil,
) )
metricServerUp = prometheus.NewDesc( metricServerUp = prometheus.NewDesc(
prometheus.BuildFQName(sockNamespace, "", "up"), prometheus.BuildFQName(namespace, "", "up"),
"Check if the fail2ban server is up", "Check if the fail2ban server is up",
nil, nil, nil, nil,
) )
metricJailCount = prometheus.NewDesc( metricJailCount = prometheus.NewDesc(
prometheus.BuildFQName(sockNamespace, "", "jail_count"), prometheus.BuildFQName(namespace, "", "jail_count"),
"Number of defined jails", "Number of defined jails",
nil, nil, nil, nil,
) )
metricJailFailedCurrent = prometheus.NewDesc( metricJailFailedCurrent = prometheus.NewDesc(
prometheus.BuildFQName(sockNamespace, "", "jail_failed_current"), prometheus.BuildFQName(namespace, "", "jail_failed_current"),
"Number of current failures on this jail's filter", "Number of current failures on this jail's filter",
[]string{"jail"}, nil, []string{"jail"}, nil,
) )
metricJailFailedTotal = prometheus.NewDesc( metricJailFailedTotal = prometheus.NewDesc(
prometheus.BuildFQName(sockNamespace, "", "jail_failed_total"), prometheus.BuildFQName(namespace, "", "jail_failed_total"),
"Number of total failures on this jail's filter", "Number of total failures on this jail's filter",
[]string{"jail"}, nil, []string{"jail"}, nil,
) )
metricJailBannedCurrent = prometheus.NewDesc( metricJailBannedCurrent = prometheus.NewDesc(
prometheus.BuildFQName(sockNamespace, "", "jail_banned_current"), prometheus.BuildFQName(namespace, "", "jail_banned_current"),
"Number of IPs currently banned in this jail", "Number of IPs currently banned in this jail",
[]string{"jail"}, nil, []string{"jail"}, nil,
) )
metricJailBannedTotal = prometheus.NewDesc( metricJailBannedTotal = prometheus.NewDesc(
prometheus.BuildFQName(sockNamespace, "", "jail_banned_total"), prometheus.BuildFQName(namespace, "", "jail_banned_total"),
"Total number of IPs banned by this jail (includes expired bans)", "Total number of IPs banned by this jail (includes expired bans)",
[]string{"jail"}, nil, []string{"jail"}, nil,
) )
@ -98,11 +98,11 @@ type Exporter struct {
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
if e.db != nil { if e.db != nil {
ch <- metricUp ch <- deprecatedMetricUp
ch <- metricBadIpsPerJail ch <- deprecatedMetricBadIpsPerJail
ch <- metricBannedIpsPerJail ch <- deprecatedMetricBannedIpsPerJail
ch <- metricEnabledJails ch <- deprecatedMetricEnabledJails
ch <- metricErrorCount ch <- deprecatedMetricErrorCount
} }
if e.socketPath != "" { if e.socketPath != "" {
ch <- metricServerUp ch <- metricServerUp
@ -112,7 +112,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- metricJailBannedCurrent ch <- metricJailBannedCurrent
ch <- metricJailBannedTotal ch <- metricJailBannedTotal
} }
ch <- metricErrorCountNew ch <- metricErrorCount
} }
func (e *Exporter) Collect(ch chan<- prometheus.Metric) { func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
@ -145,13 +145,13 @@ func (e *Exporter) collectUpMetric(ch chan<- prometheus.Metric) {
upMetricValue = 0 upMetricValue = 0
} }
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
metricUp, prometheus.GaugeValue, upMetricValue, deprecatedMetricUp, prometheus.GaugeValue, upMetricValue,
) )
} }
func (e *Exporter) collectErrorCountMetric(ch chan<- prometheus.Metric) { func (e *Exporter) collectErrorCountMetric(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
metricErrorCount, prometheus.CounterValue, float64(e.dbErrorCount), "db", deprecatedMetricErrorCount, prometheus.CounterValue, float64(e.dbErrorCount), "db",
) )
} }
@ -166,7 +166,7 @@ func (e *Exporter) collectBadIpsPerJailMetrics(ch chan<- prometheus.Metric) {
for jailName, count := range jailNameToCountMap { for jailName, count := range jailNameToCountMap {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
metricBadIpsPerJail, prometheus.GaugeValue, float64(count), jailName, deprecatedMetricBadIpsPerJail, prometheus.GaugeValue, float64(count), jailName,
) )
} }
} }
@ -182,7 +182,7 @@ func (e *Exporter) collectBannedIpsPerJailMetrics(ch chan<- prometheus.Metric) {
for jailName, count := range jailNameToCountMap { for jailName, count := range jailNameToCountMap {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
metricBannedIpsPerJail, prometheus.GaugeValue, float64(count), jailName, deprecatedMetricBannedIpsPerJail, prometheus.GaugeValue, float64(count), jailName,
) )
} }
} }
@ -198,14 +198,14 @@ func (e *Exporter) collectEnabledJailMetrics(ch chan<- prometheus.Metric) {
for jailName, count := range jailNameToEnabledMap { for jailName, count := range jailNameToEnabledMap {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
metricEnabledJails, prometheus.GaugeValue, float64(count), jailName, deprecatedMetricEnabledJails, prometheus.GaugeValue, float64(count), jailName,
) )
} }
} }
func (e *Exporter) collectErrorCountMetricNew(ch chan<- prometheus.Metric) { func (e *Exporter) collectErrorCountMetricNew(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
metricErrorCountNew, prometheus.CounterValue, float64(e.dbErrorCount), "db", metricErrorCount, prometheus.CounterValue, float64(e.dbErrorCount), "db",
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
metricErrorCountNew, prometheus.CounterValue, float64(e.socketConnectionErrorCount), "socket_conn", metricErrorCountNew, prometheus.CounterValue, float64(e.socketConnectionErrorCount), "socket_conn",