Запустите файл конфигурации Logsta sh из веб-приложения с Flask - PullRequest
0 голосов
/ 28 апреля 2020

Я создаю веб-приложение с flask. С помощью кнопки пользователь выбирает CSV-файл со своего рабочего стола, а когда он нажимает кнопку «Отправить», запускается конфигурационный файл LOGSTA SH, чтобы импортировать этот файл (ранее выбранный пользователем) в ELASTICSEARCH. Так что у меня возникло затруднение при кодировании этого с flask, как именно файл конфигурации принимает путь файла csv как ввод? и как я могу запустить файл конфигурации?

Это моя попытка:

1- file.conf

input{
    file{
      path => '**new_path**'      #Here it should be a dynamic variable 'new_path' and it should take the 
                              #path of the csv file like an input ???
      start_position => "beginning"
      sincedb_path => "NUL"
      codec => plain { charset => "CP1252" }
    }
}
filter{
    csv {
        separator => ";"


        convert => {
            "longitude" => "float"
            "latitude" => "float"


        } 

    }
    date { match => [ "time", "dd MMM yy HH:mm:ss" ] }

    mutate{ add_field => { "location" => "%{latitude},%{longitude}" } }

}

output{
    elasticsearch { 
        action => "index"
        hosts => ["http://localhost:9200/"] 
        index => "data"
        document_type => "doc"
  }
  stdout { codec => rubydebug }
}

2- profile. html

{% extends "base.html" %}strong text
{% block content %}
    <h1 class="title"> Welcome, {{ name }}! </h1>
    <h3>You can import your data here </h3>
    <form enctype="multipart/form-data" class="" action="data" method="post">
        <input type="file" name="**csvfilename**" value="">
        <input type="submit" name="" value="submit">
    </form>
{% endblock %}

3- main.py

#That is the function that is responsible for the data import into ES:  
@main.route('/data', methods=['GET', 'POST'])
def data():
    if request.method == 'POST':
        # Here I want to take the path of the file 
        new_path = os.path.abspath('csvfilename')
        # Here I should run the conf file ???
         main.config.from_object('file', 'new_path')
    return render_template('data.html') 

Буду благодарен, если кто-нибудь сможет мне помочь. : Slight_smile:

...