Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# iot-clouds
## Creating Logs, configuring Metrics and Alarms
7 changes: 7 additions & 0 deletions lab4-flask_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.6.1-alpine
RUN pip install --upgrade pip
WORKDIR /code
COPY requirements.txt /code
RUN pip install -r requirements.txt --no-cache-dir
COPY . /code
CMD ["python", "app.py"]
30 changes: 30 additions & 0 deletions lab4-flask_app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from flask import Flask, render_template, request

import logging
import datetime

app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)
PASSWORD = "0000"


@app.route('/')
def hello_world():
return render_template('index.html', utc_dt=datetime.datetime.utcnow())


@app.route('/login', methods=["GET", "POST"])
def login():
if request.method == "POST":
password = request.form.get("fpassword")
if password == PASSWORD:
app.logger.info("User logged successfully")
return render_template('login_success.html', utc_dt=datetime.datetime.utcnow())
else:
app.logger.error("Failed to log in")
return render_template('login_fail.html', utc_dt=datetime.datetime.utcnow())
return render_template('login.html')


if __name__ == '__main__':
app.run(host='0.0.0.0')
10 changes: 10 additions & 0 deletions lab4-flask_app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '2.8'
services:
lab4-flask:
build: .
image: lab4-flask-app
container_name: lab4-flask
ports:
- "5000:5000"
volumes:
- .:/code
1 change: 1 addition & 0 deletions lab4-flask_app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==2.0.3
27 changes: 27 additions & 0 deletions lab4-flask_app/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %} {% endblock %} - FlaskApp</title>
<style>
nav a {
color: black;
font-size: 3em;
margin-left: 100px;
text-decoration: black;
font-family: "Times New Roman", serif;
}
</style>
</head>
<body style="background-color: white">
<nav style="align-content: center; justify-content: center; margin: 0 0 0 25%">
<a href="{{ url_for('hello_world') }}">Flask App</a>
<a href="{{ url_for('login') }}">Login</a>
</nav>
<hr>
<div class="content">
{% block content %} {% endblock %}
</div>

</body>
</html>
9 changes: 9 additions & 0 deletions lab4-flask_app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.html' %}

{% block content %}

<h1>{% block title %} Cloud lab 4 :) {% endblock %}</h1>
<h2> Creating logs. Metrics and Alarms </h2>
<h3>{{ utc_dt }}</h3>

{% endblock %}
17 changes: 17 additions & 0 deletions lab4-flask_app/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'base.html' %}

{% block content %}
<h1 style="margin: 0 0 0 7%">{% block title %} Try it out {% endblock %}</h1>

<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSjq8zJTmjUBUUVr0k3EPI13obVsJaBuB_7pA&usqp=CAU"
style="width:300px;height:200px;margin: 20px">

<form action="{{ url_for("login")}}" method="post">
<label for="password" style="font-family: 'Times New Roman',serif;
font-size: 20px; margin: 50px 10px">Password:</label>
<input type="text" id="password" name="fpassword" placeholder="enter 4-num password" style="width: 20%;
margin: 8px 10px; box-sizing: border-box;">
<button type="submit" style="background-color: whitesmoke; border: none; font-family: 'Times New Roman',serif;
padding: 7px 12px; text-align: center; font-weight: bold; text-decoration: none;border-radius: 12px;">Submit</button>
</form>
{% endblock %}
8 changes: 8 additions & 0 deletions lab4-flask_app/templates/login_fail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}

{% block content %}
<h1 style="font-family: 'Times New Roman',serif; text-align: center;
background-color: indianred">{% block title %} Oops, try again! {% endblock %}</h1>
<h3>Password is incorrect</h3>
<h3>{{ utc_dt }}</h3>
{% endblock %}
7 changes: 7 additions & 0 deletions lab4-flask_app/templates/login_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends 'base.html' %}

{% block content %}
<h1 style="font-family: 'Times New Roman',serif; color: black; background-color: darkseagreen; text-align: center;
background-size: auto"> {% block title %} Success, whoo! {% endblock %}</h1>
<h3>{{ utc_dt }}</h3>
{% endblock %}
10 changes: 10 additions & 0 deletions task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Лабораторна робота 4
## Створення Logs, налаштування Metrics та Alarms

### Завдання
- Розробити інтерфейс логування для користувача у вашу аплікацію (розроблену в завданні 2)
- Налаштувати логування. В логах необхідно зберігати дані про вдалий вхід користувача. У разі помилки входу (неправильний пароль чи логін) слід логувати помилку
- Налаштувати Stackdriver Monitoring (GCP) / Unified CloudWatch Agent або AWS CloudWatch Log (AWS) / Azure Monitor (Azure) для вашої аплікації
- Налаштувати тривожні повідомлення (аларми), вказати умови спрацювання Аларма і адресат повідомлення про невдале логування(наприклад email).
- Налаштувати час зберігання логів або їх кількість.
- Здійснити навігацію на сайт та в браузері ввести адресу сторінки, якої немає на сайті. Здійснити спробу невдалого логування на сайт та перевірити надходження повідомлення на електронну пошту