亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

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
桃江县| 黑水县| 大姚县| 菏泽市| 镇康县| 榕江县| 克拉玛依市| 渑池县| 逊克县| 铜川市| 阳山县| 汶上县| 那曲县| 海安县| 安西县| 巨野县| 萨迦县| 邯郸市| 洪江市| 丽江市| 苗栗市| 康马县| 北安市| 岳阳县| 白玉县| 忻城县| 罗山县| 黔江区| 咸宁市| 汝阳县| 抚远县| 乌兰察布市| 阿拉善盟| 开原市| 定州市| 淮南市| 满洲里市| 于田县| 蓬莱市| 榆树市| 新田县|