The code below consist of .yaml template language.
I have a question which is "float -2" in Jinja2 template source.
I can't understand it.
Does it means simply "result value minus 2" nor "result value rounds as -2 digit"?
Please answer to me if someone learned well about Jinja2 template exist.
- id: miair2_auto_stop_window
alias: 'Mi Air Pro2 Auto Stop in Window'
trigger:
platform: template
value_template: "{{ states.fan.xiaomi_air_pro_2_window.attributes.aqi | float < states.input_number.miair2_stop_window.state | float -2 }}"
condition:
condition: state
entity_id: input_select.miair2_am_window
state: 'Auto'
action:
service: fan.turn_off
entity_id: fan.xiaomi_air_pro_2_window
float is a filter to convert the value on the left side to a float. The -2 is the default value in case the conversion for some reason fails.
See http://jinja.pocoo.org/docs/2.10/templates/#builtin-filters for description of the built in filters to jinja.
Related
I am setting up the EFK stack for my containerized environment. I have given /var/lib/docker/containers/*.log to get logs from all the containers and it is working fine.
Now I saw some strange logs generated by one of my containers and I decided to not show them on Kibana dashboard.
#timestamp August 30th 2019, 13:44:59.136
_id XXX
_index filebeat-6.0.1-2019.08.30
_score -
_type doc
beat.namexyz xyz.com
beat.version 6.0.1
container.name mycontainer
property mycontainerproperty
log:
How can I hide the entries for this container?
I thought not to take the logs from this container in the first place but the container ID is not going to be the same every time. so excluding it in the input section seems impossible.
Please let me know if anyone has any idea here. Is there any grok pattern that I can use to hide entries for this container?
So as stated from the OP in the comments the events that should be dropped start with the value DEBU: in the log field.
Here's a logstash filter (untested) that checks if the value of the log field matches this criteria. If so, the event will dropped which means it will not be indexed into Elasticsearch.
filter{
grok{
match => { "log" => "^DEBU:.*" }
tag_on_failure => [ "event_should_not_be_dropped" ]
}
if "event_should_not_be_dropped" not in [tags]{
drop { }
}
}
With the grok plugin we check if the value of the log field start with DEBU:. If not, the event will be tagged. If the event is not tagged the whole event will be dropped.
I hope I could help you.
In case anyone is looking for a solution to the above situation-
I edit my filebeat.yml and put the drop filter/processor.
My filebeat.yml looks like-
data:
kubernetes.yml: |-
- type: log
paths:
- /var/lib/docker/containers/*/*.log
json.message_key: log
json.keys_under_root: true
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: 'after'
scan_frequency: 20s
processors:
- add_kubernetes_metadata:
in_cluster: true
namespace: ${POD_NAMESPACE}
include_annotations:
- "build"
- "branch-name"
- drop_event.when:
or:
- equals:
property: "mycontaininerproperty"
- equals:
label: "mycontainerlabel"
so now if any of the log entries contains property="mycontainerproperty" or label="mycontainerlebel". It will drop those entries.
In our Angular project, we use interpolation as shown below, but we also need to use this interpolated value in the [state] property. But we haev not managed so far. Any idea?
If we set id values as shown below, there is no problem.
<a routerLink="/ticket/details/" [state]="{ id: '5' }" >{{row.TicketId}}</a>
But we cannot get dynamically by obtaining row.TicketId (it is obtained as label in {{row.TicketId}}) but cannot concatenate with id parameter.
<a routerLink="/ticket/details/" [state]="{ id: {{row.TicketId}} }" >{{row.TicketId}}</a>
The brackets in [state]="..." tell Angular to evaluate the template expression, so you cant use interpolation there. So, as I said in comment it should be:
[state]="{ id: row.TicketId }"
Try [state]="{ id: row.TicketId }"
I am using i18n API for a purpose. I seed a MySQL database with:
Translation.find_or_create_by(locale: 'en', key:'key1', value: 'value1')
However, after seed, the data is saved on database as:
locale: en
key: key1
value: --- value1\n...\n
All columns are varchar(255) and 'utf8_unicode_ci'.
On Rails i18n documentation, I could not find an explanation for this.
Because of that problem, I can not use find_or_create_by() method. It do/can not check the value column and adds duplicate entries.
Is there any solution for that?
Translate model:
Translation = I18n::Backend::ActiveRecord::Translation
if Translation.table_exists?
I18n.backend = I18n::Backend::ActiveRecord.new
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
end
What you're seing in your value column is the value serialized to YAML (that's done by the I18n::Backend::ActiveRecord::Translation); which is required, among other things, for pluralization.
#find_or_create_by doesn't work nicely when the value stored in the database needs serialization
To do a simple seed try:
Translation.create_with(value: 'value1').find_or_create_by(locale: 'en', key: 'key1')
I'm using yii2 in local server but I face error like this
Undefined class constant 'TYPE_LIST'
...
...
'type' => DepDrop::TYPE_LIST
...
...
So, I check vendor/kartik-v/yii2-widget-depdrop/DepDrop.php
There is no const TYPE_LIST but when I check thus file in production server there is const TYPE_LIST = 3
Package version is yii2-widget-depdrop 1.0.4 for both server, production and local
But when I check official package repo https://github.com/kartik-v/yii2-widget-depdrop/blob/master/DepDrop.php
There is no const TYPE_LIST
How I can fix this error?
Thanks in advance
You are looking to the wrong component
for depdrop the type is
type: int the type of dropdown list to be generated. Should be one of
the following values:
1 or DepDrop::TYPE_DEFAULT: render a default HTML select using
\yii\helpers\Html::dropDownList.
2 or DepDrop::TYPE_SELECT2: render advanced Select2 using
\kartik\widgets\Select2 widget.
If not set the type will default to 1 or DepDrop::TYPE_DEFAULT.
for sortable type is
The Sortable widget allows you to configure the following properties:
type: string, the type of the sortable widget. Defaults to
Sortable::TYPE_LIST. Should be one of
Sortable::TYPE_LIST or list
Sortable::TYPE_GRID or grid
http://demos.krajee.com/sortable
http://demos.krajee.com/widget-details/depdrop
I have a database that has a task table. In that table, there is a date column. Those dates are formatted as strings, they aren't Date.
I'm trying to sort these tasks by date. I already have an array of the tasks named tasks. I'm trying to replace it with the sorted array called tasksByDate using the below code.
tasksByDate = tasks.sort_by do |task|
task[:date].to_date
end
The error I'm getting is:
TypeError: no implicit conversion of Symbol into Integer
I also tried without to_date just to see if it would sort it without it being a date, and just being a string.
The date field is formatted as a string like so 2016-08-29. I used the to_date method on it somewhere else in the code, and it works great, so I didn't really think that was the problem.
Edit 1
I have checked that tasks actually contains a date, and it is formatted like explained.
The output of p task.class is Array
Edit 2
The output of p task is
[#<User id: 10, login: "my.name", hashed_password: "", date: "2016-08-29">]
The elements appear to be nested deeper than you expected them to be. Change the your code to:
# use '{ }' instead of 'do end' for a single-line blocks
tasksByDate = tasks.sort_by { |task| task.first[:date].to_date }
Explanation:
What you see as an output of p task:
[#<User id: 10, login: "my.name", hashed_password: "", date: "2016-08-29">]
It means that this is an Array of elements. Notice the enclosing braces [ ]. So what you have to do in this case is task.first, which will return:
#<User id: 10, login: "my.name", hashed_password: "", date: "2016-08-29">
From there you should be able to access the element's values by a key, like you intended:
task.first[:date]