Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add remove subscriptions command #979

Merged
merged 13 commits into from
Jan 10, 2024
31 changes: 30 additions & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ var (
plotting = flag.Bool("plotting", false, "enable images in all notifications")
)

var (
removeSubscriptions = flag.String("remove-subscriptions", "", "Remove given subscriptions separated by semicolons.")
)

var (
cleanupUsers = flag.Bool("cleanup-users", false, "Disable/delete contacts and subscriptions of missing users")
cleanupLastChecks = flag.Bool("cleanup-last-checks", false, "Delete abandoned triggers last checks.")
Expand Down Expand Up @@ -320,6 +324,31 @@ func main() { //nolint
}
logger.Info().Msg("Dump was pushed")
}

if *removeSubscriptions != "" {
logger.Info().Msg("Start deletion of subscriptions")
subscriptionIDs := strings.Split(*removeSubscriptions, ";")
deleted := 0

logger.Debug().
Interface("subscription_ids", subscriptionIDs).
Msg("Remove subscription IDs")

for _, subscriptionID := range subscriptionIDs {
if err := database.RemoveSubscription(strings.TrimSpace(subscriptionID)); err != nil {
kissken marked this conversation as resolved.
Show resolved Hide resolved
logger.Error().
Error(err).
String("subscription_id", subscriptionID).
Msg("Failed to remove subscription")
continue
}
deleted++
}

logger.Info().
Int("deleted", deleted).
Msg("Deletion of subscriptions finished")
}
}

func GetDumpBriefInfo(dump *dto.TriggerDump) string {
Expand All @@ -334,7 +363,7 @@ func GetDumpBriefInfo(dump *dto.TriggerDump) string {
func initApp() (cleanupConfig, moira.Logger, moira.Database) {
flag.Parse()
if *printVersion {
fmt.Println("Moira - alerting system based on graphite data")
fmt.Println("Moira - alerting system based on graphite or prometheus data")
fmt.Println("Version:", MoiraVersion)
fmt.Println("Git Commit:", GitCommit)
fmt.Println("Go Version:", GoVersion)
Expand Down
Loading