diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1ec25f8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +# name: CI + +# on: +# push: +# branches: [main] +# paths-ignore: +# - "README.md" +# - "doc/**" +# pull_request: +# branches: [main] +# paths-ignore: +# - "README.md" +# - "doc/**" + +# jobs: +# test: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# - name: Set up Python 3.10 +# uses: actions/setup-python@v2 +# with: +# python-version: "3.10" +# - name: Install dependencies for requirements and testing +# run: | +# python -m pip install --upgrade pip +# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi +# if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi +# - name: Lint with pylint +# run: | +# pylint src/* +# - name: Create token.txt +# run: | +# echo ${{ secrets.TOKEN }} > token.txt +# - name: Test with pytest +# run: | +# pytest --cov=src --cov=main tests/ --cov-fail-under=75 +# - name: Delete token.txt +# run: | +# rm -f token.txt \ No newline at end of file diff --git a/.gitignore b/.gitignore index 68bc17f..210e43d 100644 --- a/.gitignore +++ b/.gitignore @@ -157,4 +157,5 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ + +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index ecf096a..5019df8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # air-flow-monitor Real-time air quality tracking software + +# Prerequisites +To use the Air-Flow Monitor, you should be familiar with the following: +- [Docker](https://www.docker.com/) +- [Python](https://www.python.org/) +- API key (dipende dal provider scelto) + + +## Logstash +```bash +cd logstash +docker build . --tag tap:logstash +docker run --rm -it --hostname="logstash" -v $PWD/pipeline/httpoller.conf:/usr/share/logstash/pipeline/logstash.conf -e XPACK_MONITORING_ENABLED=false docker.elastic.co/logstash/logstash:8.13.0 +``` \ No newline at end of file diff --git a/logstash/Dockerfile b/logstash/Dockerfile new file mode 100644 index 0000000..1a08875 --- /dev/null +++ b/logstash/Dockerfile @@ -0,0 +1,10 @@ +FROM docker.elastic.co/logstash/logstash:8.13.0 + +# Add your logstash plugins setup here +RUN logstash-plugin install logstash-filter-sentimentalizer + +# to build with +# docker build . --tag tap:logstash +# and run with +# docker run --rm -it --hostname="logstash" -v $PWD/pipeline/echostash.conf:/usr/share/logstash/pipeline/logstash.conf -e XPACK_MONITORING_ENABLED=false docker.elastic.co/logstash/logstash:8.13.0 +# make sure that pipeline dir with proper conf is there% diff --git a/logstash/pipeline/nearest_city.conf b/logstash/pipeline/nearest_city.conf new file mode 100644 index 0000000..9197b10 --- /dev/null +++ b/logstash/pipeline/nearest_city.conf @@ -0,0 +1,59 @@ +input { + http_poller { + urls => { + get_countries => { + method => get + url => "http://api.airvisual.com/v2/nearest_city?key=0e72cb61-87b6-4ab4-b422-0886e1305ac6" + headers => { + "Content-Type" => "application/json" + # + } + } + } + request_timeout => 60 + codec => "json" + type => "Http_poller" + schedule => { "every" => "1h" } + } +} + +filter { + json { + source => "event.original" + target => "parsed_data" + } + + mutate { + remove_field => ["event", "status", "@version"] # Rimuove i campi non necessari + } + + # Rinomina i campi all'interno della struttura "data" per renderli piĆ¹ leggibili + mutate { + rename => { + "[data][current][weather][ic]" => "weather_icon" + "[data][current][weather][pr]" => "pressure" + "[data][current][weather][tp]" => "temperature" + "[data][current][weather][ws]" => "wind_speed" + "[data][current][weather][hu]" => "humidity" + "[data][current][weather][wd]" => "wind_direction" + "[data][current][weather][ts]" => "weather_timestamp" + "[data][current][pollution][maincn]" => "pollution_maincn" + "[data][current][pollution][aqius]" => "pollution_aqius" + "[data][current][pollution][mainus]" => "pollution_mainus" + "[data][current][pollution][aqicn]" => "pollution_aqicn" + "[data][current][pollution][ts]" => "pollution_timestamp" + } + } + + mutate { + remove_field => ["[data][current][weather]", "[data][current][pollution]"] + } +} + +output { + # file{ + # path => "tmp/messages" + # } + + stdout {} +} \ No newline at end of file