Разговорчивый сервер

Накидал себе небольшой скрипт на питоне который пингует мои сервера и отправляет сообщение на email об их состоянии

import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

hostname = "10.0.1.1"
response = os.system("ping -c 1 " + hostname)
hostname2 = "10.0.1.2"
response2 = os.system("ping -c 1 " + hostname2)
subj2 = ''
subj1 = ''
if response ==0:
    print(hostname, 'is up!')
    text1 = '10.0.1.1 is up\n'
    subj1 = 'server says OK'
else:
    print(hostname, 'is down!')
    text1 = '10.0.1.1 is down\n'
    subj1 = 'server says ALLERT'
if response2 ==0:
    print(hostname2, 'is up!')
    text2 = '10.0.1.2 is up'
    subj2 = 'server says OK'
else:
    print(hostname2, 'is down!')
    text2 = '10.0.1.2 is down'
    subj2 = 'server says ALLERT'

me = 'example@mail.ru'
you = 'example@mail.ru'
text = text1 + text2
subj = subj2 + subj1
server = "smtp.mail.ru"
port = 25
user_name = "example@mail.ru"
user_passwd = "password"
msg = MIMEText(text, "", "utf-8")
msg['Subject'] = subj
msg['From'] = me
msg['To'] = you
s = smtplib.SMTP(server, port)
s.ehlo()
s.starttls()
s.ehlo()
s.login(user_name, user_passwd)
s.sendmail(me, you, msg.as_string())
s.quit()
[YadiskFiles label=»Скачать autopinger.py с Яндекс.Диск» href=»https://yadi.sk/d/b7fYl5GojQv2a» name=»autopinger.py» size=»1.1 KB» path_hash=»4b975e4e1fcc7682a6af7e2703c6aea9″ counter=»true»]

пользуйтесь на здоровье..