@@ -293,7 +293,9 @@ def handle_alert_failure(
293
293
from agents .models import Agent , AgentHistory
294
294
from autotasks .models import TaskResult
295
295
from checks .models import CheckResult
296
+ from core .models import CoreSettings
296
297
298
+ core = CoreSettings .objects .first ()
297
299
# set variables
298
300
dashboard_severities = None
299
301
email_severities = None
@@ -443,12 +445,23 @@ def handle_alert_failure(
443
445
alert .hidden = False
444
446
alert .save (update_fields = ["hidden" ])
445
447
448
+ # TODO rework this
449
+ if alert .severity == AlertSeverity .INFO and not core .notify_on_info_alerts :
450
+ email_alert = False
451
+ always_email = False
452
+
453
+ elif (
454
+ alert .severity == AlertSeverity .WARNING
455
+ and not core .notify_on_warning_alerts
456
+ ):
457
+ email_alert = False
458
+ always_email = False
459
+
446
460
# send email if enabled
447
461
if email_alert or always_email :
448
462
# check if alert template is set and specific severities are configured
449
- if (
450
- not alert_template
451
- or alert_template
463
+ if not alert_template or (
464
+ alert_template
452
465
and email_severities
453
466
and alert .severity in email_severities
454
467
):
@@ -457,14 +470,22 @@ def handle_alert_failure(
457
470
alert_interval = alert_interval ,
458
471
)
459
472
473
+ # TODO rework this
474
+ if alert .severity == AlertSeverity .INFO and not core .notify_on_info_alerts :
475
+ text_alert = False
476
+ always_text = False
477
+ elif (
478
+ alert .severity == AlertSeverity .WARNING
479
+ and not core .notify_on_warning_alerts
480
+ ):
481
+ text_alert = False
482
+ always_text = False
483
+
460
484
# send text if enabled
461
485
if text_alert or always_text :
462
486
# check if alert template is set and specific severities are configured
463
- if (
464
- not alert_template
465
- or alert_template
466
- and text_severities
467
- and alert .severity in text_severities
487
+ if not alert_template or (
488
+ alert_template and text_severities and alert .severity in text_severities
468
489
):
469
490
text_task .delay (pk = alert .pk , alert_interval = alert_interval )
470
491
@@ -513,17 +534,25 @@ def handle_alert_failure(
513
534
}
514
535
515
536
elif alert_template .action_type == AlertTemplateActionType .REST :
516
- output , status = run_url_rest_action (
517
- action_id = alert_template .action_rest .id , instance = alert
518
- )
519
- logger .debug (f"{ output = } { status = } " )
520
-
521
- r = {
522
- "stdout" : output ,
523
- "stderr" : "" ,
524
- "execution_time" : 0 ,
525
- "retcode" : status ,
526
- }
537
+ if (
538
+ alert .severity == AlertSeverity .INFO
539
+ and not core .notify_on_info_alerts
540
+ or alert .severity == AlertSeverity .WARNING
541
+ and not core .notify_on_warning_alerts
542
+ ):
543
+ return
544
+ else :
545
+ output , status = run_url_rest_action (
546
+ action_id = alert_template .action_rest .id , instance = alert
547
+ )
548
+ logger .debug (f"{ output = } { status = } " )
549
+
550
+ r = {
551
+ "stdout" : output ,
552
+ "stderr" : "" ,
553
+ "execution_time" : 0 ,
554
+ "retcode" : status ,
555
+ }
527
556
else :
528
557
return
529
558
@@ -555,6 +584,9 @@ def handle_alert_resolve(
555
584
from agents .models import Agent , AgentHistory
556
585
from autotasks .models import TaskResult
557
586
from checks .models import CheckResult
587
+ from core .models import CoreSettings
588
+
589
+ core = CoreSettings .objects .first ()
558
590
559
591
# set variables
560
592
email_on_resolved = False
@@ -633,11 +665,29 @@ def handle_alert_resolve(
633
665
634
666
# check if a resolved email notification should be send
635
667
if email_on_resolved and not alert .resolved_email_sent :
636
- resolved_email_task .delay (pk = alert .pk )
668
+ if alert .severity == AlertSeverity .INFO and not core .notify_on_info_alerts :
669
+ pass
670
+
671
+ elif (
672
+ alert .severity == AlertSeverity .WARNING
673
+ and not core .notify_on_warning_alerts
674
+ ):
675
+ pass
676
+ else :
677
+ resolved_email_task .delay (pk = alert .pk )
637
678
638
679
# check if resolved text should be sent
639
680
if text_on_resolved and not alert .resolved_sms_sent :
640
- resolved_text_task .delay (pk = alert .pk )
681
+ if alert .severity == AlertSeverity .INFO and not core .notify_on_info_alerts :
682
+ pass
683
+
684
+ elif (
685
+ alert .severity == AlertSeverity .WARNING
686
+ and not core .notify_on_warning_alerts
687
+ ):
688
+ pass
689
+ else :
690
+ resolved_text_task .delay (pk = alert .pk )
641
691
642
692
# check if resolved script/webhook should be run
643
693
if alert_template and not alert .resolved_action_run :
@@ -685,17 +735,25 @@ def handle_alert_resolve(
685
735
}
686
736
687
737
elif alert_template .action_type == AlertTemplateActionType .REST :
688
- output , status = run_url_rest_action (
689
- action_id = alert_template .resolved_action_rest .id , instance = alert
690
- )
691
- logger .debug (f"{ output = } { status = } " )
692
-
693
- r = {
694
- "stdout" : output ,
695
- "stderr" : "" ,
696
- "execution_time" : 0 ,
697
- "retcode" : status ,
698
- }
738
+ if (
739
+ alert .severity == AlertSeverity .INFO
740
+ and not core .notify_on_info_alerts
741
+ or alert .severity == AlertSeverity .WARNING
742
+ and not core .notify_on_warning_alerts
743
+ ):
744
+ return
745
+ else :
746
+ output , status = run_url_rest_action (
747
+ action_id = alert_template .resolved_action_rest .id , instance = alert
748
+ )
749
+ logger .debug (f"{ output = } { status = } " )
750
+
751
+ r = {
752
+ "stdout" : output ,
753
+ "stderr" : "" ,
754
+ "execution_time" : 0 ,
755
+ "retcode" : status ,
756
+ }
699
757
else :
700
758
return
701
759
0 commit comments