forked from saiddao/OntologyManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckEventSequenceICTGW.drl
249 lines (222 loc) · 7.3 KB
/
checkEventSequenceICTGW.drl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//created Jan 24, 2023 - 17:41:32
package it.cnr.isti.labsedc.concern.event;
import it.cnr.isti.labsedc.concern.event.ConcernAbstractEvent;
import it.cnr.isti.labsedc.concern.event.ConcernProbeEvent;
import it.cnr.isti.labsedc.concern.event.ConcernICTGatewayEvent;
import it.cnr.isti.labsedc.concern.utils.KieLauncher;
import it.cnr.isti.labsedc.concern.utils.Calculator;
import it.cnr.isti.labsedc.concern.notification.NotificationManager;
//Check a sequence of events strictly
dialect "java"
declare ConcernICTGatewayEvent
@role( event )
@timestamp( timestamp )
@expires(2m)
end
declare FirstAndSecondEvent
@role( event )
@expires(2m)
@timestamp ( timestamp )
destinationID : String
senderID : String
first : ConcernICTGatewayEvent
second : ConcernICTGatewayEvent
name : String
timestamp : long
end
declare FirstAndSecondAndThirdEvent
@role( event )
@expires(2m)
@timestamp ( timestamp )
destinationID : String
senderID : String
first : ConcernICTGatewayEvent
second: ConcernICTGatewayEvent
third : ConcernICTGatewayEvent
name: String
timestamp : long
end
rule "checkFirst"
no-loop
salience 1000
dialect "java"
when
$aEvent: ConcernICTGatewayEvent(
this.senderID == "ICTGW_Probe",
this.destinationID == "Monitoring",
this.name == "AUTHENTICATION_REQUEST",
this.consumed == false);
then
$aEvent.setConsumed(true);
update($aEvent);
KieLauncher.printInfo("Session started - Rule fired:" + drools.getRule().getName());
end
rule "checkStarter"
no-loop
salience 999
dialect "java"
when
$aEvent: ConcernICTGatewayEvent(
this.consumed == false);
not(ConcernICTGatewayEvent(
this.senderID == "ICTGW_Probe",
this.destinationID == "Monitoring",
this.name == "AUTHENTICATION_REQUEST",
this.consumed == true,
this before $aEvent) || FirstAndSecondEvent() || FirstAndSecondAndThirdEvent()
);
then
retract($aEvent);
NotificationManager.NotifyViolation($aEvent.getSenderID(), "Unattended event - Rule fired:" + drools.getRule().getName(), drools.getRule().getName(), drools.getRule().getMetaData());
end
rule "doubleStart"
no-loop
salience 998
dialect "java"
when
$aEvent: ConcernICTGatewayEvent(
this.senderID == "ICTGW_Probe",
this.destinationID == "Monitoring",
this.name == "AUTHENTICATION_REQUEST",
this.consumed == true);
$bEvent: ConcernICTGatewayEvent(
this.senderID == "ICTGW_Probe",
this.destinationID == "Monitoring",
this.name == "AUTHENTICATION_REQUEST",
this.consumed == false,
this after $aEvent);
then
retract($aEvent);
retract($bEvent);
NotificationManager.NotifyViolation($aEvent.getSenderID(), "Unattended event - Rule fired:" + drools.getRule().getName(), drools.getRule().getName(), drools.getRule().getMetaData());
end
rule "catchFirstAndCheckSecond"
no-loop
salience 997
dialect "java"
when
$aEvent: ConcernICTGatewayEvent(
this.senderID == "ICTGW_Probe",
this.destinationID == "Monitoring",
this.name == "AUTHENTICATION_REQUEST",
this.consumed == true);
$bEvent: ConcernICTGatewayEvent(
this.senderID == $aEvent.getSenderID(),
this.destinationID == $aEvent.getDestinationID(),
this.name != "REGISTRATION_RESPONSE" || this.ICTMessageType != "REGISTRATION_RESPONSE" || this.ICTMessageCategory != "REGISTRATION",
this after $aEvent);
then
retract($aEvent);
retract($bEvent);
NotificationManager.NotifyViolation($aEvent.getSenderID(), "Unattended event - Rule fired:" + drools.getRule().getName(), drools.getRule().getName(), drools.getRule().getMetaData());
end
rule "catchFirstAndSecond"
no-loop
salience 996
dialect "java"
when
$aEvent: ConcernICTGatewayEvent(
this.senderID == "ICTGW_Probe",
this.destinationID == "Monitoring",
this.name == "AUTHENTICATION_REQUEST",
this.ICTMessageType == "AUTHENTICATION_REQUEST",
this.ICTMessageCategory == "AUTHENTICATION",
this.consumed == true
);
$bEvent: ConcernICTGatewayEvent(
this.senderID == $aEvent.getSenderID,
this.destinationID == $aEvent.getDestinationID,
this.name == "REGISTRATION_RESPONSE",
this.ICTMessageType == "REGISTRATION_RESPONSE",
this.ICTMessageCategory == "REGISTRATION",
this after $aEvent);
then
FirstAndSecondEvent captured = new FirstAndSecondEvent();
captured.setTimestamp($aEvent.getTimestamp());
captured.setFirst($aEvent);
captured.setSecond($bEvent);
captured.setDestinationID($aEvent.getDestinationID());
captured.setSenderID($aEvent.getSenderID());
captured.setName($aEvent.getName() + "-" + $bEvent.getName());
insert(captured);
retract($aEvent);
retract($bEvent);
KieLauncher.printInfo("ComplexEvent first and second created - Rule fired:" + drools.getRule().getName());
end
rule "checkForCorrectThird"
no-loop
salience 995
dialect "java"
when
$aEvent: FirstAndSecondEvent();
$bEvent: ConcernICTGatewayEvent(
this.senderID == $aEvent.getSenderID(),
this.destinationID == $aEvent.getDestinationID(),
this.name != "TOPOLOGY_ELEMENTS_RESPONSE" || this.ICTMessageType != "TOPOLOGY_ELEMENTS_RESPONSE" || this.ICTMessageCategory != "DATA",
this after $aEvent);
then
retract($aEvent);
retract($bEvent);
NotificationManager.NotifyViolation($aEvent.getSenderID(), "Unattended event - Rule fired:" + drools.getRule().getName(), drools.getRule().getName(), drools.getRule().getMetaData());
end
rule "catchSecondAndThird"
no-loop
salience 994
dialect "java"
when
$aEvent: FirstAndSecondEvent();
$bEvent: ConcernICTGatewayEvent(
this.senderID == $aEvent.getSenderID(),
this.destinationID == $aEvent.getDestinationID(),
this.name == "TOPOLOGY_ELEMENTS_RESPONSE",
this.ICTMessageType == "TOPOLOGY_ELEMENTS_RESPONSE",
this.ICTMessageCategory == "DATA",
this after $aEvent);
then
FirstAndSecondAndThirdEvent captured = new FirstAndSecondAndThirdEvent();
captured.setTimestamp($aEvent.getTimestamp());
captured.setFirst($aEvent.getFirst());
captured.setSecond($aEvent.getSecond());
captured.setThird($bEvent);
captured.setDestinationID($aEvent.getDestinationID());
captured.setSenderID($aEvent.getSenderID());
captured.setName($aEvent.getName() + "-" + $bEvent.getName());
insert(captured);
retract($aEvent);
retract($bEvent);
KieLauncher.printInfo("ComplexEvent first, second and third created - Rule fired:" + drools.getRule().getName());
end
rule "checkForCorrectFourth"
no-loop
salience 993
dialect "java"
when
$aEvent: FirstAndSecondAndThirdEvent();
$bEvent: ConcernICTGatewayEvent(
this.senderID == $aEvent.getSenderID(),
this.destinationID == $aEvent.getDestinationID(),
this.name != "TOPOLOGY_ELEMENT_DETAILS_RESPONSE" || this.ICTMessageType != "TOPOLOGY_ELEMENT_DETAILS_RESPONSE" || this.ICTMessageCategory != "DATA",
this after $aEvent);
then
retract($aEvent);
retract($bEvent);
NotificationManager.NotifyViolation($aEvent.getSenderID(), "Unattended event - Rule fired:" + drools.getRule().getName(), drools.getRule().getName(), drools.getRule().getMetaData());
end
rule "catchThirdAndFourth"
no-loop
salience 991
dialect "java"
when
$aEvent: FirstAndSecondAndThirdEvent();
$bEvent: ConcernICTGatewayEvent(
this.senderID == $aEvent.getSenderID(),
this.destinationID == $aEvent.getDestinationID(),
this.name == "TOPOLOGY_ELEMENT_DETAILS_RESPONSE",
this.ICTMessageType == "TOPOLOGY_ELEMENT_DETAILS_RESPONSE",
this.ICTMessageCategory == "DATA",
this after $aEvent);
then
retract($aEvent);
retract($bEvent);
KieLauncher.printInfo("Cycle completed - Rule fired:" + drools.getRule().getName());
end