-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck2.py
53 lines (46 loc) · 1.8 KB
/
check2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import commands
import time
from twilio.rest import TwilioRestClient
#output = commands.getoutput('ps -A')
failservice = ""
#Twilio credentials
account_sid = ""
auth_token = ""
client = TwilioRestClient(account_sid, auth_token)
twilio_number = "+44"
auth_number = "+44"
services = ["apache2", "sshd"]
status = 1
def status1():
global status
global failedservice
global client
while status == 1:
time.sleep(2)
for service in services:
output = commands.getoutput('ps -A')
if service in output:
print(service + " is up an running!")
else:
print(service + " is NOT running")
status = 0
failedservice = service
smsbody = "Hi Jordi, I'm your server! Sorry to bother you but " + failedservice + " has been stopped unexpectedly -- Reply 'service " + failedservice + " start' if you want to restart the service"
message = client.messages.create(to=auth_number, from_=twilio_number, body=smsbody)
break
def status0():
global status
global failedservice
while status == 0:
print ("Waiting")
time.sleep(3)
output = commands.getoutput('ps -A')
if failedservice not in output:
pass
else:
smsbody = failedservice + " is working again."
message = client.messages.create(to=auth_number, from_=twilio_number, body=smsbody)
status = 1
status1()
status1()
status0()