filebeat.prospectors:
- input_type: log
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["192.168.1.42:9200"]
filebeat.prospectors:
- input_type: log
paths:
- /var/log/*.log
- input_type: log
paths:
- "/var/log/apache2/*"
fields:
apache: true
output.elasticsearch:
hosts: ["192.168.1.42:9200"]
input {
file {
path => "/var/*.log"
}
elasticsearch {
hosts => "localhost"
query => '{ "query": { ... }'
}
}
filter {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{DATA:syslog_program}..." }
add_field => [ "received_from", "%{host}" ]
}
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
mutate {
remove_field => ["syslog_timestamp", "message"]
}
}
output {
stdout {
}
elasticsearch {
hosts => ["localhost"]
}
}
Verbes : GET, POST, PUT, DELETE
POST http://host:port/index/type/id/_action?param=42
{ "clef": "valeur" }
PUT /zenika-index/nightclazz/1
{
"name": "Stack Elastic",
"speaker": "Emmanuel DEMEY"
}
GET /zenika-index/nightclazz/1
DELETE /zenika-index/nightclazz/1
POST /zenika-index/nighclazz/_search
{ "query":{
"query_string":{
"query":"batch"
}
}
}
{ "hits": {
"hits": [
{
"_index": "zenika-index",
"_type": "elasticsearch",
"_id": "1",
"_score": 0.076713204,
"_source": {"titre": "Spring Batch in Action"}
}
], ...
} ... }
PUT /zenika-index/_mapping/nightclazz
{
"properties": {
"name": {
"type": "text",
"fields": {
"original": {"type": "keyword"}
}
},
"attendees":{ "type":"double" },
"speaker": {
"type":"text"
}
}
Tant va la cruche à l'eau qu'à la fin elle se brise
→ tant,va,cruch,eau,fin,bris
POST /zenika-index/nightclazz/_search
{
"query": { "match": {"titre": "action"}},
"sort": [{"titre": "asc"},"_score"],
"from": 0, "size": 100,
"aggs": {"stats_prix": {"stats": {"field": "prix"}}},
"highlight": {"fields": {"titre": {}}}
}
POST /zenika-index/nightclazz/_search
{ "query": {
"match_all": {}}}
POST /zenika-index/nightclazz/_search
{ "query": {
"match": {
"titre": "spring" }}}
POST /zenika-index/nightclazz/_search
{ "query": {
"query_string": {
"query": "spring AND batch" }}}
POST /zenika-index/nightclazz/_search
{ "query": {
"term": {
"editeur.code": "manning" }}}
POST /zenika-index/nightclazz/_search
{ "query": {
"range": {
"prix": {
"gt": 10,
"lte": 30 }}}}
POST /zenika-index/nightclazz/_search
{
"query": {
"bool": {
"must": [
{ "match": { "titre": "spring" }},
{ "match": { "auteurs": "cogoluegnes" }}
],
"should": [
{ "match": { "editeur": "manning" }}
]
}
}
}
POST /zenika-index/nightclazz/_search
{
"query": {
"match": {"titre": "action"}
},
"aggs": {
"titre_terms": {
"terms": {
"field": "titre",
"size": 5 }},
"prix_histo": {
"histogram": {
"field": "prix",
"interval": 2 }},
"prix_avg": {
"avg": {
"field": "prix" }}}}
>>>Response: POST /zenika-index/nightclazz/_search
{ ...
"aggregations":{
"titre_terms": {
"buckets": [
{ "key": "action", "doc_count": 6 },
{ "key": "spring", "doc_count": 2 },
{ "key": "batch", "doc_count": 1 },...]},
"prix_histo": {
"buckets": [
{ "key": 40, "doc_count": 2 },
{ "key": 42, "doc_count": 1 },
{ "key": 44, "doc_count": 0 }, ...]},
"prix_avg": {
"value": 44.74 }}}
PUT _xpack/watcher/watch/log_errors
{
"trigger" : {
"schedule" : {
"interval" : "5m"
}
},
"input" : {
"search" : {
"request" : {
"indices" : "log-events",
"body" : {
"size" : 0,
"query" : { "match" : { "status" : "error" } }
}
}
}
},
"condition" : {
"compare" : { "ctx.payload.hits.total" : { "gt" : 5 }}
},
"actions" : {
"my_webhook" : {
"webhook" : {
"method" : "POST",
"host" : "mylisteninghost",
"port" : 9200,
"path" : "/monitoring",
"body" : "Encountered {{ctx.payload.hits.total}} errors"
}
}
}
}