Skip to content
Merged
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
6 changes: 5 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'''Module containing the main function of the app.'''
import os
import socket
from flask import Flask, Response
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST
from app import opensense
from app import storage

app = Flask(__name__)

HOSTNAME = socket.gethostname()
IPADDR = socket.gethostbyname(HOSTNAME)

@app.route('/version')
def print_version():
'''Function printing the current version of the app.'''
Expand All @@ -20,7 +24,7 @@ def print_version():
@app.route('/temperature')
def get_temperature():
'''Function to get the current temperature.'''
return opensense.get_temperature()
return opensense.get_temperature() + f"From: {IPADDR}\n"

@app.route('/metrics')
def metrics():
Expand Down
6 changes: 1 addition & 5 deletions app/opensense.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
'''Module to get entries from OpenSenseMap API and get the average temperature'''
from datetime import datetime, timezone, timedelta
import os
import socket
import requests
import redis

HOSTNAME = socket.gethostname()
IPADDR = socket.gethostbyname(HOSTNAME)

REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))
REDIS_DB = int(os.environ.get('REDIS_DB', 0))
Expand Down Expand Up @@ -85,4 +81,4 @@ def get_temperature():
except redis.RedisError as e:
print(f"Redis error while caching data: {e}")

return result + f"From: {IPADDR}\n"
return result
2 changes: 1 addition & 1 deletion tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_store_temperature_data_invalid_response_error():
mock_client.bucket_exists.return_value = True
mock_client.put_object.side_effect = InvalidResponseError(
"Invalid response",
content_type="application/json",
content_type="application/json",
body=b"{}"
)

Expand Down