Author Topic: weewx extension to send notification if the station goes offline  (Read 2730 times)

0 Members and 1 Guest are viewing this topic.

Offline uajqq

  • Member
  • *
  • Posts: 28
weewx extension to send notification if the station goes offline
« on: December 28, 2021, 01:38:18 PM »
I created a simple extension that sends a ping to healthchecks.io with every weewx archive interval. That way, you can receive a notification whenever the station goes offline for a certain length of time. Notifications can be emails, text messages, even phone calls. Let me know what you think:

https://github.com/uajqq/weewx-healthchecks

Offline zoomx

  • Senior Contributor
  • ****
  • Posts: 210
Re: weewx extension to send notification if the station goes offline
« Reply #1 on: December 31, 2021, 12:25:28 PM »
Next year I will test it! Thanks!

Offline vrishabkakade

  • Member
  • *
  • Posts: 3
    • Betta Weather Reports
Re: weewx extension to send notification if the station goes offline
« Reply #2 on: October 31, 2024, 03:41:05 AM »
Thank you so much for this extension. I have been using it successfully.

Can you please tell me how I can customize it to use it with custom alerts? For example, I want to be able to automatically execute a restart script if weewx crashes.

Offline uajqq

  • Member
  • *
  • Posts: 28
Re: weewx extension to send notification if the station goes offline
« Reply #3 on: October 31, 2024, 07:14:59 PM »
You could get the source code from GitHub and modify it. Basically you erase what I have and would put whatever you want to happen within the “send_ping” function:

def send_ping(self):
    [your stuff]


But that’s running within weewx, so it won’t do much good if weewx itself crashes. You’d have to set Healthchecks or something similar to run the script itself, or notify your server to run the script. I’m not sure how you’d do that.

Offline davidmc36

  • He who dies with the most toys wins!
  • Forecaster
  • *****
  • Posts: 1335
  • FN25IE61IX
    • MorewoodW34
Re: weewx extension to send notification if the station goes offline
« Reply #4 on: October 31, 2024, 09:08:51 PM »
Righteous.

I just set up MB to ping every hour when my email notice goes out. I set up the email a while back to monitor its status. But you have to remember to check it.

So now I will get notice if it fails. Sweet.

I can just change the frequency of the email and keep closer tabs if need be.

Offline vrishabkakade

  • Member
  • *
  • Posts: 3
    • Betta Weather Reports
Re: weewx extension to send notification if the station goes offline
« Reply #5 on: October 31, 2024, 09:27:14 PM »
I see the code is supposed to be writing to a log file, but I couldn't find anything in journal (I'm running weewx on a raspberry pi) where weewx writes the logs.
Perhaps I could write a "ping success" message with timestamp to a file.
I can then check the file from a shell script and take appropriate action if the file hasn't been written for more than 5 minutes.
 

Offline vrishabkakade

  • Member
  • *
  • Posts: 3
    • Betta Weather Reports
Re: weewx extension to send notification if the station goes offline
« Reply #6 on: October 31, 2024, 09:48:03 PM »
I'm running a few checks from a shell script and restart weewx if it crashes. Perhaps, it would be more elegant if I can check the pings from notify and take action instead.

# Script to restart weewx when it goes down
ps -ef | grep weewxd | grep -v color | grep -v grep >> restart_weewx.log
output=`echo $?`
echo "Output of checking process: $output" >> restart_weewx.log

if [ $output -eq 0 ]
then
  echo "Weewx is already running" >> restart_weewx.log
  # Additional check as sometimes it crashes and the process remains. The service also shows the state as running. The only way to know if a
  # crash has occured is to see a message such as "CRITICAL __main__:     ****  Exiting..."
  sudo systemctl status weewx | grep -i Exiting
  if [ `echo $?` -eq 1 ]
  then
  echo "Weewx has not crashed" >> restart_weewx.log
  else
  echo "Weewx has crashed...restarting" >> restart_weewx.log
  sudo systemctl restart weewx
  fi
  echo "" >> restart_weewx.log
else
  echo "Weewx is down. Starting it" >> restart_weewx.log
  sudo systemctl restart weewx >> restart_weewx.log
  echo "" >> restart_weewx.log
fi

 

anything