diff --git a/.gitignore b/.gitignore index 0e84020..aa5c249 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ examples/*.ogg .env # openvpn server configuration services/ansible_openvpn/docker/openvpn-data +services/ansible_openvpn/docker/dashboard/config.json diff --git a/services/ansible_openvpn/docker/dashboard/README.md b/services/ansible_openvpn/docker/dashboard/README.md index 60f01f2..b5065e6 100644 --- a/services/ansible_openvpn/docker/dashboard/README.md +++ b/services/ansible_openvpn/docker/dashboard/README.md @@ -1,7 +1,20 @@ -Derived from this work -https://github.com/docker/awesome-compose/tree/c2f8036fd353dae457eba7b9b436bf3a1c85d937/flask +# Dashboard website -To test locally +This frontend website is displaying the state and data of the sensor network. + +It is linked to an elastic-search instance that store and index the files +generated by zero_*.py services. + +This website and the backend is easily deployed if you are using the docker +services described in [ansible_openvpn](../ansible_openvpn) folder. + +# Build and run image to container + +```shell +sudo docker build ./ -t dashboard && sudo docker run -p "8080:80" -v ./app/:/home/dashboard/app/ dashboard +``` + +Then open localhost:8080 in browser + +Without having to rebuild the image or restarting the container, all changes made in files will be automatically applied -docker build -t flasktest . -docker run --name flasktest -p 8000:8000 flasktest diff --git a/services/ansible_openvpn/docker/dashboard/app/config.json b/services/ansible_openvpn/docker/dashboard/app/config.json new file mode 100644 index 0000000..66896c7 --- /dev/null +++ b/services/ansible_openvpn/docker/dashboard/app/config.json @@ -0,0 +1,8 @@ +{ + "id": "hKUAUIoBOM9IQ1Kp18_2", + "name": "python2", + "api_key": "Qk77qq1AR3WxkwbuQw_Jcw", + "encoded": "aEtVQVVJb0JPTTlJUTFLcDE4XzI6UWs3N3FxMUFSM1d4a3didVF3X0pjdw==", + "url": "https://172.20.0.3:9200", + "verify_certs": false +} diff --git a/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.ttf b/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.ttf new file mode 100644 index 0000000..35acda2 Binary files /dev/null and b/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.ttf differ diff --git a/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.woff b/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.woff new file mode 100644 index 0000000..400014a Binary files /dev/null and b/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.woff differ diff --git a/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.woff2 b/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.woff2 new file mode 100644 index 0000000..4d13fc6 Binary files /dev/null and b/services/ansible_openvpn/docker/dashboard/app/fonts/fontawesome-webfont.woff2 differ diff --git a/services/ansible_openvpn/docker/dashboard/app/main.py b/services/ansible_openvpn/docker/dashboard/app/main.py index 0aed9f1..a7fb355 100644 --- a/services/ansible_openvpn/docker/dashboard/app/main.py +++ b/services/ansible_openvpn/docker/dashboard/app/main.py @@ -27,23 +27,44 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -from fastapi import FastAPI +from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates +import json +import os +from elasticsearch import Elasticsearch +from elasticsearch.helpers import streaming_bulk +import elasticsearch.helpers app = FastAPI() +app.mount("/static", StaticFiles(directory="app/static"), name="static") + +app.mount("/fonts", StaticFiles(directory="app/fonts"), name="fonts") + +templates = Jinja2Templates(directory="app/templates") + +if not os.path.exists("app/config.json"): + raise Exception("Configuration file not found " + + os.path.abspath("app/config.json")) +configuration = json.load(open("app/config.json", "r")) + +client = Elasticsearch( + configuration.get("url", "https://es01:9200"), + api_key=(configuration["id"], configuration["api_key"]), + verify_certs=configuration.get("verify_certs", True), timeout=60 +) + + +@app.get("/api/sensor_position") +async def get_sensor_position(request: Request): + post_data = templates.get_template("query_sensor_list.json").render() + resp = client.search(index="sensor_location_*", query=post_data) + return resp @app.get('/', response_class=HTMLResponse) -async def home(): - return """ - - - - NoiseSensor dashboard default page - - -

Please run the Ansible playbook named deploy_elastic_web_dashboard.yml

- -""" +async def home(request: Request): + return templates.TemplateResponse("status.html", + context={"request": request}) diff --git a/services/website_dashboard/app/static/d3.v5.min.js b/services/ansible_openvpn/docker/dashboard/app/static/d3.v5.min.js similarity index 100% rename from services/website_dashboard/app/static/d3.v5.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/d3.v5.min.js diff --git a/services/website_dashboard/app/static/daterangepicker.css b/services/ansible_openvpn/docker/dashboard/app/static/daterangepicker.css similarity index 100% rename from services/website_dashboard/app/static/daterangepicker.css rename to services/ansible_openvpn/docker/dashboard/app/static/daterangepicker.css diff --git a/services/website_dashboard/app/static/daterangepicker.min.js b/services/ansible_openvpn/docker/dashboard/app/static/daterangepicker.min.js similarity index 100% rename from services/website_dashboard/app/static/daterangepicker.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/daterangepicker.min.js diff --git a/services/website_dashboard/app/static/font-awesome.min.css b/services/ansible_openvpn/docker/dashboard/app/static/font-awesome.min.css similarity index 100% rename from services/website_dashboard/app/static/font-awesome.min.css rename to services/ansible_openvpn/docker/dashboard/app/static/font-awesome.min.css diff --git a/services/website_dashboard/app/static/forge.min.js b/services/ansible_openvpn/docker/dashboard/app/static/forge.min.js similarity index 100% rename from services/website_dashboard/app/static/forge.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/forge.min.js diff --git a/services/website_dashboard/app/static/forge.min.js.map b/services/ansible_openvpn/docker/dashboard/app/static/forge.min.js.map similarity index 100% rename from services/website_dashboard/app/static/forge.min.js.map rename to services/ansible_openvpn/docker/dashboard/app/static/forge.min.js.map diff --git a/services/website_dashboard/app/static/forms.css b/services/ansible_openvpn/docker/dashboard/app/static/forms.css similarity index 100% rename from services/website_dashboard/app/static/forms.css rename to services/ansible_openvpn/docker/dashboard/app/static/forms.css diff --git a/services/website_dashboard/app/static/handsontable.full.css b/services/ansible_openvpn/docker/dashboard/app/static/handsontable.full.css similarity index 100% rename from services/website_dashboard/app/static/handsontable.full.css rename to services/ansible_openvpn/docker/dashboard/app/static/handsontable.full.css diff --git a/services/website_dashboard/app/static/handsontable.full.js b/services/ansible_openvpn/docker/dashboard/app/static/handsontable.full.js similarity index 100% rename from services/website_dashboard/app/static/handsontable.full.js rename to services/ansible_openvpn/docker/dashboard/app/static/handsontable.full.js diff --git a/services/website_dashboard/app/static/handsontable.js.map b/services/ansible_openvpn/docker/dashboard/app/static/handsontable.js.map similarity index 100% rename from services/website_dashboard/app/static/handsontable.js.map rename to services/ansible_openvpn/docker/dashboard/app/static/handsontable.js.map diff --git a/services/website_dashboard/app/static/handsontable.min.css b/services/ansible_openvpn/docker/dashboard/app/static/handsontable.min.css similarity index 100% rename from services/website_dashboard/app/static/handsontable.min.css rename to services/ansible_openvpn/docker/dashboard/app/static/handsontable.min.css diff --git a/services/website_dashboard/app/static/handsontable.min.js b/services/ansible_openvpn/docker/dashboard/app/static/handsontable.min.js similarity index 100% rename from services/website_dashboard/app/static/handsontable.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/handsontable.min.js diff --git a/services/website_dashboard/app/static/jquery.min.js b/services/ansible_openvpn/docker/dashboard/app/static/jquery.min.js similarity index 100% rename from services/website_dashboard/app/static/jquery.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/jquery.min.js diff --git a/services/website_dashboard/app/static/leaflet/L.Control.Locate.min.css b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.css similarity index 100% rename from services/website_dashboard/app/static/leaflet/L.Control.Locate.min.css rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.css diff --git a/services/website_dashboard/app/static/leaflet/L.Control.Locate.min.css.map b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.css.map similarity index 100% rename from services/website_dashboard/app/static/leaflet/L.Control.Locate.min.css.map rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.css.map diff --git a/services/website_dashboard/app/static/leaflet/L.Control.Locate.min.js b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.js similarity index 100% rename from services/website_dashboard/app/static/leaflet/L.Control.Locate.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.js diff --git a/services/website_dashboard/app/static/leaflet/L.Control.Locate.min.js.map b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.js.map similarity index 100% rename from services/website_dashboard/app/static/leaflet/L.Control.Locate.min.js.map rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/L.Control.Locate.min.js.map diff --git a/services/website_dashboard/app/static/leaflet/images/layers-2x.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/layers-2x.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/images/layers-2x.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/layers-2x.png diff --git a/services/website_dashboard/app/static/leaflet/images/layers.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/layers.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/images/layers.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/layers.png diff --git a/services/website_dashboard/app/static/leaflet/images/marker-icon-2x.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/marker-icon-2x.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/images/marker-icon-2x.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/marker-icon-2x.png diff --git a/services/website_dashboard/app/static/leaflet/images/marker-icon.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/marker-icon.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/images/marker-icon.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/marker-icon.png diff --git a/services/website_dashboard/app/static/leaflet/images/marker-shadow.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/marker-shadow.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/images/marker-shadow.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/images/marker-shadow.png diff --git a/services/website_dashboard/app/static/leaflet/img/cabinet-icon-2x-green.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet-icon-2x-green.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/cabinet-icon-2x-green.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet-icon-2x-green.png diff --git a/services/website_dashboard/app/static/leaflet/img/cabinet-icon-2x-red.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet-icon-2x-red.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/cabinet-icon-2x-red.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet-icon-2x-red.png diff --git a/services/website_dashboard/app/static/leaflet/img/cabinet-icon-2x-yellow.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet-icon-2x-yellow.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/cabinet-icon-2x-yellow.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet-icon-2x-yellow.png diff --git a/services/website_dashboard/app/static/leaflet/img/cabinet.svg b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet.svg similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/cabinet.svg rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/cabinet.svg diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-black.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-black.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-black.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-black.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-blue.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-blue.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-blue.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-blue.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-green.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-green.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-green.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-green.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-grey.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-grey.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-grey.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-grey.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-orange.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-orange.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-orange.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-orange.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-red.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-red.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-red.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-red.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-violet.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-violet.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-violet.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-violet.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-2x-yellow.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-yellow.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-2x-yellow.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-2x-yellow.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-black.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-black.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-black.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-black.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-blue.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-blue.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-blue.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-blue.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-green.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-green.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-green.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-green.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-grey.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-grey.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-grey.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-grey.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-orange.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-orange.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-orange.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-orange.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-red.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-red.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-red.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-red.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-violet.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-violet.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-violet.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-violet.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-icon-yellow.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-yellow.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-icon-yellow.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-icon-yellow.png diff --git a/services/website_dashboard/app/static/leaflet/img/marker-shadow.png b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-shadow.png similarity index 100% rename from services/website_dashboard/app/static/leaflet/img/marker-shadow.png rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/img/marker-shadow.png diff --git a/services/website_dashboard/app/static/leaflet/leaflet-color-markers.js b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-color-markers.js similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet-color-markers.js rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-color-markers.js diff --git a/services/website_dashboard/app/static/leaflet/leaflet-src.esm.js b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.esm.js similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet-src.esm.js rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.esm.js diff --git a/services/website_dashboard/app/static/leaflet/leaflet-src.esm.js.map b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.esm.js.map similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet-src.esm.js.map rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.esm.js.map diff --git a/services/website_dashboard/app/static/leaflet/leaflet-src.js b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.js similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet-src.js rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.js diff --git a/services/website_dashboard/app/static/leaflet/leaflet-src.js.map b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.js.map similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet-src.js.map rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet-src.js.map diff --git a/services/website_dashboard/app/static/leaflet/leaflet.css b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet.css similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet.css rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet.css diff --git a/services/website_dashboard/app/static/leaflet/leaflet.js b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet.js similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet.js rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet.js diff --git a/services/website_dashboard/app/static/leaflet/leaflet.js.map b/services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet.js.map similarity index 100% rename from services/website_dashboard/app/static/leaflet/leaflet.js.map rename to services/ansible_openvpn/docker/dashboard/app/static/leaflet/leaflet.js.map diff --git a/services/website_dashboard/app/static/moment.min.js b/services/ansible_openvpn/docker/dashboard/app/static/moment.min.js similarity index 100% rename from services/website_dashboard/app/static/moment.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/moment.min.js diff --git a/services/website_dashboard/app/static/placeholders.min.js b/services/ansible_openvpn/docker/dashboard/app/static/placeholders.min.js similarity index 100% rename from services/website_dashboard/app/static/placeholders.min.js rename to services/ansible_openvpn/docker/dashboard/app/static/placeholders.min.js diff --git a/services/website_dashboard/app/static/status.css b/services/ansible_openvpn/docker/dashboard/app/static/status.css similarity index 100% rename from services/website_dashboard/app/static/status.css rename to services/ansible_openvpn/docker/dashboard/app/static/status.css diff --git a/services/website_dashboard/app/static/status.js b/services/ansible_openvpn/docker/dashboard/app/static/status.js similarity index 93% rename from services/website_dashboard/app/static/status.js rename to services/ansible_openvpn/docker/dashboard/app/static/status.js index 93acf63..e7cc20c 100644 --- a/services/website_dashboard/app/static/status.js +++ b/services/ansible_openvpn/docker/dashboard/app/static/status.js @@ -77,19 +77,19 @@ var lmap = L.map('mapid').setView([47.7456, -3.3687], 16); var sensors = L.layerGroup(); var routers = L.layerGroup(); -L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', { +L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1Ijoibmljb2xhcy1mIiwiYSI6ImNsbTBhMTkxMTE3ODkzZHA2ZGM0NWVhb3EifQ.XLAxFMiFQD1VomPnHjcFAA', { maxZoom: 18, attribution: 'Map data © OpenStreetMap contributors, ' + 'CC-BY-SA, ' + 'Imagery © Mapbox', - id: 'mapbox.streets' + id: 'streets-v11' }).addTo(lmap); sensors.addTo(lmap); routers.addTo(lmap); -getStations(lmap, sensors); -getRouters(lmap, routers); +//getStations(lmap, sensors); +//getRouters(lmap, routers); var legend = L.control({position: 'bottomright'}); diff --git a/services/website_dashboard/app/templates/query.json b/services/ansible_openvpn/docker/dashboard/app/templates/query.json similarity index 100% rename from services/website_dashboard/app/templates/query.json rename to services/ansible_openvpn/docker/dashboard/app/templates/query.json diff --git a/services/ansible_openvpn/docker/dashboard/app/templates/query_sensor_list.json b/services/ansible_openvpn/docker/dashboard/app/templates/query_sensor_list.json new file mode 100644 index 0000000..ad9513e --- /dev/null +++ b/services/ansible_openvpn/docker/dashboard/app/templates/query_sensor_list.json @@ -0,0 +1,39 @@ +{ + "size": 0, + "fields": [ + "TPV.lat", + "TPV.lon", + "hwa", + "date" + ], + "aggs": { + "group": { + "terms": { + "field": "hwa.keyword", + "size": 200 + }, + "aggs": { + "results_without_mb_id": { + "filter": { + "exists": { + "field": "TPV.lat" + } + } + }, + "group_docs": { + "top_hits": { + "size": 1, + "_source": false, + "sort": [ + { + "date": { + "order": "desc" + } + } + ] + } + } + } + } + } +} diff --git a/services/website_dashboard/app/templates/query_sensor_record_count.json b/services/ansible_openvpn/docker/dashboard/app/templates/query_sensor_record_count.json similarity index 100% rename from services/website_dashboard/app/templates/query_sensor_record_count.json rename to services/ansible_openvpn/docker/dashboard/app/templates/query_sensor_record_count.json diff --git a/services/website_dashboard/app/templates/status.html b/services/ansible_openvpn/docker/dashboard/app/templates/status.html similarity index 96% rename from services/website_dashboard/app/templates/status.html rename to services/ansible_openvpn/docker/dashboard/app/templates/status.html index d4cc554..b05e6d5 100644 --- a/services/website_dashboard/app/templates/status.html +++ b/services/ansible_openvpn/docker/dashboard/app/templates/status.html @@ -2,6 +2,7 @@ + Live sensors map diff --git a/services/ansible_openvpn/docker/dashboard/requirements.txt b/services/ansible_openvpn/docker/dashboard/requirements.txt index 0c2f9f8..d9f1e10 100644 --- a/services/ansible_openvpn/docker/dashboard/requirements.txt +++ b/services/ansible_openvpn/docker/dashboard/requirements.txt @@ -1,2 +1,4 @@ fastapi>=0.103.0,<0.104.0 uvicorn>=0.23.2,<0.24 +Jinja2>=3.1.2,<3.2.0 +elasticsearch>=8.9.0,<8.10.0 diff --git a/services/ansible_openvpn/playbooks/deploy_elastic_web_dashboard.yml b/services/ansible_openvpn/playbooks/deploy_elastic_web_dashboard.yml index 4d58bff..66f20e1 100644 --- a/services/ansible_openvpn/playbooks/deploy_elastic_web_dashboard.yml +++ b/services/ansible_openvpn/playbooks/deploy_elastic_web_dashboard.yml @@ -8,10 +8,10 @@ tasks: - name: Create configuration file for website copy: - content: "[ELASTIC_SEARCH]\nURL = es01\nAPI_ID = {{ api_key_id }}\nAPI_KEY = {{ api_key }}\n" + content: "{\"id\":\"{{ api_key_id }}\",\"name\":\"python\",\"api_key\":\"Qk77qq1AR3WxkwbuQw_Jcw\",\"es_url\":\"https://es01\",\"verify_certs\":false}" dest: '{{ destination }}appconfig.ini' - name: Website synchronization ansible.posix.synchronize: mode: 'pull' - src: '{{ playbook_dir }}../../website_dashboard' + src: '{{ playbook_dir }}../docker/dashboard' dest: '{{ destination }}' diff --git a/services/ansible_openvpn/playbooks/files/scripts_elasticsearch/requirements.txt b/services/ansible_openvpn/playbooks/files/scripts_elasticsearch/requirements.txt index cd583e9..87cf856 100644 --- a/services/ansible_openvpn/playbooks/files/scripts_elasticsearch/requirements.txt +++ b/services/ansible_openvpn/playbooks/files/scripts_elasticsearch/requirements.txt @@ -1 +1 @@ -elasticsearch==8.9.0 +elasticsearch>=8.9.0,<8.10.0 diff --git a/services/website_dashboard/README.md b/services/website_dashboard/README.md deleted file mode 100644 index b532558..0000000 --- a/services/website_dashboard/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Dashboard website - -This frontend website is displaying the state and data of the sensor network. - -It is linked to an elastic-search instance that store and index the files -generated by zero_*.py services. - -This website and the backend is easily deployed if you are using the docker -services described in [ansible_openvpn](../ansible_openvpn) folder. \ No newline at end of file diff --git a/services/website_dashboard/app/__init__.py b/services/website_dashboard/app/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/services/website_dashboard/app/main.py b/services/website_dashboard/app/main.py deleted file mode 100644 index ce89071..0000000 --- a/services/website_dashboard/app/main.py +++ /dev/null @@ -1,45 +0,0 @@ -# BSD 3-Clause License -# -# Copyright (c) 2023, University Gustave Eiffel -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -from fastapi import FastAPI -from fastapi.responses import HTMLResponse -from fastapi.staticfiles import StaticFiles -from fastapi.templating import Jinja2Templates - -app = FastAPI() - -app.mount("/static", StaticFiles(directory="static"), name="static") - -templates = Jinja2Templates(directory="templates") - -@app.get('/', response_class=HTMLResponse) -async def home(): - return templates.TemplateResponse("status.html") - diff --git a/services/website_dashboard/app/templates/query_sensor_list.json b/services/website_dashboard/app/templates/query_sensor_list.json deleted file mode 100644 index 3b36f25..0000000 --- a/services/website_dashboard/app/templates/query_sensor_list.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "size": 0, - "aggs": { - "group": { - "terms": { - "field": "producerID", - "size" : 200 - }, - "aggs": { - "group_docs": { - "top_hits": { - "size": 1, - "sort": [ - { - "timestamp": { - "order": "desc" - } - } - ] - } - } - } - } - } -} diff --git a/services/website_dashboard/requirements.txt b/services/website_dashboard/requirements.txt deleted file mode 100644 index 0c2f9f8..0000000 --- a/services/website_dashboard/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -fastapi>=0.103.0,<0.104.0 -uvicorn>=0.23.2,<0.24