-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_and_send.py
More file actions
49 lines (44 loc) · 1.19 KB
/
check_and_send.py
File metadata and controls
49 lines (44 loc) · 1.19 KB
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
#!/usr/bin/env python
#coding=utf8
import subprocess
import time
import smtplib
import sys
def myrun(cmd):
""" Method for input information from cmd
it's file which checke interface
if interfaces is down we use method mail
"""
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout = []
while True:
line = p.stdout.readline()
stdout.append(line)
#print line
ph1 = line[9:19]
#print (ph1)
if ph1 == 'no carrier':
mail("NOT WORKING")
time.sleep(60)
def mail(txtparam):
"""
fromaddr - send address
toaddr - receiver address
username - your email
pass - your pass from email
msg_txt - input error message from first method
"""
fromaddr = 'Mr. Robot <fromaddr@example.com>'
toaddr = 'Administrator <toaddr@example.com>'
subj = 'Notification from system'
msg_txt = txtparam
msg = "From: %s\nTo: %s\nSubject: %s\n\n%s" % ( fromaddr, toaddr, subj, msg_txt)
username = 'example@example.com'
password = 'pass from example@example.com'
server = smtplib.SMTP('smtp.gmail.com:587')
server.set_debuglevel(1);
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddr, msg)
server.quit()
myrun("/data/check/check.sh")