so I am a Python newbie attempting to write a script that will light up a different LED based on the priority level of the latest security alert added to a log file generated by the Suricata Intrusion Detection System... The issue with the script I have now is that it will only read the last log that has been generated before the script is run and light up the according to LED, but not light up different LEDs as more alerts with different levels are added to the log:
from gpiozero import LED
from time import sleep
with open("fast.log") as f:
last_row = f.readlines()[-1]
if "[Priority: 2]" in last_row:
led = LED(18)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
elif "[Priority: 3]" in last_row:
led = LED(23)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
elif "[Priority: 1]" in last_row:
led = LED(21)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
I am running the script in the background via python3 script.py &
(b) Accelero Q&A: https://raspberrypi.stackexchange.com/questions/106954/is-there-a-motion-location-sensor-for-rpi-python. By the way, GpioZero is actually a declarative style program. You need to understand the basic declarative style correctly/fully appreciate/make use of it. More about GpioZero's declarative style leter, ... Cheers.
– tlfong01 Jan 08 '20 at 02:27