2 Commits
1.0.0 ... 1.0.2

Author SHA1 Message Date
58f17be962 fix 2023-11-09 18:04:05 +01:00
0eb133cede fix 2023-11-09 17:57:55 +01:00
6 changed files with 85 additions and 24 deletions

View File

@ -3,7 +3,7 @@ FROM python:3.10-bullseye
ENV MQTT_LOGIN "-"
ENV MQTT_PASSWORD "-"
ENV MQTT_BROKER "-"
ENV MQTT_PORT "8883"
ENV MQTT_PORT "1883"
ENV MQTT_CA ""
ENV PGHOST ""

11
deployment/install.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
NAMESPACE=$(cat namespace)
~/Workspace/MyKubernetesEnv/tools/create-namespace.sh $NAMESPACE
./roll-db-credential.sh
kubectl -f install.yml -n $NAMESPACE apply

36
deployment/install.yml Normal file
View File

@ -0,0 +1,36 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cemmetering
data:
MQTT_BROKER: "emqx01-anonymous-cluster-internal.broker.svc.cluster.local"
MQTT_PORT: "1883"
PGDATABASE: "cem_monitoring_berresheim"
PGHOST: "timescaledb.database.svc.cluster.local"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cemmetering
labels:
app: cemmetering
spec:
replicas: 1
selector:
matchLabels:
app: cemmetering
template:
metadata:
labels:
app: cemmetering
spec:
containers:
- name: cemmetering
image: wollud1969/cemmetering-preprocessor:1.0.1
envFrom:
- configMapRef:
name: cemmetering
- secretRef:
name: cemmetering-db-cred

1
deployment/namespace Normal file
View File

@ -0,0 +1 @@
berresheim

View File

@ -0,0 +1,33 @@
#!/bin/bash
. ~/Workspace/MyKubernetesEnv/ENVDB
DATABASE=cem_monitoring_berresheim
LOGIN=cem_preprocessor
PASSWORD=`openssl rand -base64 24`
NAMESPACE=`cat namespace`
psql <<EOF
do
\$\$
begin
if not exists (SELECT * FROM pg_user WHERE usename = '$LOGIN') then
CREATE USER $LOGIN WITH PASSWORD '$PASSWORD';
else
ALTER USER $LOGIN WITH PASSWORD '$PASSWORD';
end if;
end
\$\$
;
commit;
EOF
kubectl create secret generic cemmetering-db-cred \
--dry-run=client \
-o yaml \
--save-config \
--from-literal=PGUSER="$LOGIN" \
--from-literal=PGPASSWORD="$PASSWORD" | \
kubectl apply -f - -n $NAMESPACE

View File

@ -29,7 +29,7 @@ class JustIgnoreMessage (Exception):
self.message = message
class DbOp(object):
def __init__(self, config):
def __init__(self):
self.conn = None
def __getConn(self):
@ -125,7 +125,7 @@ def mqttOnMessageCallback(client, userdata, message):
(appId, converterId, deviceId, variableId) = splitTopic(topic)
dbh = DbOp(config)
dbh = DbOp()
variable = dbh.getVariable(appId, converterId, deviceId, variableId)
measurement = {
"vid": variable["vid"],
@ -150,21 +150,6 @@ logger.info("preprocess starting")
REQUIRED_CONFIG_OPTIONS = [
'MQTT_LOGIN',
'MQTT_PASSWORD',
'MQTT_BROKER',
'MQTT_PORT',
'MQTT_CA'
]
config = {}
for rco in REQUIRED_CONFIG_OPTIONS:
try:
config[rco] = os.environ[rco]
except KeyError:
logger.error(f"{rco} is a required config option, not available in environment")
sys.exit(-1)
@ -172,12 +157,7 @@ client = mqtt.Client()
client.on_message = mqttOnMessageCallback
client.on_connect = mqttOnConnectCallback
client.on_disconnect = mqttOnDisconnectCallback
client.username_pw_set(config['MQTT_LOGIN'], config['MQTT_PASSWORD'])
client.tls_set(
cert_reqs=ssl.CERT_REQUIRED,
ciphers=None
)
client.connect(config["MQTT_BROKER"], int(config["MQTT_PORT"]))
client.connect(os.environ["MQTT_BROKER"], int(os.environ["MQTT_PORT"]))
#client.connect('172.16.2.16', 1883)
logger.info("mqtt loop starting")
client.loop_forever()