Skip to content

Commit

Permalink
Merge pull request #1 from AppDirect/master
Browse files Browse the repository at this point in the history
add proper licence + address labelname specification
  • Loading branch information
nzin authored Jul 7, 2018
2 parents 659ecd8 + c3b7d45 commit ac7c470
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
41 changes: 41 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
def now = new Date()
env.DATE = now.format("yyyyMMdd_HHmmss")

pipeline {
agent any
stages {
stage('Checkout project...') {
steps {
checkout scm
}
}

stage('Define Version') {
steps {
script {
version = "1.0.1"
}
}
}

stage('Building...') {
steps {
ansiColor('xterm') {
sh 'docker build --no-cache .'
}
}
}
stage('Publishing Docker Image...') {
when {
expression {
env.BRANCH_NAME == 'master'
}
}
steps {
dockerBuilder "${env.WORKSPACE}", "prometheus-cachethq", version
}
}
}
}


9 changes: 9 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Copyright 2018 Nicolas Zin <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You have to configure the Prometheus Alert Manager something like:
If you have a CachetHQ and a Prometheus running on your local machine

go build .
./prometheus-cachethq -prometheus_token _prometheus_bearer_token_ -cachethq_token _token_
./prometheus-cachethq -prometheus_token _prometheus_bearer_token_ -cachethq_token _token_ -label_name alertname

# to test, you can send by hand an alert to the Prometheus Alert Manager
curl -H "Content-Type: application/json" -d '[{"labels":{"alertname":"component21"}}]' localhost:9093/api/v1/alerts
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type PrometheusCachetConfig struct {
PrometheusToken string
CachetURL string
CachetToken string
LabelName string
LogLevel int
}

Expand All @@ -34,6 +35,7 @@ func main() {
flag.StringVar(&loglevel, "log_level", "info", "log level: [info|debug]")
flag.StringVar(&sslCert, "ssl_cert_file", "", "to be used with ssl_key: enable https server")
flag.StringVar(&sslKey, "ssl_key_file", "", "to be used with ssl_cert: enable https server")
flag.StringVar(&config.LabelName, "label_name", "alertname", "label to look for in Prometheus Alert info")
flag.IntVar(&httpPort, "http_port", 8080, "port to listen on")

flag.Parse()
Expand Down Expand Up @@ -63,6 +65,10 @@ func main() {
sslKey = os.Getenv("SSL_KEY_FILE")
}

if os.Getenv("LABEL_NAME") != "" {
config.LabelName = os.Getenv("LABEL_NAME")
}

config.LogLevel = LOG_INFO
if loglevel == "debug" {
config.LogLevel = LOG_DEBUG
Expand Down
2 changes: 2 additions & 0 deletions minikube/cachethq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ spec:
value: "http://localhost:8000"
- name: CACHETHQ_TOKEN
value: "GswCqve7hl9CZKBPDQQr"
- name: LABEL_NAME
value: "alertname"
- name: cachethq
image: cachethq/docker:2.3-latest
ports:
Expand Down
2 changes: 1 addition & 1 deletion webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func SubmitAlert(c *gin.Context, config *PrometheusCachetConfig) {
}
for _, alert := range alerts.Alerts {
// fire something
if componentID, ok := list[alert.Labels["alertname"]]; ok {
if componentID, ok := list[alert.Labels[config.LabelName]]; ok {
if err := cachetAlert(componentID, status, config.CachetURL, config.CachetToken); err != nil {
if config.LogLevel == LOG_DEBUG {
log.Println(err)
Expand Down

0 comments on commit ac7c470

Please sign in to comment.