feat: default list_alerts to active alerts only

Change list_alerts (MCP tool) and alerts (CLI command) to show only
active (non-silenced, non-inhibited) alerts by default. Add state=all
option and --all CLI flag to show all alerts when needed.

- MCP: list_alerts with no state param now returns active alerts only
- MCP: list_alerts with state=all returns all alerts (previous default)
- CLI: alerts command defaults to active, --all shows everything
- Add tests for new default behavior and state=all option
- Update README with new CLI examples
- Bump version to 0.3.0
- Clarify version bumping rules in CLAUDE.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 19:59:37 +01:00
parent 9dfe61e170
commit 9b16a5fe86
10 changed files with 158 additions and 55 deletions

View File

@@ -20,7 +20,7 @@ import (
const (
defaultDatabase = "sqlite://hm-options.db"
version = "0.2.1"
version = "0.3.0"
)
func main() {

View File

@@ -15,7 +15,7 @@ import (
"git.t-juice.club/torjus/labmcp/internal/monitoring"
)
const version = "0.2.0"
const version = "0.3.0"
func main() {
app := &cli.App{
@@ -113,12 +113,16 @@ func alertsCommand() *cli.Command {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "state",
Usage: "Filter by state: active, suppressed, unprocessed",
Usage: "Filter by state: active (default), suppressed, unprocessed, all",
},
&cli.StringFlag{
Name: "severity",
Usage: "Filter by severity label",
},
&cli.BoolFlag{
Name: "all",
Usage: "Show all alerts including silenced and inhibited (shorthand for --state all)",
},
},
Action: func(c *cli.Context) error {
return runAlerts(c)
@@ -226,23 +230,32 @@ func runAlerts(c *cli.Context) error {
am := monitoring.NewAlertmanagerClient(c.String("alertmanager-url"))
filters := monitoring.AlertFilters{}
if state := c.String("state"); state != "" {
switch state {
case "active":
active := true
filters.Active = &active
silenced := false
filters.Silenced = &silenced
inhibited := false
filters.Inhibited = &inhibited
case "suppressed":
active := false
filters.Active = &active
case "unprocessed":
unprocessed := true
filters.Unprocessed = &unprocessed
}
// Determine state filter: --all flag takes precedence, then --state, then default to active
state := c.String("state")
if c.Bool("all") {
state = "all"
}
switch state {
case "active", "":
// Default to active alerts only (non-silenced, non-inhibited)
active := true
filters.Active = &active
silenced := false
filters.Silenced = &silenced
inhibited := false
filters.Inhibited = &inhibited
case "suppressed":
active := false
filters.Active = &active
case "unprocessed":
unprocessed := true
filters.Unprocessed = &unprocessed
case "all":
// No filters - return everything
}
if severity := c.String("severity"); severity != "" {
filters.Filter = append(filters.Filter, fmt.Sprintf(`severity="%s"`, severity))
}

View File

@@ -19,7 +19,7 @@ import (
const (
defaultDatabase = "sqlite://nixos-options.db"
version = "0.2.1"
version = "0.3.0"
)
func main() {

View File

@@ -20,7 +20,7 @@ import (
const (
defaultDatabase = "sqlite://nixpkgs-search.db"
version = "0.2.1"
version = "0.3.0"
)
func main() {