Monitoring and alerting | Monitoring USB device availability
A simple script is checking if the Smart Steppers are connected by USB.
vim /opt/monitorUSBdevices.sh
#!/bin/bash
while true; do
A_MOT=$(ls -alF /dev |grep "ttyUSB-SMART-A-AXIS")
B_MOT=$(ls -alF /dev |grep "ttyUSB-SMART-B-AXIS")
C_MOT=$(ls -alF /dev |grep "ttyUSB-SMART-C-AXIS")
D_MOT=$(ls -alF /dev |grep "ttyUSB-SMART-D-AXIS")
DUET=$(ls -alF /dev |grep "ttyUSB-DUET2ETHERNET")
WEBCAM=$(ls -alF /dev |grep "ttyUSB-LOGITECH-C920")
HUB=$(ls -alF /dev |grep "ttyUSB-MINI-4PORT-HUB")
if [[ ! -z $A_MOT ]]; then
A_AVAIL=1
else
A_AVAIL=0
fi
if [[ ! -z $B_MOT ]]; then
B_AVAIL=1
else
B_AVAIL=0
fi
if [[ ! -z $C_MOT ]]; then
C_AVAIL=1
else
C_AVAIL=0
fi
if [[ ! -z $D_MOT ]]; then
D_AVAIL=1
else
D_AVAIL=0
fi
if [[ ! -z $DUET ]]; then
DUET_AVAIL=1
else
DUET_AVAIL=0
fi
if [[ ! -z $WEBCAM ]]; then
WEBCAM_AVAIL=1
else
WEBCAM_AVAIL=0
fi
if [[ ! -z $HUB ]]; then
HUB_AVAIL=1
else
HUB_AVAIL=0
fi
curl -k -XPOST "http://localhost:8086/write?db=trikarus" --data-binary "usb_devices,host=hangdevice.fablabchemnitz.de a_avail=${A_AVAIL},b_avail=${B_AVAIL},c_avail=${C_AVAIL},d_avail=${D_AVAIL},duet_avail=${DUET_AVAIL},webcam_avail=${WEBCAM_AVAIL},hub_avail=${HUB_AVAIL}" --user user:password
sleep 1
done
chmod +x /opt/monitorUSBdevices.sh
vim /opt/monitorUSBdevices.service
[Unit]
After=network.target
Description=USB device availability Monitoring Service
[Service]
Type=simple
ExecStart=/opt/monitorUSBdevices.sh
KillMode=process
Restart=on-failure
RestartSec=10
RemainAfterExit=no
User=root
Group=root
[Install]
WantedBy= multi-user.target
systemctl enable /opt/monitorUSBdevices.service
service restart monitorUSBdevices && journalctl -f -u monitorUSBdevices.service
Keine Kommentare vorhanden
Keine Kommentare vorhanden