中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

Python自動化導出zabbix數據并發郵件腳本

小云
99
2023-08-17 12:43:11
欄目: 編程語言

import smtplib

from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText

from email.mime.base import MIMEBase

from email import encoders

import os

import subprocess

import time

Zabbix參數

zabbix_server = ‘192.168.1.100’

zabbix_user = ‘admin’

zabbix_password = ‘zabbix’

zabbix_export_script = ‘/usr/lib/zabbix/export_zabbix_data.py’

zabbix_export_output = ‘/tmp/zabbix_data.csv’

郵件參數

smtp_server = ‘smtp.example.com’

smtp_port = 587

smtp_username = ‘sender@example.com’

smtp_password = ‘password’

email_from = ‘sender@example.com’

email_to = [‘recipient@example.com’]

email_subject = ‘Zabbix Data Export’

email_body = ‘Please see the attached Zabbix data file.’

導出Zabbix數據

subprocess.call([‘python’, zabbix_export_script, zabbix_server, zabbix_user, zabbix_password, zabbix_export_output])

發送郵件

msg = MIMEMultipart()

msg[‘From’] = email_from

msg[‘To’] = ‘,’.join(email_to)

msg[‘Subject’] = email_subject

msg.attach(MIMEText(email_body, ‘plain’))

attachment = open(zabbix_export_output, ‘rb’)

part = MIMEBase(‘application’, ‘octet-stream’)

part.set_payload((attachment).read())

encoders.encode_base64(part)

part.add_header(‘Content-Disposition’, “attachment; filename= %s” % os.path.basename(zabbix_export_output))

msg.attach(part)

server = smtplib.SMTP(smtp_server, smtp_port)

server.starttls()

server.login(smtp_username, smtp_password)

server.sendmail(email_from, email_to, msg.as_string())

server.quit()

print(“Email sent successfully”)

0
大埔县| 广汉市| 丹棱县| 伊川县| 金秀| 勐海县| 金乡县| 兖州市| 师宗县| 辽阳市| 香港| 武宁县| 集贤县| 四川省| 仲巴县| 襄汾县| 儋州市| 自贡市| 平凉市| 陇西县| 绵竹市| 贵州省| 会泽县| 北安市| 武安市| 观塘区| 承德市| 合水县| 芦山县| 大余县| 天台县| 玛纳斯县| 同江市| 旬邑县| 克东县| 进贤县| 祁连县| 永城市| 台北县| 常山县| 九龙县|