summaryrefslogtreecommitdiffstats
path: root/web/attachments/305359-sslutils.c.expiry.patch
blob: 151fc625b6791c77d46420ab58d68929b6d71cc0 (plain)
1
2
3
4
5
6
7
8
9
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
--- nagios-plugins-1.4.13/plugins/sslutils.c.orig	2008-12-13 22:26:49.000000000 +0000
+++ nagios-plugins-1.4.13/plugins/sslutils.c	2008-12-15 11:46:37.000000000 +0000
@@ -92,7 +92,7 @@
         ASN1_STRING *tm;
 	int offset;
 	struct tm stamp;
-	int days_left;
+	double days_left, hours_left, minutes_left;
 	char timestamp[17] = "";
 
 	certificate=SSL_get_peer_certificate(s);
@@ -138,20 +138,26 @@
 	stamp.tm_sec = 0;
 	stamp.tm_isdst = -1;
 
-	days_left = (mktime (&stamp) - time (NULL)) / 86400;
+	minutes_left = (mktime (&stamp) - time (NULL)) / 60.0;
+	hours_left = minutes_left / 60.0;
+	days_left = hours_left / 24.0;
 	snprintf
 		(timestamp, 17, "%02d/%02d/%04d %02d:%02d",
 		 stamp.tm_mon + 1,
 		 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
 
-	if (days_left > 0 && days_left <= days_till_exp) {
-		printf (_("WARNING - Certificate expires in %d day(s) (%s).\n"), days_left, timestamp);
-		return STATE_WARNING;
-	} else if (days_left < 0) {
+	if (days_left < 0) {
 		printf (_("CRITICAL - Certificate expired on %s.\n"), timestamp);
 		return STATE_CRITICAL;
-	} else if (days_left == 0) {
-		printf (_("WARNING - Certificate expires today (%s).\n"), timestamp);
+	}
+	else if (days_left <= days_till_exp) {
+		printf (_("WARNING - Certificate expires in %d day(s) (%s).\n"), days_left, timestamp);
+		return STATE_WARNING;
+	} else if (days_left < 1 && hours_left > 1 && days_left <= days_till_exp) {
+		printf (_("WARNING - Certificate expires in %d hours (%s).\n"), hours_left, timestamp);
+		return STATE_WARNING;
+	} else if (days_left < 1 && hours_left < 1 && days_left <= days_till_exp) {
+		printf (_("WARNING - Certificate expires in %d minutes (%s).\n"), minutes_left, timestamp);
 		return STATE_WARNING;
 	}