[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: www site monitor

On Fri, Feb 10, 2012 at 05:29:02PM +0000, pch0317 wrote:
> Hi list,
> I must monitor remote site to check that it works. I refresh this
> site from time to time in web browser. Can I automate this process?
> I search for service which:
> - monitors *remote* WWW site (via http request)
> - when remote site doesn't respond for example 5 minutes it notify
> some person (via e-mail or SMS).
> Is that service available in Debian repository? Or is there any
> commercial product which do that?

assume you have a local working smtp server, let's check if debian is
online by running following script from cron.

#!/usr/bin/env python
import urllib2
import cookielib

URL = 'http://www.debian.org/'

def browser():
    cj = cookielib.CookieJar()
    cookie_support = urllib2.HTTPCookieProcessor(cj)
    opener = urllib2.build_opener(urllib2.HTTPHandler, cookie_support)
    return opener

def sendmail(subject, msgbody):
    '''send mail to gmail via a working local exim4'''
    import smtplib
    from email.mime.text import MIMEText
    msg = MIMEText(msgbody)
    from_addr = 'my_address'
    dest_addr = 'man_on_duty'
    msg['Subject'] = subject
    msg['From'] = from_addr
    msg['To'] = dest_addr
    s_obj = smtplib.SMTP('localhost')
    s_obj.sendmail(from_addr, dest_addr, msg.as_string())
    print 'Successfully sent mail to {0}'.format(dest_addr)

def main(url):
    brs = browser()
        site = brs.open(url)
    except urllib2.URLError:
        sendmail('datacenter on fire?')
    except urllib2.HTTPError:
        sendmail('or under water')

if __name__ == "__main__":

Chen Wei

Reply to: