def notify(abnormal, hostname, ip_address, options, subject): log = Logger().get_logger() if "mail" in options: ps_names = "<br>".join(abnormal) mail = Mail() mail.send_mail("<>", get_emails(), [], "[" + ip_address + "] " + subject, ps_names, None) log.info("[mail] %s %s %s %s" % (get_emails(), ip_address, subject, ps_names)) if "syslog" in options: ps_names = ",".join(abnormal) message = '%shostname=%s\tprocess=%s\t' % (make_header(ip_address), hostname, ps_names) log.info('[syslog] %shostname=%s\tprocess=%s\t' % (make_header(ip_address), hostname, ps_names)) send_qradar(message) if "db" in options: insert_db = importlib.import_module("insert_db") ps_names = ",".join(abnormal) message = 'hostname=%s\tip=%s\tprocess=%s\t' % (hostname, ip_address, ps_names) log.info('[db] hostname=%s\tip=%s\tprocess=%s\t' % (hostname, ip_address, ps_names)) insert_db.insert_db(message)
column_contents = db_connection.get_column_contents(db, TABLE_NAME, COL_NAME) values = db_connection.convert_contents_notes(column_contents) string_values = '\n\n' for i in values: string_values = string_values + 'Note : ' + str(i.note_number) + '\n' for j in i.note_value: string_values = string_values + j + '\n' string_values = string_values + '\n\n' os.chdir(home_location) file_value = open('json_value.txt', 'w+') for i in values: json_value = json.dumps(i.__dict__) file_value.write(json_value) file_value.close() sender = input("Enter sender mail id\n") sender_password = input("Enter sender password id\n") receiver = input("Enter receiver mail id\n") #sending string value to mail mail_obj = Mail(sender, sender_password, receiver) mail_obj.send_mail(string_values) #JSON FILE CREATED IN CURRENT DIRECTORY , FILE NAME : 'json_value.txt'
# coding:utf-8 # # Whois检测程序 # 实现了队列的检测,程序运行情况,速度和其他内容的检测,定期发送检测结果到邮箱中。 # version: 0.1.0 # time:2016.9.8 # author:@`13 # # !/usr/bin/python # encoding:utf-8 import sys import time from send_mail import Mail sys.stdout.flush() #try: # import schedule #except ImportError: # sys.exit("无schedul模块,请安装 easy_install schedule") if __name__ == "__main__": M = Mail() M.send_mail() print '初始化完成...' while True: M.send_mail() time.sleep(3600*1)