mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
check-certificates: split loop for certificate renew and warning
This allows to have differnt time values.
This commit is contained in:
parent
99a23f99e5
commit
a66713d093
1 changed files with 29 additions and 22 deletions
|
@ -18,7 +18,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
:foreach Cert in=[ / certificate find where !revoked expires-after<2w ] do={
|
||||
:foreach Cert in=[ / certificate find where !revoked expires-after<3w ] do={
|
||||
:local CertName [ / certificate get $Cert name ];
|
||||
:local CommonName [ / certificate get $Cert common-name ];
|
||||
:local FingerPrint [ / certificate get $Cert fingerprint ];
|
||||
|
@ -32,7 +32,7 @@
|
|||
/ certificate import file-name=($CommonName . ".pem") passphrase=$CertRenewPass;
|
||||
/ file remove [ find where name=($CommonName . ".pem") ];
|
||||
|
||||
:local CertNew [ / certificate find where common-name=$CommonName fingerprint!=$FingerPrint expires-after>2w ];
|
||||
:local CertNew [ / certificate find where common-name=$CommonName fingerprint!=$FingerPrint expires-after>3w ];
|
||||
:local CertNameNew [ / certificate get $CertNew name ];
|
||||
|
||||
:foreach IpService in=[ / ip service find where certificate=$CertName ] do={
|
||||
|
@ -65,25 +65,32 @@
|
|||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
||||
:log info ("The certificate " . $CertName . " has been renewed.");
|
||||
} on-error={
|
||||
:local InvalidBefore [ / certificate get $Cert invalid-before ];
|
||||
:local InvalidAfter [ / certificate get $Cert invalid-after ];
|
||||
: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!") \
|
||||
("A certificate on " . $Identity . " " . $State . ".\n\n" . \
|
||||
"Name: " . $CertName . "\n" . \
|
||||
"CommonName: " . $CommonName . "\n" . \
|
||||
"Fingerprint: " . $FingerPrint . "\n" . \
|
||||
"Issuer: " . $Issuer . "\n" . \
|
||||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
||||
:log warning ("The certificate " . $CertName . " " . $State . \
|
||||
", it is invalid after " . $InvalidAfter . ".");
|
||||
:log debug ("Could not renew certificate " . $CertName ".");
|
||||
}
|
||||
}
|
||||
|
||||
:foreach Cert in=[ / certificate find where !revoked expires-after<2w ] do={
|
||||
:local CertName [ / certificate get $Cert name ];
|
||||
:local CommonName [ / certificate get $Cert common-name ];
|
||||
:local FingerPrint [ / certificate get $Cert fingerprint ];
|
||||
:local Issuer [ $GetIssuerCN [ / certificate get $Cert issuer ] ];
|
||||
:local InvalidBefore [ / certificate get $Cert invalid-before ];
|
||||
:local InvalidAfter [ / certificate get $Cert invalid-after ];
|
||||
|
||||
:local State;
|
||||
:if ([ / certificate get $Cert expired ] = true) do={
|
||||
:set State "expired";
|
||||
} else={
|
||||
:set State "is about to expire";
|
||||
}
|
||||
|
||||
$SendNotification ("Certificate warning!") \
|
||||
("A certificate on " . $Identity . " " . $State . ".\n\n" . \
|
||||
"Name: " . $CertName . "\n" . \
|
||||
"CommonName: " . $CommonName . "\n" . \
|
||||
"Fingerprint: " . $FingerPrint . "\n" . \
|
||||
"Issuer: " . $Issuer . "\n" . \
|
||||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
||||
:log warning ("The certificate " . $CertName . " " . $State . \
|
||||
", it is invalid after " . $InvalidAfter . ".");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue