Skip to content

Instantly share code, notes, and snippets.

@adeekshith
Forked from eriwen/gist:187610
Last active September 19, 2024 13:11
Show Gist options
  • Save adeekshith/fef4ff9949b88ce102bd to your computer and use it in GitHub Desktop.
Save adeekshith/fef4ff9949b88ce102bd to your computer and use it in GitHub Desktop.
Scripts for website monitoring using Python
import pickle, pprint, time, os
if os.path.isfile('data.pkl'):
pklFile = open('data.pkl','rb')
data1 = pickle.load(pklFile)
pprint.pprint(data1)
elapsedTime = time.time() - data1['timestamp']
elapsedMinutes = elapsedTime/60
if elapsedMinutes > 2:
print 'It\'s been longer than two minutes'
else:
data1 = {}
def isSiteup(urls):
import httplib
data = {}
data['timestamp'] = time.time()
for url in urls:
conn = httplib.HTTPConnection(url)
conn.request("HEAD", "/")
res = conn.getresponse()
data[url] = res.status
print res.status, res.reason, url
if url in data1:
if data1[url] != res.status:
print url, 'has changed from', data1[url], 'to', res.status
print 'Sending an email!'
else:
print url, 'is still the same', data1[url], 'and', res.status
output = open('data.pkl','wb')
pickle.dump(data, output)
output.close()
urls = ['www.sfrcorp.com',
'www.nixtutor.com',
'www.marksanborn.net',
'faceoffshow.com',
'rocketship.it',
'jaderobbins.com']
isSiteup(urls)
#pklFile.close()
@Mutale85
Copy link

I am new to python. Can this script send an email when the site is down?

@sesseor
Copy link

sesseor commented Mar 8, 2021

I am new to python. Can this script send an email when the site is down?

yes it does send email when the website is down

@xanorbkid
Copy link

can this script check the total active users on the website??

@sesseor
Copy link

sesseor commented Dec 18, 2022

can this script check the total active users on the website??

nope

@TinkuSandeep
Copy link

can this script monitor HTTPS connections also?

@TinkuSandeep
Copy link

what is we have multiple websites to moniot at a time?how can we do it with this script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment