summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorPeter (pir) Radcliffe <pir-gitweb.com@pir.net>2015-11-25 13:58:30 +0000
committerSven Nierlein <sven@nierlein.de>2016-11-07 22:42:40 +0100
commit2f2b2f1987d63cb4b31b2ef4c95cf8c8ab1d83c6 (patch)
tree241c1345032f3e7f650f188d02ebee8b092d0290 /plugins
parent06059ecd0ebf4646cda5e24c31e9d17672e2c295 (diff)
downloadmonitoring-plugins-2f2b2f1987d63cb4b31b2ef4c95cf8c8ab1d83c6.tar.gz
GMT expiry display
Change solution to display GMT time in the local display format with the offset number of hours from GMT to be clear about what timezone this is if the local display format does not include offset.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sslutils.c11
-rwxr-xr-xplugins/tests/check_http.t8
2 files changed, 14 insertions, 5 deletions
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index 6437289f..b412ef3d 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -197,6 +197,7 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
197 X509_NAME *subj=NULL; 197 X509_NAME *subj=NULL;
198 char timestamp[50] = ""; 198 char timestamp[50] = "";
199 char cn[MAX_CN_LENGTH]= ""; 199 char cn[MAX_CN_LENGTH]= "";
200 char *tz;
200 201
201 int cnlen =-1; 202 int cnlen =-1;
202 int status=STATE_UNKNOWN; 203 int status=STATE_UNKNOWN;
@@ -267,7 +268,15 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
267 tm_t = timegm(&stamp); 268 tm_t = timegm(&stamp);
268 time_left = difftime(tm_t, time(NULL)); 269 time_left = difftime(tm_t, time(NULL));
269 days_left = time_left / 86400; 270 days_left = time_left / 86400;
270 strftime(timestamp, 50, "%F %R %z/%Z", localtime(&tm_t)); 271 tz = getenv("TZ");
272 setenv("TZ", "GMT", 1);
273 tzset();
274 strftime(timestamp, 50, "%c %z", localtime(&tm_t));
275 if (tz)
276 setenv("TZ", tz, 1);
277 else
278 unsetenv("TZ");
279 tzset();
271 280
272 if (days_left > 0 && days_left <= days_till_exp_warn) { 281 if (days_left > 0 && days_left <= days_till_exp_warn) {
273 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp); 282 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index e72d243a..5984d489 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -186,21 +186,21 @@ SKIP: {
186 186
187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" ); 187 $result = NPTest->testCmd( "$command -p $port_https -S -C 14" );
188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" ); 188 is( $result->return_code, 0, "$command -p $port_https -S -C 14" );
189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019.', "output ok" ); 189 is( $result->output, 'OK - Certificate \'Ton Voon\' will expire on Sun Mar 3 21:41:28 2019 +0000.', "output ok" );
190 190
191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" ); 191 $result = NPTest->testCmd( "$command -p $port_https -S -C 14000" );
192 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" ); 192 is( $result->return_code, 1, "$command -p $port_https -S -C 14000" );
193 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" ); 193 like( $result->output, '/WARNING - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" );
194 194
195 # Expired cert tests 195 # Expired cert tests
196 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" ); 196 $result = NPTest->testCmd( "$command -p $port_https -S -C 13960,14000" );
197 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" ); 197 is( $result->return_code, 2, "$command -p $port_https -S -C 13960,14000" );
198 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019\)./', "output ok" ); 198 like( $result->output, '/CRITICAL - Certificate \'Ton Voon\' expires in \d+ day\(s\) \(Sun Mar 3 21:41:28 2019 \+0000\)./', "output ok" );
199 199
200 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" ); 200 $result = NPTest->testCmd( "$command -p $port_https_expired -S -C 7" );
201 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" ); 201 is( $result->return_code, 2, "$command -p $port_https_expired -S -C 7" );
202 is( $result->output, 202 is( $result->output,
203 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009.', 203 'CRITICAL - Certificate \'Ton Voon\' expired on Thu Mar 5 00:13:16 2009 +0000.',
204 "output ok" ); 204 "output ok" );
205 205
206} 206}