jamslights
Posts: 4
Joined: Mon May 18, 2020 5:29 pm

Pi to monitor server online status

Mon May 18, 2020 5:41 pm

Hello all,

I am looking to make a pi project. I work in 2 offices and I have a windows server at one location. I don't go to this location office. Occasionally this server crashes or goes down and I don't know about it for a day or so and that poses an issue. I would like to setup the raspberry pi to ping the server (open port I have enabled) at a set interval, say 30 mins or every hour, and if it is not responding to a ping, send me a text message. Worse case scenario, send me an email alert. Any suggestions on how I can accomplish this? Both office locations have internet. The pi will be at one office and the server at the other. Thank you!


pcmanbob
Posts: 9254
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi to monitor server online status

Tue May 19, 2020 11:33 am

deepo wrote:
Mon May 18, 2020 8:33 pm
Maybe a little bit of this:
https://weworkweplay.com/play/rebooting ... tion-wifi/
And this:
https://raspberry-projects.com/pi/softw ... end-emails

/Mogens
SSMPT will not work on buster you have to use MSMTP as a replacement
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

jamslights
Posts: 4
Joined: Mon May 18, 2020 5:29 pm

Re: Pi to monitor server online status

Tue May 19, 2020 7:48 pm

Thanks for the information, I will give this a try!

jamslights
Posts: 4
Joined: Mon May 18, 2020 5:29 pm

Re: Pi to monitor server online status

Wed May 20, 2020 2:24 am

I've tried to write something to help with my scenario, and I think the below posts put me in the right direction, but not having any coding experience, is anyone able to help me write a quick script for my scenario? Thank you!

deepo
Posts: 574
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Pi to monitor server online status

Wed May 20, 2020 7:50 pm

How far have you come?
Are you able to create the checkwifi.sh script in the first link?
Are you able to add the script to cron?
You won't want to implement the reboot and ifdown/ifup features, that's where you want to add sending an email.
I haven't worked with MSMTP so I'm afraid I can only link to another guide:
https://www.techrapid.uk/2017/04/send-e ... msmtp.html

/Mogens

User avatar
TideMan
Posts: 259
Joined: Fri Jun 22, 2012 8:08 am
Location: ChCh, NZ

Re: Pi to monitor server online status

Wed May 20, 2020 9:20 pm

I've just been playing with MSMTP using gmail as the mail server.
But I had problems getting gmail to accept my password.
It gets its knickers in a twist about an insecure app trying use the account.

Then I discovered the concept of "16-character app passwords" here:
https://support.google.com/accounts/ans ... authuser=2

Once I generated such a password and inserted it in /etc/msmtprc, it all worked!

I hope this info is useful to others trying to use MSMTP with gmail.

pcmanbob
Posts: 9254
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi to monitor server online status

Thu May 21, 2020 8:23 am

The other option is to just enable less secure apps on gmail,

this is what I do as I have separate accounts for use by my pi's with random character passwords.

there is an entire thread about using and setting up MSMTP on your pi using buster.

viewtopic.php?f=28&t=244147#p1517480
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

jamslights
Posts: 4
Joined: Mon May 18, 2020 5:29 pm

Re: Pi to monitor server online status

Thu May 21, 2020 12:54 pm

Thanks for the Gmail suggestions, I will give that a try. I am still working on my project.

pcmanbob
Posts: 9254
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi to monitor server online status

Thu May 21, 2020 3:03 pm

Once you have MSMTP and mailutils installed and working you simply need a short bash script like this

Code: Select all

#!/bin/bash

# Check server status

ping -c2 192.168.1.1 # change this to your server IP address

 
if [ $? != 0 ] 
then 
  
  echo "Alert Server down" | mail -s "Alert Server down" recipientname@domain.com
    
else
    echo "Server OK"
    
fi
run every few minutes using cron.

you will need to change the IP address to that of your server, and replace the recipientname@domain.com with an actual email address.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Networking and servers”