This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring Promotheus metrics behavior
- Loading branch information
1 parent
5c4aff9
commit c1a9b38
Showing
3 changed files
with
60 additions
and
45 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
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,51 @@ | ||
package metrics | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// Send logs to metrics | ||
func Send(log map[string]string) { | ||
var counter prometheus.Counter | ||
|
||
switch { | ||
case strings.HasPrefix(log["category"], "Common Web Attack"): | ||
counter = getCWA.WithLabelValues( | ||
log["category"], | ||
log["remote_addr"], | ||
log["request_uri"], | ||
log["status"], | ||
) | ||
case strings.HasPrefix(log["category"], "CVE-"): | ||
counter = getCVE.WithLabelValues( | ||
log["category"], | ||
log["remote_addr"], | ||
log["request_uri"], | ||
log["status"], | ||
) | ||
case log["category"] == "Bad Crawler": | ||
counter = getBadCrawler.WithLabelValues( | ||
log["remote_addr"], | ||
log["http_user_agent"], | ||
log["status"], | ||
) | ||
case log["category"] == "Bad IP Address": | ||
counter = getBadIP.WithLabelValues( | ||
log["remote_addr"], | ||
) | ||
case log["category"] == "Bad Referrer": | ||
counter = getBadReferrer.WithLabelValues( | ||
log["http_referer"], | ||
) | ||
case log["category"] == "Directory Bruteforce": | ||
counter = getDirBruteforce.WithLabelValues( | ||
log["remote_addr"], | ||
log["request_uri"], | ||
log["status"], | ||
) | ||
} | ||
|
||
counter.Inc() | ||
} |
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