我对与弹性搜索API集成的python脚本感到困惑。我正确地使用了所有导入的库。但是问题是在运行脚本时。邮件未送达
我已经关闭了firewalld并刷新了ip表,并且使用Curl调用成功。
在脚本下方可以看到:
#!/usr/bin/python2.7
#-*- coding: utf-8 -*-
elastichost = 'http://10.204.11.13:1337'
elkindex = '*'
import elasticsearch
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import pyblake2
#import os
#echo '{"hashes": ["test"]}' > syslog.db
import pickledb
db = pickledb.load('syslog.db', True)
def email_user(email, subject, msgs):
fromm = 'redacted <redacted@gmail.com>'
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
msg = MIMEMultipart()
msg['From'] = fromm
msg['To'] = "redacted@gmail.com"
msg['Subject'] = "log"
msg.attach(MIMEText(msgs))
server.login('redcated@gmail.com', 'redacted')
server.sendmail(fromm, "redacted@gmail.com", msg.as_string())
server.quit()
return True
es = elasticsearch.Elasticsearch("10.204.11.13:1338", http_auth=('elastic','DVX3q1QlBqProSmvBO09'))
for x in es.search(index = elkindex, body = {"query": {"match_all": {}}})['hits']['hits']:
if 'kernel' in str(x):
minhash = pyblake2.blake2b(x.encode('utf-8')).hexdigest()
if not db.get('hashes').__contains__(minhash):
db.append('hashes', minhash)
db.dump()
email_user("jag@minemail.com", "Ett kernel meddelande har hittas i syslog", x)
总而言之:
脚本成功执行,与ELS api的连接成功。
但邮件未送达
感谢所有建议。