mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
check-certificates: show remaining time
This commit is contained in:
parent
26ccf41298
commit
de602cba4f
1 changed files with 16 additions and 8 deletions
|
@ -18,6 +18,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:local FormatExpire do={
|
||||||
|
:global CharacterReplace;
|
||||||
|
:return [ $CharacterReplace [ $CharacterReplace [ :tostr $1 ] "w" "w " ] "d" "d " ];
|
||||||
|
}
|
||||||
|
|
||||||
:foreach Cert in=[ / certificate find where !revoked expires-after<3w ] do={
|
:foreach Cert in=[ / certificate find where !revoked expires-after<3w ] do={
|
||||||
:local CertName [ / certificate get $Cert name ];
|
:local CertName [ / certificate get $Cert name ];
|
||||||
:local CommonName [ / certificate get $Cert common-name ];
|
:local CommonName [ / certificate get $Cert common-name ];
|
||||||
|
@ -61,11 +66,12 @@
|
||||||
/ certificate remove $Cert;
|
/ certificate remove $Cert;
|
||||||
/ certificate set $CertNew name=$CertName;
|
/ certificate set $CertNew name=$CertName;
|
||||||
|
|
||||||
:local InvalidBefore [ / certificate get $CertNew invalid-before ];
|
|
||||||
:local InvalidAfter [ / certificate get $CertNew invalid-after ];
|
|
||||||
:local Issuer [ $GetIssuerCN [ / certificate get $CertNew issuer ] ];
|
|
||||||
:set CommonName [ / certificate get $CertNew common-name ];
|
:set CommonName [ / certificate get $CertNew common-name ];
|
||||||
:set FingerPrint [ / certificate get $CertNew fingerprint ];
|
:set FingerPrint [ / certificate get $CertNew fingerprint ];
|
||||||
|
:local Issuer [ $GetIssuerCN [ / certificate get $CertNew issuer ] ];
|
||||||
|
:local InvalidBefore [ / certificate get $CertNew invalid-before ];
|
||||||
|
:local InvalidAfter [ / certificate get $CertNew invalid-after ];
|
||||||
|
:local ExpiresAfter [ $FormatExpire [ / certificate get $CertNew expires-after ] ];
|
||||||
|
|
||||||
$SendNotification ("Certificate renewed") \
|
$SendNotification ("Certificate renewed") \
|
||||||
("A certificate on " . $Identity . " has been renewed.\n\n" . \
|
("A certificate on " . $Identity . " has been renewed.\n\n" . \
|
||||||
|
@ -73,7 +79,8 @@
|
||||||
"CommonName: " . $CommonName . "\n" . \
|
"CommonName: " . $CommonName . "\n" . \
|
||||||
"Fingerprint: " . $FingerPrint . "\n" . \
|
"Fingerprint: " . $FingerPrint . "\n" . \
|
||||||
"Issuer: " . $Issuer . "\n" . \
|
"Issuer: " . $Issuer . "\n" . \
|
||||||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
"Validity: " . $InvalidBefore . " to " . $InvalidAfter . "\n" . \
|
||||||
|
"Expires in: " . $ExpiresAfter);
|
||||||
:log info ("The certificate " . $CertName . " has been renewed.");
|
:log info ("The certificate " . $CertName . " has been renewed.");
|
||||||
} on-error={
|
} on-error={
|
||||||
:log debug ("Could not renew certificate " . $CertName ".");
|
:log debug ("Could not renew certificate " . $CertName ".");
|
||||||
|
@ -88,11 +95,11 @@
|
||||||
:local InvalidBefore [ / certificate get $Cert invalid-before ];
|
:local InvalidBefore [ / certificate get $Cert invalid-before ];
|
||||||
:local InvalidAfter [ / certificate get $Cert invalid-after ];
|
:local InvalidAfter [ / certificate get $Cert invalid-after ];
|
||||||
|
|
||||||
:local State;
|
:local ExpiresAfter [ $FormatExpire [ / certificate get $Cert expires-after ] ];
|
||||||
|
:local State "is about to expire";
|
||||||
:if ([ / certificate get $Cert expired ] = true) do={
|
:if ([ / certificate get $Cert expired ] = true) do={
|
||||||
|
:set ExpiresAfter "expired";
|
||||||
:set State "expired";
|
:set State "expired";
|
||||||
} else={
|
|
||||||
:set State "is about to expire";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$SendNotification ("Certificate warning!") \
|
$SendNotification ("Certificate warning!") \
|
||||||
|
@ -101,7 +108,8 @@
|
||||||
"CommonName: " . $CommonName . "\n" . \
|
"CommonName: " . $CommonName . "\n" . \
|
||||||
"Fingerprint: " . $FingerPrint . "\n" . \
|
"Fingerprint: " . $FingerPrint . "\n" . \
|
||||||
"Issuer: " . $Issuer . "\n" . \
|
"Issuer: " . $Issuer . "\n" . \
|
||||||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
"Validity: " . $InvalidBefore . " to " . $InvalidAfter . "\n" . \
|
||||||
|
"Expires in: " . $ExpiresAfter);
|
||||||
:log warning ("The certificate " . $CertName . " " . $State . \
|
:log warning ("The certificate " . $CertName . " " . $State . \
|
||||||
", it is invalid after " . $InvalidAfter . ".");
|
", it is invalid after " . $InvalidAfter . ".");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue