mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-08-14 23:12:28 +02:00
check-certificates: properly handle expired certificates
This commit is contained in:
parent
4ab9f9e7c8
commit
e62fbd2489
1 changed files with 11 additions and 4 deletions
|
@ -18,7 +18,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
:foreach Cert in=[ / certificate find where !revoked expires-after<2w expires-after>0 ] do={
|
:foreach Cert in=[ / certificate find where !revoked expires-after<2w ] 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 ];
|
||||||
:local FingerPrint [ / certificate get $Cert fingerprint ];
|
:local FingerPrint [ / certificate get $Cert fingerprint ];
|
||||||
|
@ -65,18 +65,25 @@
|
||||||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
||||||
:log info ("The certificate " . $CertName . " has been renewed.");
|
:log info ("The certificate " . $CertName . " has been renewed.");
|
||||||
} on-error={
|
} on-error={
|
||||||
:local ExpiresAfter [ / certificate get $Cert expires-after ];
|
|
||||||
: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 Issuer [ $GetIssuerCN [ / certificate get $Cert issuer ] ];
|
:local Issuer [ $GetIssuerCN [ / certificate get $Cert issuer ] ];
|
||||||
|
|
||||||
|
:local State;
|
||||||
|
:if ([ / certificate get $Cert expired ] = true) do={
|
||||||
|
:set State "expired";
|
||||||
|
} else={
|
||||||
|
:set State "is about to expire";
|
||||||
|
}
|
||||||
|
|
||||||
$SendNotification ("Certificate warning!") \
|
$SendNotification ("Certificate warning!") \
|
||||||
("A certificate on " . $Identity . " is about to expire.\n\n" . \
|
("A certificate on " . $Identity . " " . $State . ".\n\n" . \
|
||||||
"Name: " . $CertName . "\n" . \
|
"Name: " . $CertName . "\n" . \
|
||||||
"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);
|
||||||
:log warning ("The certificate " . $CertName . " is about to expire in " . $ExpiresAfter . ".");
|
:log warning ("The certificate " . $CertName . " " . $State . \
|
||||||
|
", it is invalid after " . $InvalidAfter . ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue