@@ -23,42 +23,78 @@ jobs:
23
23
run : gcc -o suricata-notify suricata-notify.c -ljansson
24
24
25
25
- name : Upload Build Artifact
26
- uses : actions/upload-artifact@v3
26
+ uses : actions/upload-artifact@v4
27
27
with :
28
28
name : suricata-notify
29
29
path : suricata-notify
30
30
retention-days : 30
31
31
32
- download :
32
+ test :
33
33
runs-on : ubuntu-latest
34
34
needs : build
35
35
36
36
steps :
37
37
- name : Download Artifact
38
- uses : actions/download-artifact@v3
38
+ uses : actions/download-artifact@v4
39
39
with :
40
40
name : suricata-notify
41
41
path : ./
42
+
42
43
- name : Install Dependencies
43
44
run : |
44
- sudo apt-get update
45
- sudo apt-get install -y build-essential xvfb libnotify-bin strace
46
-
47
- - name : List Downloaded Files
48
- run : ls -la
45
+ sudo apt-get update
46
+ # sudo apt-get install -y xvfb strace libnotify-bin dbus-x11
47
+ sudo apt-get install -y xvfb xfce4-notifyd x11-apps x11-utils strace libnotify-bin dbus-x11
49
48
50
49
- name : Make Executable
51
50
run : chmod +x suricata-notify
52
51
52
+ - name : Show Help
53
+ run : ./suricata-notify --help
54
+
53
55
- name : Create Test Data
54
- run : echo '[{"event_type":"alert","timestamp":"2023-08-02T00:05:06.384656+0200","alert":{"signature":"Test Signature 1","category":"Test Category 1"}},{"event_type":"alert","timestamp":"2023-08-02T00:06:00.000000+0200","alert":{"signature":"Test Signature 2","category":"Test Category 2"}},{"event_type":"alert","timestamp":"2023-08-02T00:07:00.000000+0200","alert":{"signature":"Test Signature 3","category":"Test Category 3"}}]' > eve.json
56
+ run : |
57
+ current_time=$(date --utc --date="-33 seconds" +"%Y-%m-%dT%H:%M:%S.%6NZ")
58
+ echo "Current Time: $current_time"
59
+ # Create the JSON data with the timestamp embedded
60
+ json_data='{"timestamp":"'"$current_time"'","flow_id":1234567890123456,"pcap_cnt":150,"event_type":"alert","src_ip":"192.168.1.100","src_port":8080,"dest_ip":"10.0.0.5","dest_port":80,"proto":"TCP","pkt_src":"wire/pcap","ether":{"src_mac":"00:11:22:33:44:55","dest_mac":"66:77:88:99:AA:BB"},"tx_id":2,"alert":{"action":"allowed","gid":1,"signature_id":1000001,"rev":1,"signature":"Test Signature Example","category":"Test Category","severity":2,"metadata":{"affected_product":["Linux_Server_64_Bit"],"attack_target":["Server_Endpoint"],"created_at":["2024_08_20"],"deployment":["Perimeter"],"former_category":["TEST_RESPONSE"],"signature_severity":["Minor"],"updated_at":["2024_08_20"]}},"http":{"hostname":"example.com","http_port":8080,"url":"/test","http_content_type":"application/json","http_method":"GET","protocol":"HTTP/1.1","status":200,"length":1024},"files":[{"filename":"/test","gaps":false,"state":"CLOSED","stored":false,"size":1024,"tx_id":2}],"app_proto":"http","direction":"to_server","flow":{"pkts_toserver":10,"pkts_toclient":8,"bytes_toserver":2048,"bytes_toclient":4096,"start":"2024-08-20T15:29:50.000000+0000","src_ip":"10.0.0.5","dest_ip":"192.168.1.100","src_port":80,"dest_port":8080}}'
61
+ echo "$json_data"
62
+ echo "$json_data" > eve.json
63
+ echo "Test data written to eve.json"
55
64
56
- - name : Prepare Virtual Display
57
- run : xvfb-run -a -s "-screen 0 1024x768x24" sh -c "strace -o strace.log ./suricata-notify eve.json"
65
+ - name : Prepare Virtual Display and Test Notifications
66
+ run : |
67
+ # Run the program in a virtual display and capture strace logs
68
+ # export DISPLAY=:99 && xvfb-run -a -s "-screen 0 1024x768x24" sh -c '
69
+ export DISPLAY=:0 && xvfb-run -a -s "-screen 0 1024x768x24" sh -c '
70
+ echo "Starting dbus-session...";
71
+ eval $(dbus-launch --sh-syntax --exit-with-session);
72
+ echo "Running suricata-notify with strace..."
73
+ strace -f -o /tmp/suricata-notify-strace.log ./suricata-notify -v -w 60 -z 0 -e eve.json
74
+ '
58
75
59
76
- name : Upload Strace Log
60
- uses : actions/upload-artifact@v3
77
+ uses : actions/upload-artifact@v4
61
78
with :
62
79
name : strace-log
63
- path : strace.log
80
+ path : /tmp/suricata-notify- strace.log
64
81
retention-days : 30
82
+
83
+ - name : Check Strace Log
84
+ run : |
85
+ # Check for specific output in the strace log to determine success
86
+
87
+ # Check if the log contains the specific message we expect to send with notify-send
88
+ if grep -q "Test Category" /tmp/suricata-notify-strace.log; then
89
+ # Check if notify-send exited successfully
90
+ if grep -q "notify-send failed" /tmp/suricata-notify-strace.log; then
91
+ echo "Notification test failed due to notify-send error"
92
+ exit 1
93
+ else
94
+ echo "Notification test passed"
95
+ exit 0
96
+ fi
97
+ else
98
+ echo "Notification test failed: Message not found in strace log"
99
+ exit 1
100
+ fi
0 commit comments