1
1
import requests
2
2
import json
3
+ import time
3
4
from src .utils import get_ip_address
4
5
5
6
def send_test_alert (alertmanager_url , alert_name , severity , instance ):
6
- # Define the alert data
7
+ # Generate a unique alert name by appending the current timestamp
8
+ unique_alert_name = f"{ alert_name } _{ int (time .time ())} "
9
+
10
+ # Define the alert data with the unique alert name
7
11
alert_data = [
8
12
{
9
13
"labels" : {
10
- "alertname" : alert_name ,
14
+ "alertname" : unique_alert_name ,
11
15
"severity" : severity ,
12
16
"instance" : instance
13
17
},
14
18
"annotations" : {
15
- "description" : "This is a test alert" ,
19
+ "description" : f "This is a test alert generated at { time . strftime ( '%Y-%m-%d %H:%M:%S' ) } " ,
16
20
"summary" : "Test alert to check Slack notifications"
17
21
}
18
22
}
@@ -32,7 +36,7 @@ def send_test_alert(alertmanager_url, alert_name, severity, instance):
32
36
33
37
# Check the response
34
38
if response .status_code == 202 :
35
- print ("Test alert sent successfully!" )
39
+ print (f "Test alert ' { unique_alert_name } ' sent successfully!" )
36
40
else :
37
41
print (f"Failed to send alert. Status code: { response .status_code } , Response: { response .text } " )
38
42
@@ -47,5 +51,5 @@ def send_test_alert(alertmanager_url, alert_name, severity, instance):
47
51
alertmanager_port = "9093"
48
52
alertmanager_url = f"http://{ alertmanager_ip } :{ alertmanager_port } "
49
53
50
- # Send a test alert
54
+ # Send a test alert with a unique name
51
55
send_test_alert (alertmanager_url , "ScriptAlert" , "critical" , "instance_name" )
0 commit comments