3 A filter examine an event and decides if it matches or doesn't. Filters
\r
4 are mainly used in rules to decide if the processing entries should be
\r
5 executed on the given event. They're also used for settings, and systems
\r
6 like the Graph Correlator re-use Highland Park's filter mechanism to
\r
7 specify which alarms fit in a correlation. Some publishers may produce
\r
8 topics with a lot of volume and a subscriber may want only a portion of
\r
9 those messages. The subscriber can certainly filter messages after
\r
10 receiving them, but it may be substantially more efficient to ask the
\r
11 API server to filter the messages before sending them to the
\r
12 subscriber.The standard library includes a number of simple filters. The
\r
13 Equals filter, for example, compares a field's value with some other
\r
14 value and returns true if the values match. The standard library also
\r
15 includes filter classes called And, Or, and Not, so you can compose more
\r
16 complex filters. For example, written in the standard JSON config
\r
19 +-----------------------------------------+
\r
24 | { "class":"Equals", "foo":"abc" }, |
\r
25 | { "class":"Assigned", "field":"bar" } |
\r
28 +-----------------------------------------+
\r
30 | This filter matches events in which the field "foo" has value "abc"
\r
31 and the field "bar" is assigned to some value (as opposed to not being
\r
32 present on the event). Filters are used by the consumers to filter out
\r
33 data and consume only specific set of data which matches the
\r
34 conditions mentioned in filter. Filters can be passed as a query
\r
35 parameter by the consumer in consume request as mentioned below:
\r
36 **http://localhost:8080/DMaaP/dmaaprest/events/DMaaP/consumergroup/mHOeNFY4XiWx4CBa?filter=\\{"class":"Equals",
\r
37 "field":"email", "value":"test@abc.com" }**
\r
38 | Filters can be applied only on data in JSON format i.e. if applied,
\r
39 filters will automatically ignore any non-json data. While consuming,
\r
40 request CONTENT\_TYPE is not relevant to filter.
\r
42 All the supported filter can be found below.
\r
45 Filters <https://wiki.web.att.com/display/MessageRouter/Types+of+Filters>`__
\r
47 | DMaaP Message Router supports all the filters which were supported by
\r
48 DMaaP Message Router and are mentioned below:-
\r
50 | Match all alarms.
\r
52 | Create a set of filters. This filter matches when all of them matches.
\r
54 +-------------+--------------------+------------+---------------------+
\r
55 | **Field** | **Description** | **Type** | **Notes** |
\r
56 +=============+====================+============+=====================+
\r
57 | filters | Combined Filters | LIST | A list of filters |
\r
58 +-------------+--------------------+------------+---------------------+
\r
60 +-------------+--------------------+------------+---------------------+
\r
63 | Choose a field from the event to check for assignment. This filter
\r
64 matches when the field is assigned.
\r
66 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
67 | **Field** | **Description** | **Type** | **Notes** |
\r
68 +===================+========================================================+============+=================+
\r
69 | field | The field to check for on the event. | STRING | A field name |
\r
70 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
71 | emptyIsAssigned | If true, an empty value is considered an assignment. | BOOLEAN | True or False |
\r
72 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
75 | Check if a search string contains another string.
\r
77 +-------------+---------------------------------------------------+------------+--------------+
\r
78 | **Field** | **Description** | **Type** | **Notes** |
\r
79 +=============+===================================================+============+==============+
\r
80 | String | The value to search. Supports ${} notation. | STRING | Any string |
\r
81 +-------------+---------------------------------------------------+------------+--------------+
\r
82 | Value | The value to search for. Supports ${} notation. | STRING | Any string |
\r
83 +-------------+---------------------------------------------------+------------+--------------+
\r
85 +-------------+---------------------------------------------------+------------+--------------+
\r
88 | Check if a search string ends with another string.
\r
90 +-------------+---------------------------------------------------+------------+--------------+
\r
91 | **Field** | **Description** | **Type** | **Notes** |
\r
92 +=============+===================================================+============+==============+
\r
93 | string | The value to search. Supports ${} notation. | STRING | Any string |
\r
94 +-------------+---------------------------------------------------+------------+--------------+
\r
95 | value | The value to search for. Supports ${} notation. | STRING | Any string |
\r
96 +-------------+---------------------------------------------------+------------+--------------+
\r
99 | Choose a field from the event and a value to check for equality.
\r
101 +-------------+----------------------------------------------+------------+--------------+
\r
102 | **Field** | **Description** | **Type** | **Notes** |
\r
103 +=============+==============================================+============+==============+
\r
104 | field | The field to check. Supports ${} notation. | STRING | Any string |
\r
105 +-------------+----------------------------------------------+------------+--------------+
\r
106 | value | The value to match. Supports ${} notation. | STRING | Any string |
\r
107 +-------------+----------------------------------------------+------------+--------------+
\r
109 | **FlatironObjectExists**
\r
110 | Matches when the given object exists in the given Flatiron instance.
\r
112 +-------------+---------------------------------------------+------------+--------------+
\r
113 | **Field** | **Description** | **Type** | **Notes** |
\r
114 +=============+=============================================+============+==============+
\r
115 | oid | The OID of the object to look for. | STRING | Any string |
\r
116 +-------------+---------------------------------------------+------------+--------------+
\r
117 | flatiron | The name of the Flatiron client instance. | STRING | Any string |
\r
118 +-------------+---------------------------------------------+------------+--------------+
\r
121 | Choose a field to test. This filter matches if the expression is
\r
124 +-------------+---------------------------------------------+------------+--------------+
\r
125 | **Field** | **Description** | **Type** | **Notes** |
\r
126 +=============+=============================================+============+==============+
\r
127 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
128 +-------------+---------------------------------------------+------------+--------------+
\r
131 | Choose a field to test. This filter matches if the expression is
\r
134 +-------------+---------------------------------------------+------------+--------------+
\r
135 | **Field** | **Description** | **Type** | **Notes** |
\r
136 +=============+=============================================+============+==============+
\r
137 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
138 +-------------+---------------------------------------------+------------+--------------+
\r
140 | **MathCondition**
\r
141 | Choose a field from the event and a value for logical math conditions.
\r
143 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
144 | **Field** | **Description** | **Type** | **Notes** |
\r
145 +=============+=================================================+============+===================================+
\r
146 | Field | The field to check. Supports ${} notation. | STRING | Any string |
\r
147 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
148 | Value | The value to consider. Supports ${} notation. | STRING | Any string |
\r
149 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
150 | operator | The operation. | STRING | One of { "<=", ">=", ">", "<" } |
\r
151 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
153 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
156 | Don't match any alarms.
\r
158 | Negate the configured filter.
\r
160 +-------------+-------------------------+------------+-------------+
\r
161 | **Field** | **Description** | **Type** | **Notes** |
\r
162 +=============+=========================+============+=============+
\r
163 | filter | The filter to negate. | FILTER | A filter |
\r
164 +-------------+-------------------------+------------+-------------+
\r
167 | Choose a field from the event and a value to check for inequality.
\r
169 +-------------+----------------------------------------------+------------+--------------+
\r
170 | **Field** | **Description** | **Type** | **Notes** |
\r
171 +=============+==============================================+============+==============+
\r
172 | field | The field to check. Supports ${} notation. | STRING | Any string |
\r
173 +-------------+----------------------------------------------+------------+--------------+
\r
174 | value | The value to match. Supports ${} notation. | STRING | Any string |
\r
175 +-------------+----------------------------------------------+------------+--------------+
\r
178 | Match when the specified field does not have a value from the given
\r
181 +-------------+---------------------------------------------+------------+---------------------+
\r
182 | **Field** | **Description** | **Type** | **Notes** |
\r
183 +=============+=============================================+============+=====================+
\r
184 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
185 +-------------+---------------------------------------------+------------+---------------------+
\r
186 | values | The matching values. | LIST | A list of strings |
\r
187 +-------------+---------------------------------------------+------------+---------------------+
\r
190 | Match when the specified field has a value from the given list.
\r
192 +-------------+---------------------------------------------+------------+---------------------+
\r
193 | **Field** | **Description** | **Type** | **Notes** |
\r
194 +=============+=============================================+============+=====================+
\r
195 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
196 +-------------+---------------------------------------------+------------+---------------------+
\r
197 | values | The matching values. | LIST | A list of strings |
\r
198 +-------------+---------------------------------------------+------------+---------------------+
\r
201 | Create a set of filters. This filter matches when any one of them
\r
204 +-------------+--------------------+------------+---------------------+
\r
205 | **Field** | **Description** | **Type** | **Notes** |
\r
206 +=============+====================+============+=====================+
\r
207 | filters | Combined Filters | LIST | A list of filters |
\r
208 +-------------+--------------------+------------+---------------------+
\r
211 | Choose a field from the event to match against the regular expression
\r
214 +-------------+---------------------------------------------------------+------------+--------------+
\r
215 | **Field** | **Description** | **Type** | **Notes** |
\r
216 +=============+=========================================================+============+==============+
\r
217 | field | The text to check for a match. Supports ${} notation. | STRING | Any string |
\r
218 +-------------+---------------------------------------------------------+------------+--------------+
\r
219 | value | The regular expression (pattern) to match. | STRING | Any string |
\r
220 +-------------+---------------------------------------------------------+------------+--------------+
\r
223 | Check if a search string starts with another string.
\r
225 +-------------+---------------------------------------------------+------------+--------------+
\r
226 | **Field** | **Description** | **Type** | **Notes** |
\r
227 +=============+===================================================+============+==============+
\r
228 | string | The value to search. Supports ${} notation. | STRING | Any string |
\r
229 +-------------+---------------------------------------------------+------------+--------------+
\r
230 | Value | The value to search for. Supports ${} notation. | STRING | Any string |
\r
231 +-------------+---------------------------------------------------+------------+--------------+
\r
234 | Choose a field from the event to check for assignment. This filter
\r
235 matches when the field is not assigned.
\r
237 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
238 | **Field** | **Description** | **Type** | **Notes** |
\r
239 +===================+========================================================+============+=================+
\r
240 | field | The field to check for on the event. | STRING | A field name |
\r
241 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
242 | emptyIsAssigned | If true, an empty value is considered an assignment. | BOOLEAN | True or False |
\r
243 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
245 | **WithinSecondsFrom**
\r
246 | This filter matches when the specified epoch time value is within the
\r
247 given number of seconds from the baseline time value. Both time values
\r
248 are assumed to be in seconds. If a value is in milliseconds, set
\r
249 baselineTimeInMillis and/or eventTimeInMillis to true.
\r
251 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
252 | **Field** | **Description** | **Type** | **Notes** |
\r
253 +========================+============================================================+============+=================+
\r
254 | field | The time value to test. Supports ${} | STRING | A field name |
\r
255 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
256 | eventTimeInMillis | Whether to convert the event value from milliseconds. | BOOLEAN | True or False |
\r
257 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
258 | seconds | The number of seconds. | NUMBER | A number |
\r
259 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
260 | baselineTimeInMillis | Whether to convert the baseline value from milliseconds. | BOOLEAN | True or False |
\r
261 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
262 | baseline | The baseline time value. Supports ${}. | STRING | Any string |
\r
263 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
265 | **WithinTimeFromNow**
\r
266 | This filter matches when the named field has an epoch time value
\r
267 within the given number of seconds from the current time. The event's
\r
268 time value is assumed to be in seconds. If it's in milliseconds, set
\r
269 eventTimeInMillis to true.
\r
271 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
272 | **Field** | **Description** | **Type** | **Notes** |
\r
273 +=====================+=========================================================+============+=================+
\r
274 | field | The field to check on the event. | STRING | A field name |
\r
275 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
276 | eventTimeInMillis | Whether to convert the event value from milliseconds. | BOOLEAN | True or False |
\r
277 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
278 | seconds | The number of seconds. | NUMBER | A number |
\r
279 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
283 - Limit is the integer value and DMaaP Message Router will consumes
\r
284 only that set of message which are specified in limit.
\r
286 | Suppose if we set limit=2, then only 2 sets of data will be consumed.
\r
287 | *Get \ **<<topicName>>/group/2?limit=4***
\r
288 | Let us suppose if
\r
289 | **No of data available** = 4
\r
290 | **Set limit** = 6
\r
291 | i.e. limit>no of data
\r
292 | In this scenario all 4 sets of data will be consumed.
\r
294 - If limit is not passed with the url then by default limit is set to
\r
297 | i.e. 4096 sets of data will be consumed.
\r
298 | **Timeout and Long Poll:**
\r
300 - Timeout is the integer value which will be treated by DMaaP Message
\r
301 Router as time in millisecond.
\r
307 +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
\r
308 | `***http://localhost/DMaaP/dmaaprest/events/<<topicName>>/group/2?timeout=20000*** <http://localhost/DMaaP/dmaaprest/events/%3c%3ctopicName%3e%3e/group/2?timeout=20000>`__ |
\r
309 +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
\r
311 - If there is no data available to be consumed, then DMaaP Message
\r
312 Router will poll for the particular period of time specified in
\r
313 timeout this mechanism is known as Long Poll.
\r
315 - If timeout is not passed with url then DMaaP Message Router will set
\r
316 the value of timeout =10000
\r
318 - i.e. if no set of data are available then DMaaP Message Router will
\r
323 - Meta is a Boolean value.
\r
325 - DMaaP Message Router reads the value of meta from
\r
326 MRConfiguration.properties file at the time of startup.
\r
328 - If the value of meta is not null and if value of meta is one of these
\r
329 values true, yes, on, 1, y, checked then DMaaP Message Router will
\r
330 take meta flag as true, else it will be false.
\r
332 - If meta is set to true then consumer will get the value of message
\r
333 offset along with message.
\r
338 - Pretty is a Boolean value.
\r
340 - DMaaP Message Router reads the value of pretty from
\r
341 MRConfiguration.properties file at the time of startup.
\r
343 - If the value of pretty is not null and if value of pretty is one of
\r
344 these values true, yes, on, 1, y, checked then DMaaP Message Router
\r
345 will take pretty flag as true, else it will be false.
\r
347 - If pretty is set to true then different sets of messages will be
\r
348 printed in next line separated by comma (,).
\r
352 | A filter examine an event and decides if it matches or doesn't.
\r
353 | Filters are mainly used in rules to decide if the processing entries
\r
354 should be executed on the given event. They're also used for settings,
\r
355 and systems like the Graph Correlator re-use Highland Park's filter
\r
356 mechanism to specify which alarms fit in a correlation.
\r
357 | The standard library includes a number of simple filters. The Equals
\r
358 filter, for example, compares a field's value with some other value
\r
359 and returns true if the values match.
\r
360 | The standard library also includes filter classes called And, Or, and
\r
361 Not, so you can compose more complex filters. For example, written in
\r
362 the standard JSON config format:
\r
364 +-----------------------------------------+
\r
369 | { "class":"Equals", "foo":"abc" }, |
\r
370 | { "class":"Assigned", "field":"bar" } |
\r
373 +-----------------------------------------+
\r
375 | This filter matches events in which the field "foo" has value "abc"
\r
376 and the field "bar" is assigned to some value (as opposed to not being
\r
377 present on the event).
\r
378 | Filters are used by the consumers to filter out data and consume only
\r
379 specific set of data which matches the conditions mentioned in filter.
\r
380 | Filters can be passed as a query parameter by the consumer in consume
\r
381 request as mentioned below:
\r
382 | **http://localhost:8080/DMaaP/dmaaprest/events/DMaaP/consumergroup/mHOeNFY4XiWx4CBa?filter=\\{"class":"Equals",
\r
383 "field":"email", "value":"`test@abc.com <mailto:test@att.com>`__" }**
\r
384 | Filters can be applied only on data in JSON format i.e. if applied,
\r
385 filters will automatically ignore any non-json data.
\r
386 | While consuming, request CONTENT\_TYPE is not relevant to filter.
\r
388 The MR API allows a subscriber pass a Highland Park filter as part of
\r
389 the GET request. This will filter the stream of messages sent back to
\r
390 the subscriber, but for this to work, there are some requirements:
\r
392 - The message payload must be JSON
\r
394 - Only a filter built from Highland Park's Standard Library may be
\r
395 used. (The Cambria API server doesn't have access to plugged in
\r
398 - The filter must be encoded properly in the URL path.
\r
400 Server-side filtering can also be setup in the Java client as
\r
403 **Filtering Consumer**
\r
405 You can also provide a Highland Park filter to your consumer instance,
\r
406 and this filter is passed on to the server in the GET request. One way
\r
407 to create the filter is programmatically. In your code, instantiate a
\r
408 filter from the Highland Park Standard Library Then create a String
\r
409 representation of the filter using the FilterIo.write utility. This
\r
410 String can then be passed to the Cambria client instance for use on the
\r
413 Remember, only Highland Park standard library filter components can be
\r
414 used -- no plug-ins are available in the Cambria server context.
\r
416 package org.onap.sa.highlandPark.integration;
\r
418 import java.io.IOException;
\r
420 import java.util.UUID;
\r
422 import org.onap.nsa.cambria.client.CambriaClientFactory;
\r
424 import org.onap.nsa.cambria.client.CambriaConsumer;
\r
426 import org.onap.sa.highlandPark.processor.HpEvent;
\r
428 import org.onap.sa.highlandPark.stdlib.filters.FilterIo;
\r
430 import org.onap.sa.highlandPark.stdlib.filters.OneOf;
\r
432 public class ExampleFilteringConsumer
\r
436 public static void main ( String[] args ) throws IOException,
\r
437 InterruptedException
\r
441 // Cambria clients take a set of 1 or more servers to use in round-robin
\r
444 // If a server becomes unreachable, another in the group is used.
\r
447 serverGroup="ueb01hydc.it.att.com,ueb02hydc.it.att.com,ueb03hydc.it.att.com";
\r
451 final String topic = "TEST-TOPIC";
\r
453 // Cambria clients can run in a cooperative group to handle high-volume
\r
456 // Here, we create a random group name, which means this client is not
\r
459 final String consumerGroup = UUID.randomUUID ().toString ();
\r
461 final String consumerId = "0";
\r
463 // Cambria clients can sit in a tight loop on the client side, using a
\r
466 // to wait for messages, and a limit to tell the server the most to send
\r
469 final int longPollMs = 30\*1000;
\r
471 final int limit = -1;
\r
473 // The Cambria server can filter the returned message stream using
\r
476 // Highland Park system. Here, we create a simple filter to test for the
\r
479 // value being one of the Mobility power alarms.
\r
481 final OneOf oneOf = new OneOf ( "AlarmId", kPowerAlarms );
\r
483 // create the consumer
\r
485 final CambriaConsumer cc = CambriaClientFactory.createConsumer (
\r
486 serverGroup, topic,
\r
488 consumerGroup, consumerId, longPollMs, limit, FilterIo.write ( oneOf )
\r
491 // now loop reading messages. Note that cc.fetch() will wait in its HTTP
\r
494 // method for up to 30 seconds (longPollMs) when nothing's available at
\r
503 for ( String msg : cc.fetch () )
\r
507 System.out.println ( "" + (++count) + ": " + msg );
\r
515 private static final String[] kPowerAlarms =
\r
519 "HUB COMMERCIAL POWER FAIL\_FWD",
\r
521 "HUB COMMERCIAL POWER FAIL",
\r
523 "RBS COMMERCIAL POWER FAIL - Fixed\_FWD",
\r
525 "RBS COMMERCIAL POWER FAIL\_FWD",
\r
527 "RBS COMMERCIAL POWER FAIL - No Generator\_FWD",
\r
529 "RBS COMMERCIAL POWER FAIL - Portable\_FWD",
\r
531 "RBS COMMERCIAL POWER FAIL - Shared\_FWD",
\r
533 "RBS COMMERCIAL POWER FAIL - Yes\_FWD",
\r
535 "RBS COMMERCIAL POWER FAIL - YES\_FWD",
\r
537 "RBS COMMERCIAL POWER FAIL - Fixed",
\r
539 "RBS COMMERCIAL POWER FAIL - No Generator",
\r
541 "RBS COMMERCIAL POWER FAIL - Portable",
\r
543 "RBS COMMERCIAL POWER FAIL - Shared",
\r
545 "RBS COMMERCIAL POWER FAIL - YES",
\r
547 "RBS COMMERCIAL POWER FAIL - Yes",
\r
549 "RBS COMMERCIAL POWER FAIL",
\r
551 "HUB COMMERCIAL POWER FAIL - Fixed",
\r
553 "HUB COMMERCIAL POWER FAIL - No Generator",
\r
555 "HUB COMMERCIAL POWER FAIL - Portable",
\r
557 "HUB COMMERCIAL POWER FAIL - Shared",
\r
559 "HUB COMMERCIAL POWER FAIL - Fixed\_FWD",
\r
561 "HUB COMMERCIAL POWER FAIL - No Generator\_FWD",
\r
563 "HUB COMMERCIAL POWER FAIL - Portable\_FWD",
\r
565 "HUB COMMERCIAL POWER FAIL - Shared\_FWD",
\r
573 ** Filter Builder**
\r
575 MR server-side filtering allows a consumer to filter the stream of
\r
576 messages returned from the GET call. The following link provide details
\r
577 of building some of the filter to illustrate Filter Builder. It is not
\r
578 meant to cover and provide examples of every filter
\r
580 .. |image1| image:: images/image1.png
\r
581 .. |image2| image:: images/image2.png
\r