91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

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
黄梅县| 远安县| 仁布县| 青田县| 衡东县| 滁州市| 黑山县| 通海县| 淅川县| 克山县| 美姑县| 天长市| 娄底市| 新竹市| 台前县| 鹤岗市| 龙里县| 沂源县| 阿坝县| 泽州县| 涟水县| 太和县| 余江县| 南阳市| 新蔡县| 谷城县| 简阳市| 隆安县| 莱阳市| 安义县| 肃宁县| 阜城县| 商都县| 阿克陶县| 英吉沙县| 读书| 青铜峡市| 哈巴河县| 潮安县| 桦南县| 韩城市|