- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
#!/usr/bin/python
# encoding utf8
# head1 NAME
#
# ssl-expiry_ - Munin plugin to display number of days until an SSL certificate
# expires.
#
# APPLICABLE SYSTEMS
#
# Any system that can connect to the internet
#
# CONFIGURATION
#
#
import sys, os, string, subprocess, time
from ssl import SSLError, cert_time_to_seconds
THIS_SCRIPT_NAME = "ssl-expiry_"
def get_num_days(site_name):
p1 = subprocess.Popen(["openssl", "s_client", "-connect", site_name + ":443"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p2 = subprocess.Popen(["openssl", "x509", "-noout", "-enddate"], stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p1.stdout.close()
output = p2.communicate();
not_after = output[0]
index_of = not_after.find("notAfter")
if(index_of < 0):
# have an error here
return(0)
else:
# notAfter=Jan 6 11:02:56 2017 GMT
time_string = not_after[index_of + len("notAfter") + 1:-1]
num_seconds = cert_time_to_seconds(time_string)
return(int(round( (num_seconds - time.time())/(60*60*24))))
if __name__ == "__main__":
# figure out which one we are doing
full_caller_name = sys.argv[0]
index_of_script = full_caller_name.find(THIS_SCRIPT_NAME)
site_name = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_script:]
# are we doing config/autoconfig?
if(len(sys.argv) > 1):
if (sys.argv[1]=="config"):
print "graph_title Days until SSL certificate for " + site_name + " expires."
print "graph_vlabel Number Of Days"
print "graph_category SSL"
# in green
print "NUM_DAYS.label Number of Days"
print "NUM_DAYS.colour 00cc00"
print "NUM_DAYS.draw AREA"
print "graph_args --base 1000 -l 0 "
sys.exit()
# now that we know the caller, get the environment
#stat_url = os.environ.get("url." + caller)
print("NUM_DAYS.value %i" % (get_num_days(site_name)))
Комментарии (0) RSS
Добавить комментарий