Alcuni servizi/piattatorme che potrebbero tornare utili quando si sviluppa.
Timber, ma non ho visto come sia la GUIcreazione account x Elastic e Kibana
  PUT /documentale
  PUT /_ingest/pipeline/attachment
  BODY
  {
      "description": "Extract attachment information",
      "processors": [
          {
              "attachment": {
                  "field": "data"
              }
          },
          {
              "json": {
                  "field": "metadata"
              }
          }
      ]
  }
  PUT /documentale/_doc/my_id?pipeline=attachment
  GET /documentale/_search
  BODY 
  {
    "size": 10,
    "_source": {
      "excludes": [
        "attachment.content",
        "data"
      ]
    },
    "query": {
      "bool": {
        "should": [
          {
            "match_phrase": {
              "metadata.tags": "Due Tag"
            }
          },
          {
            "match_phrase": {
              "metadata.tags": "Dues Tag"
            }
          }
        ]
      }
    }
  }
Quindi per i log di apache posso fare cosi’:
uso il file fisico come sorgente input (/var/log/….)
uso un collettore (logstash, filebeat, rsyslog, etc)
il collettore oltre all’input puo’ avere un parser
nel collettore va specificato l’output, che sostanzialmente e’ l’endpoint di elastic search
Esempio di docker-compose:
service:
    logstash:
        image: docker.elastic.co/logstash/logstash:7.6.2
        volumes:
            - ./overrides/tests/logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro
            # - ./overrides/tests/logstash/config/:/usr/share/logstash/config/:ro
            - ./overrides/tests/logstash/pipeline:/usr/share/logstash/pipeline:ro
            - ./common-logs/:/logstash-logs/
Esempio di configurazione (config/logstash.yml):
---
## Default Logstash configuration from logstash-docker.
## from https://github.com/elastic/logstash-docker/blob/master/build/logstash/config/logstash-oss.yml
#
http.host: "0.0.0.0"
#path.config: /usr/share/logstash/pipeline
# :error=>"Elasticsearch Unreachable: [http://elasticsearch:9200/]
xpack.monitoring.enabled: false
#  Successfully started Logstash API endpoint {:port=>9600}
# original config file
#http.host: "0.0.0.0"
#xpack.monitoring.elasticsearch.hosts: [ "http://elasticsearch:9200" ]
Esempio di pipeline (pipeline/logstash.conf):
input {
  # se abilitato [logstash.inputs.beats    ][main] Beats inputs: Starting input listener {:address=>"0.0.0.0:5044"}
  #beats {
  #  port => 5044
  #}
    # questo server per evitare:START, creating Discoverer, Watch with file and sincedb collections;
    file {
      path => "/logstash-logs/apache2/*.log"
      #start_position => "beginning"
      sincedb_path => "/dev/null"
    }
}
filter {
  if [path] =~ "access" {
    mutate { replace => { "type" => "apache_access" } }
    grok {
      match => { "message" => "%{COMBINEDAPACHELOG}" }
    }
  }
  date {
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
  }
}
output {
    elasticsearch {
        hosts => ["https://XXXX:9200"]
        user => "<elasticsearch_user>"
        password => "<elasticsearch_pass>"
        # se non specificato, crea in automatico un indice del tipo logstash-aaaa.mm.gg
        #index => "linux-logs-test"
    }
}
Elastic Examples
GET _search
{
  "query": {
    "match_all": {}
  }
}
GET /_cat/indices
GET /_ingest/pipeline
PUT /test-index-rsyslog
GET /_cat/indices/test-index-rsyslog
GET /test-index-rsyslog
POST /test-index-rsyslog/_doc/
{
    "test" : "hello",
    "message" : "trying out Elasticsearch"
}
In Management > Kibana devo creare un nuovo index-pattern per poter visualizzare i logs nella sezione Discover,
ma la cosa importante da notare e’ che posso farlo solamente DOPO aver inserito almento un record per tale index.
Quindi a quel punto posso usare un index-pattern del tipo test-index-*