Compare commits
2 Commits
project/sh
...
project/sh
| Author | SHA1 | Date | |
|---|---|---|---|
| 121bd007b3 | |||
| db63eb6d79 |
@@ -16,6 +16,8 @@ def connect_mqtt(broker, port):
|
|||||||
print("Failed to connect {broker}:{port}, return code %d\n", rc)
|
print("Failed to connect {broker}:{port}, return code %d\n", rc)
|
||||||
exit(rc) # Stop execution
|
exit(rc) # Stop execution
|
||||||
|
|
||||||
|
logging.info(f"Acting as USER_ID = {config.USER_ID}")
|
||||||
|
|
||||||
client = mqtt_client.Client()
|
client = mqtt_client.Client()
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.connect(broker, port)
|
client.connect(broker, port)
|
||||||
@@ -29,13 +31,14 @@ def publish(client, topic, datasource):
|
|||||||
data = datasource.read()
|
data = datasource.read()
|
||||||
msg = AggregatedDataSchema().dumps(data)
|
msg = AggregatedDataSchema().dumps(data)
|
||||||
result = client.publish(topic, msg)
|
result = client.publish(topic, msg)
|
||||||
logging.info(f"Published to {topic}: {msg[:50]}...")
|
logging.debug(f"Published to {topic}: {msg[:50]}...")
|
||||||
status = result[0]
|
status = result[0]
|
||||||
if status != 0:
|
if status != 0:
|
||||||
print(f"Failed to send message to topic {topic}")
|
logging.error(f"Failed to send message to topic {topic}")
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
logging.basicConfig(level = logging.INFO)
|
||||||
# Prepare mqtt client
|
# Prepare mqtt client
|
||||||
client = connect_mqtt(config.MQTT_BROKER_HOST, config.MQTT_BROKER_PORT)
|
client = connect_mqtt(config.MQTT_BROKER_HOST, config.MQTT_BROKER_PORT)
|
||||||
# Prepare datasource
|
# Prepare datasource
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
print("Checking for dead containers...")
|
print("Checking for dead containers...")
|
||||||
|
|
||||||
@@ -14,6 +15,9 @@ for i in statuses:
|
|||||||
if not i[status_index:].startswith("Up "):
|
if not i[status_index:].startswith("Up "):
|
||||||
service_name = i[name_index:]
|
service_name = i[name_index:]
|
||||||
print(f"Crash detected in {service_name}")
|
print(f"Crash detected in {service_name}")
|
||||||
|
print(f"docker logs for the container:\n")
|
||||||
|
os.system(f"docker logs {i.split(' ')[0]}")
|
||||||
|
print()
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
|
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|||||||
Reference in New Issue
Block a user