From ceaa83b83edb069ecf1cca181ec461519f0cc020 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 26 Feb 2020 14:19:54 +0100 Subject: global-functions: merge $LogAnd{Error,Put} to $LogPrintExit ... ... and fix logging. Logging with severity from variable (:log $severity ...) is not possible, this is considered a syntax error. Also the 'workaround' with parsing code failed with missing message in log. The reliable code is a lot longer, so merge the two functions to save a lot of duplicate code. --- check-certificates | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'check-certificates') diff --git a/check-certificates b/check-certificates index 56e9537..d94c330 100644 --- a/check-certificates +++ b/check-certificates @@ -14,8 +14,7 @@ :global TimeIsSync; :global UrlEncode; :global WaitForFile; -:global LogAndError; -:global LogAndPut; +:global LogPrintExit; :local FormatExpire do={ :global CharacterReplace; @@ -23,7 +22,7 @@ } :if ($TimeIsSync = false) do={ - $LogAndError warning "Time is not yet synchronized."; + $LogPrintExit warning "Time is not yet synchronized." true; } :foreach Cert in=[ / certificate find where !revoked !ca expires-after<3w ] do={ @@ -31,7 +30,7 @@ :do { :if ([ :len $CertRenewUrl ] = 0) do={ - $LogAndError warning "No CertRenewUrl given."; + $LogPrintExit warning "No CertRenewUrl given." true; } :foreach Type in={ ".pem"; ".p12" } do={ @@ -86,7 +85,7 @@ "Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \ "Validity: " . ($CertNewVal->"invalid-before") . " to " . ($CertNewVal->"invalid-after") . "\n" . \ "Expires in: " . [ $FormatExpire ($CertNewVal->"expires-after") ]) "" "true"; - $LogAndPut info ("The certificate " . ($CertVal->"name") . " has been renewed."); + $LogPrintExit info ("The certificate " . ($CertVal->"name") . " has been renewed.") false; } on-error={ :log debug ("Could not renew certificate " . ($CertVal->"name") . "."); } @@ -110,6 +109,6 @@ "Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \ "Validity: " . ($CertVal->"invalid-before") . " to " . ($CertVal->"invalid-after") . "\n" . \ "Expires in: " . $ExpiresAfter); - $LogAndPut warning ("The certificate " . ($CertVal->"name") . " " . $State . \ - ", it is invalid after " . ($CertVal->"invalid-after") . "."); + $LogPrintExit warning ("The certificate " . ($CertVal->"name") . " " . $State . \ + ", it is invalid after " . ($CertVal->"invalid-after") . ".") false; } -- cgit v1.2.3-54-g00ecf