0

A startup has a website that must run 0/24. The datacenter is not notifying us on outages, and even if it would, relying on a single entity doesn’t feel safe.

The idea is writing a script that monitors the website and rings my iPhone in case of any problem. It doesn’t have to be call ring. Any sound would do. It must bypass the "don’t disturb me" mode.

It’ easy to make calls or send SMSs from Mac OS X Yosemite when there is an iPhone attached to the Apple ID. However, ringing the iPhone itself, especially from command line seems to be less trivial.

I’d like to avoid using third party software (including VoiP providers) if possible as more layers and more software means more bugs. Also, I would never give away my Apple ID password to 3rd parties.

There are few ideas so far.

  1. Find my iPhone. It bypasses not only the don’t disturb me mode but any plugged in headphones too. That’s great. Is there a way to natively execute it from the Mac or somehow call it through Apple? Writing a REST application for this wouldn’t be a problem if there is an official interface. I thought about using browser emulation (Capybara + Webkit) that would log into my iCloud account and press the "Ring my phone" button but I find this fragile and unreliable. I just tried manually and it was like 5 clicks on a HTML5 interface that can be changed by Apple anytime.

  2. As far as I know Skype accepts command line arguments on Linux and Windows only. If it still does at all. Otherwise, it could be a solution. It’s a 3rd party software, however, I didn’t have to provide my Apple ID, and I thought it might be reliable. The problem is that I don’t like to have Skype running on my Macs at all.

  3. Even being able to send a couple of SMS to myself would be better than nothing. Can I somehow do that with iMessage and command line?

I think I’d prefer the find my iPhone as it is the most reliable to make sound, but any idea is welcome.

Martina Mózes
  • 461
  • 4
  • 3
  • You can send SMSs programatically, yes. See [this](https://apple.stackexchange.com/questions/162598/programmatically-send-text-message-through-messages-app-on-os-x-10-10) and [this](https://stackoverflow.com/questions/11812184/how-to-send-an-imessage-text-with-applescript-only-in-provided-service) for quick examples. Might not work for messaging yourself, though. Also, keep in mind Do Not Disturb can be easily bypassed by [adding a number to favourites or allowing repeated calls to go through](http://cdn.cultofmac.com/wp-content/uploads/2014/04/Do-Not-Disturb.jpg). – user137369 Jun 07 '16 at 13:17

2 Answers2

0

Write a script that pings your server ip from your Mac. With the serverfail function set it up to send you email to your phone. The example included uses a python script for sending you a message through gmail. Just a quick working example... .

Make the serverup.sh script executable, create a cronjob on your Mac to run this program as many times a day minute hour you feel is necessary.. and then in the event that your server goes down you will be notified. Here are the 2 files. serverup.sh and serverfail.py

#!/bin/bash

function serverup {
    target=000.000.0.000 #this is your server ip address
   /sbin/ping -c 1 $target > /dev/null  # run the ping command
   if [ $? -eq 0 ]; then     
itsup
else
serverfail

fi 

}

itsup() {
echo "its up" # or whatever you want this to do
}

serverfail() {
python ~/Desktop/server_scripts/serverfail.py
}

serverup

And then from here you can write a serverfail.py script which you have placed on your Desktop in a folder called server scripts.

Get yourself a new gmail account for just sending server messages

fill in your new username, password, gmail account, email of the email address to send the message to..

Here is a simple python script you can use.

#!/usr/bin/python

import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("gmail_username", "gmail_passwd")

msg = "Server Down!"
server.sendmail("yourgmail@gmail.com",    "the_email_you_want_to_send_to@email.com", msg)
server.quit()
Loonbox
  • 48
  • 5
  • Unfortunately, this is 3rd party and not reliable. I sent an SMS to myself ten minutes ago and I haven’t received it. (International number, however, my provider is listed as "Supported international carrier"). Also, SMS has the lowest chance to bypass the don’t disturb me mode and wake me up in the night. – Martina Mózes Dec 10 '15 at 18:34
  • I updated my answer to include a python script and a gmail example – Loonbox Dec 10 '15 at 19:21
0

If you're willing to use a service such as Twilio, you can make calls or send SMS through their API and use that api from the command line.

Place a Twilio Call from the Shell

Send a Twilio SMS from the Shell

However, I wouldn't recommend creating your own monitoring/notification solution because you're just creating more things that can fail and therefore also need to be monitored. Better use a third party monitoring solution such as WDT.io. On your iPhone, create a VIP contact for the email address of that service. And then you can change the alert on your iPhone for that VIP (under Settings>Notifications>Mail I believe).