elastalert
elastalert copied to clipboard
HTML Within Email Alert
I've tried using the setting "email_format: html" like specified in the documentation but the rule fails to load with the error below.
Feb 20 10:47:44 ELK python3[1424]: ERROR:root:Could not load rule /root/env/elastalert/rules/ids_alert.yaml: Could not parse file /root/env/elastalert/rules/ids_alert.yaml: while scanning a simple key
Feb 20 10:47:44 ELK python3[1424]: in "/root/env/elastalert/rules/ids_alert.yaml", line 33, column 1
Feb 20 10:47:44 ELK python3[1424]: could not find expected ':'
Feb 20 10:47:44 ELK python3[1424]: in "/root/env/elastalert/rules/ids_alert.yaml", line 38, column 52
My Rule.yaml
2 es_port: 12345
3 use_ssl: True
4 es_username: USERNAME
5 es_password: PASSWORD
6 name: IDS_Alert
7 type: frequency
8 index: index-*
9 num_events: 1
10 timeframe:
11 minutes: 15
12
13 use_local_time: true
14 filter:
15 - term:
16 log_type.keyword: "security_event"
17
18 match_enhancements:
19 - "TimeEnhancement"
20 alert:
21 - "email"
22
23 email_format: html
24
25 alert_text_type: alert_text_only
26
27 alert_subject: "IDS Event From {0} Priority: {1}"
28 alert_subject_args:
29 - hostname
30 - priority
31 alert_text: |
32
33 <table>
34 <tr>
35 <th colspan="2"><span style="font-weight:bold">IDS Event from Appliance</span><br><br><span style="font-weight:700"> {0}</span></th>
36 </tr>
37 <tr>
38 <td><span style="font-weight:bold">Appliance IP: </span>{1}</td>
39 <td><span style="font-weight:bold">Time:</span> {2}</td>
40 </tr>
41 <tr>
42 <td><span style="font-weight:bold">Signature:</span> {3}</td>
43 <td><span style="font-weight:bold">Priority:</span> {4}</td>
44 </tr>
45 <tr>
46 <td><span style="font-weight:bold">Src IP:</span> {5}</td>
47 <td><span style="font-weight:bold">Src Port:</span> {6}</td>
48 </tr>
49 <tr>
50 <td colspan="2"><span style="font-weight:bold">Description:</span> {9}</td>
51 </tr>
52 </table>
53
54 email:
55 - "[email protected]"
56
57
58
59 alert_text_args: ["hostname", "host", "@timestamp", "signature", "priority", "src_ip", "src_port", "dst_ip", "dst_port", "alert_msg"]
Apparently indentation for the "alert_text" contents is required. The config below works.
1 es_host: localhost
2 es_port: 12345
3 use_ssl: True
4 es_username: username
5 es_password: password
6 name: IDS_Alert
7 type: frequency
8 index: index-*
9 num_events: 1
10 timeframe:
11 minutes: 15
12
13 use_local_time: true
14 filter:
15 - term:
16 sec_type.keyword: "ids_alerted"
17
18 match_enhancements:
19 - "TimeEnhancement"
20 alert:
21 - "email"
22
23 email_format: html
24
25 alert_text_type: alert_text_only
26
27 alert_subject: "IDS Event From {0} Priority: {1}"
28 alert_subject_args:
29 - hostname
30 - priority
31 alert_text: |
32
33 <p>
34 <br>
35 </p>
36 <table style="width: 42%; margin-right: calc(58%);">
37 <thead>
38 <tr>
39 <th colspan="2" style="background-color: rgb(209, 72, 65);"><strong><span style="color: rgb(239, 239, 239); font-size: 20px;"> IDS Event from Appliance:</span></strong><span style="color: rgb(239, 239, 239);"> <span style="font-size:
40 20px;">{0}</span></span>
41 <br>
42 </th>
43 </tr>
44 </thead>
45 <tbody>
46 <tr>
47 <td style="width: 50%; background-color: rgb(239, 239, 239);"><strong>Appliance IP:</strong> {1}
48 <br>
49 </td>
50 <td style="width: 50%; background-color: rgb(239, 239, 239);"><strong>Time:</strong> {2}
51 <br>
52 </td>
53 </tr>
54 <tr>
55 <td style="width: 50.0583%; background-color: rgb(239, 239, 239);"><strong>Signature</strong><strong>:</strong> {3}
56 <br>
57 </td>
58 <td style="width: 49.9417%; background-color: rgb(239, 239, 239);"><strong>Priority:</strong> {4}
59 <br>
60 </td>
61 </tr>
62 <tr>
63 <td style="width: 50.0583%; background-color: rgb(239, 239, 239);"><strong>Src IP:</strong> {5}
64 <br>
65 </td>
66 <td style="width: 49.9417%; background-color: rgb(239, 239, 239);"><strong>Src Port:</strong> {6}
67 <br>
68 </td>
69 </tr>
70 <tr>
71 <td style="width: 50.0583%; background-color: rgb(239, 239, 239);"><strong>Dst IP:</strong> {7}
72 <br>
73 </td>
74 <td style="width: 49.9417%; background-color: rgb(239, 239, 239);"><strong>Dst Port:</strong> {8}
75 <br>
76 </td>
77 </tr>
78 <tr>
79 <td colspan="2" style="width: 99.8834%; background-color: rgb(239, 239, 239);"><strong>Description:</strong> {9}
80 <br>
81 </td>
82 </tr>
83 </tbody>
84 </table>
85 <p>
86 <br>
87 </p>
88 <p>
89 <br>
90 </p>
91
92 email:
93 - "[email protected]"
94
96 alert_text_args: ["hostname", "host", "@timestamp", "signature", "priority", "src_ip", "src_port", "dst_ip", "dst_port", "alert_msg"]