Filebeat, Kafka - topic name by %{[type]} or constant value? - filebeat

I have filebeat, which outputs to kafka.
Depending on type of document, I need to send logs to different topics.
In pseudo code:
if(type == type1)
topic = 'special.type1.topic'
...
else
topic = '%{[type]}'
I found that this is possible:
topics:
- topic: 'special.type1.topic'
when:
equals:
%{[type]}: type1
But if type is none of the tested, I want to use default topic name, as seen in pseudo by else statement. Is that possible ?

provide a default topic field for all untested files. When none of the rules match in "topics" then topic field is used.
In this case you will not need any rule for else in "topics". There your configuration will look something like this:
topic: untested-files
topics:
- topic: 'special.type1.topic'
when:
equals:
%{[type]}: type1

Related

PostgreSQL RPCs : allow required array parameters that will be processed in ANY/IN keywords to be null/empty

I have a PostgreSQL RPC that aims to select filtered rows of a view.
This RPC requires some parameters (name_article, catg_article, color_article, etc).
Most of these parameters are int[]/bigint[] because I want the user to be able to request "all blue articles or all red articles, etc" but I want the user to be able to post empty parameters as well, and that the request considers he doesn't care about which color or category so it will return all possibilities.
The problem is that from what I saw after many topics on Internet, the ANY () or IN () can't be empty, which I'd like to allow it otherwise my filters system would have to manage all possibilities and I really don't want to cry.
This is what I've readen on Internet to try ( param is null or in()/any() ) but it doesn't work, not returning any article (the first where is fine, also don't pay attention to the cast thing, it's just that catg_and_type is json so I have to say id_catgarticle from this json is a bigint so it works fine) :
SELECT *
FROM dev.get_all_articles
WHERE get_all_articles.lib_article ILIKE '%' || $1 || '%'
AND ($2 is null or CAST(get_all_articles.catg_et_type->>'id_catgarticle' AS BIGINT) = any ($2));
Do you have any idea how I could allow empty arrays that will be processed with IN/ANY commands ?
Thanks a lot.
Problem solved, as mentionned into my answer to #LaurenceIsla's answer to the topic.
When having to send an array parameter into a PostgREST API endpoint, the syntax is like this : /rpc/endpoint?param={1,2,3}. So in order to make the request understand an empty param in URL (endpoint?param={}), I had to say, in the WHERE clause this : OR $2 = '{}'. That's all. Kind of tricky syntax when you don't know it.

How do use fuzzy matching validation for either a non-present key or an empty array?

In karate version 0.9.6 I used the following match statement in a .feature file and it worked for validating the value to be an empty array or a key that was not present.
def example = {}
match example.errors == '##[0]'
In 1.0 the documentation example suggests that this should check for the key being present and null or an empty array and testing this fails with a validation error that the value is not present.
From https://karatelabs.github.io/karate/#schema-validation
# should be null or an array of strings
* match foo == '##[] #string'
This appears to be an undocumented breaking change from pre-1.0 to 1.0.
My question is: how do I construct a validator to cover this case correctly when the key is allowed to be absent but if it is present it must be an empty array?
I've found an undesirable solution for now but am leaving this open in case someone has a better answer.
I'm validating the entire parent object with a minimal schema:
Replace
match $.errors == '##[0]'
With
* match $ == { data: '#object', extensions: '##object', errors: '##[0]' }
While more brittle and verbose it is technically working.
This indeed looks like an in-intended breaking change. Here is another workaround:
* def example = {}
* def expected = example.errors ? '#[0]' : '#notpresent'
* match example.errors == expected
I see you have opened an issue here: https://github.com/karatelabs/karate/issues/1825
EDIT: this might be an improvement over the workaround you came up with in your answer:
* match example contains { errors: '##[0]' }

How to give names to MobX flows

How do I give a name to my flows?
I currently see messages in the console (using dev tools) like:
action '<unnamed flow> - runid: 3 - init'
index.js:1 action '<unnamed flow> - runid: 3 - yield 0'
My code (in typescript):
fetchMetricData = flow( function * (this: MetricDataStore) {
const responseJson:IMetrics[] = yield Http.post("/metrics");
this.metrics = responseJson;
});
According to following text found in MobX Api Reference · MobX page:
Tip: it is recommended to give the generator function a name, this is the name that will show up in dev tools and such
Unfortunately, this is the only way to set the name (I use LiveScript and can't set names to function expressions while defining it).
In your case, you can turn your unnamed function expression into a named one. If you ever face another situation where you can't, you could also use Object.defineProperty(myFunction, 'name', {value: 'myExplicitName'}).
You can find the culprit in the code: mobx/flow.ts at master · mobxjs/mobx.

Send keys with modifiers in Capybara/Poltergeist

So Poltergeist send_keys let you do this:
element = find('input#id')
element.native.send_key('String')
element.native.send_keys('H', 'elo', :Left, 'l') # => 'Hello'
element.native.send_key(:Enter) # triggers Enter key
I'm looking to send key combinations like:
Control-A
Alt-C
Can't find any references or had any success with various attempts.
Suggestions?
According to Issue #420 and the accompanying commit, you can do it in the following way:
element.native.send_keys('H', [:Shift, 'elo'], :Left, 'l')
element.native.send_key([:Ctrl, :Enter])
You can define multiple modifiers like this:
[:Ctrl, :Shift, "aaa"]
There is currently no release containing that change (last one is 1.6.0), so you will need to build it yourself.

Query Appcelerator Cloud services Place with LIKE operator and case insensitive

Q) Is it possible to query Appcelerator cloud services Places objects (insensitive) where: - name LIKE 'fred' - SQL would be something like?
SELECT * FROM Places WHERE name like '%fred%'
I.e. query would return (if existing):
Fred
Alfred
Winnefred
Please tell me if this is possible with a simple code block using Ti.Cloud or REST or anything!
Note: I've read the documentation thoroughly but can't find an answer there. Please don't direct me to the documentation for the answer. Thanks.
Thanks.
Possibly. What you want is a $regex in the "where" parameter of Places.Query. The docs say it only supports prefix searches, but maybe it can do more. The below would be the equivalent of your select.
Ti.Cloud.Places.query({
where: {
name: { $regex: 'fred', $options: 'i' }
}
}, ...);
If it doesn't work, then you'll need to open up a feature request for it.
http://cloud.appcelerator.com/docs/api/v1/places/query
http://cloud.appcelerator.com/docs/search_query