python3检查SSL过期情况并计算过期天数发送告警
本脚本参考了百度一些脚本的内容,由于发现其他脚本很多都只是返回过期的时间,并没有计算天数及发送告警,所以自己改了一部分计算剩余天数以及告警的部分,这样更符合实际的监控需要
# -*- encoding: utf-8 -*-
# requires a recent enough python with idna support in socket
# pyopenssl, cryptography and idna
#优化人:wangpeisong
#邮箱1456171833@qq.com
import datetime
#获取系统当前时间
Startime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
from OpenSSL import SSL
from cryptography import x509
from cryptography.x509.oid import NameOID
import idna
import time
import json
import urllib
import requests
from socket import socket
from collections import namedtuple
#定义发送钉钉告警的函数
def send_to_ding(access_token,content):
header = {
"Content-Type": "application/json",
"charset": "utf-8"
}
data = {
"msgtype": "text",
"text": {
"content": content
},
"at":{
#这里填