Skip to content

Commit

Permalink
[ENHANCEMENT] Add dryrun to alerts-index command #249
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Mar 2, 2020
2 parents 4686a90 + 44beca3 commit 95760fd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion promgen/management/commands/alerts-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@


class Command(BaseCommand):
def handle(self, **kargs):
def add_arguments(self, parser):
parser.add_argument(
"--force",
dest="dryrun",
action="store_false",
help="Defaults to dry run. Use to execute operation",
)

def handle(self, dryrun, **kargs):
for alert in models.Alert.objects.filter(alertlabel__isnull=True):
if dryrun:
labels = alert.json.get("commonLabels")
self.stderr.write("alert_id: %s, labels: %s" % (alert.pk, labels))
continue

tasks.index_alert.delay(alert.pk)
time.sleep(0.1)

0 comments on commit 95760fd

Please sign in to comment.