-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michel Hollands <michel.hollands@gmail.com>
- Loading branch information
1 parent
ff88f3c
commit 7b7d3d4
Showing
350 changed files
with
46,074 additions
and
1 deletion.
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
Binary file not shown.
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,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/alecthomas/kingpin.v2" | ||
|
||
"github.com/prometheus/common/version" | ||
|
||
"github.com/grafana/loki/pkg/tool/commands" | ||
) | ||
|
||
var ( | ||
ruleCommand commands.RuleCommand | ||
) | ||
|
||
func main() { | ||
app := kingpin.New("lokitool", "A command-line tool to manage Loki.") | ||
ruleCommand.Register(app) | ||
|
||
app.Command("version", "Get the version of the lokitool CLI").Action(func(k *kingpin.ParseContext) error { | ||
fmt.Println(version.Print("loki")) | ||
return nil | ||
}) | ||
|
||
kingpin.MustParse(app.Parse(os.Args[1:])) | ||
} |
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
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,76 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const alertmanagerAPIPath = "/api/v1/alerts" | ||
|
||
type configCompat struct { | ||
TemplateFiles map[string]string `yaml:"template_files"` | ||
AlertmanagerConfig string `yaml:"alertmanager_config"` | ||
} | ||
|
||
// CreateAlertmanagerConfig creates a new alertmanager config | ||
func (r *LokiClient) CreateAlertmanagerConfig(ctx context.Context, cfg string, templates map[string]string) error { | ||
payload, err := yaml.Marshal(&configCompat{ | ||
TemplateFiles: templates, | ||
AlertmanagerConfig: cfg, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := r.doRequest(ctx, alertmanagerAPIPath, "POST", payload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res.Body.Close() | ||
|
||
return nil | ||
} | ||
|
||
// DeleteAlermanagerConfig deletes the users alertmanagerconfig | ||
func (r *LokiClient) DeleteAlermanagerConfig(ctx context.Context) error { | ||
res, err := r.doRequest(ctx, alertmanagerAPIPath, "DELETE", nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res.Body.Close() | ||
|
||
return nil | ||
} | ||
|
||
// GetAlertmanagerConfig retrieves a rule group | ||
func (r *LokiClient) GetAlertmanagerConfig(ctx context.Context) (string, map[string]string, error) { | ||
res, err := r.doRequest(ctx, alertmanagerAPIPath, "GET", nil) | ||
if err != nil { | ||
log.Debugln("no alert config present in response") | ||
return "", nil, err | ||
} | ||
|
||
defer res.Body.Close() | ||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
|
||
compat := configCompat{} | ||
err = yaml.Unmarshal(body, &compat) | ||
if err != nil { | ||
log.WithFields(log.Fields{ | ||
"body": string(body), | ||
}).Debugln("failed to unmarshal rule group from response") | ||
|
||
return "", nil, errors.Wrap(err, "unable to unmarshal response") | ||
} | ||
|
||
return compat.AlertmanagerConfig, compat.TemplateFiles, nil | ||
} |
Oops, something went wrong.