The blueprint will return an array of dictionaries, which can be referenced using {{items}}
. This way you can gain greater control over how the output should be handled.
An example of the returned data:
[
{
"host": "portainer.example.com",
"port": "9443",
"rel_time": "9 days",
'is_valid': True,
"entity_id": "sensor.cert_expiry_timestamp_portainer_example_com_9443",
"state": "2023-02-24T20:24:44+00:00"
},
{
"host": "proxmox.example.com",
"port": "8006",
"rel_time": "1 day",
'is_valid': True,
"entity_id": "sensor.cert_expiry_timestamp_proxmox_example_com_8006",
"state": "2023-02-16T23:06:53+00:00"
},
{
"host": "www.example.com",
"port": 443,
"rel_time": "9 days",
'is_valid': True,
"entity_id": "sensor.cert_expiry_timestamp_www_example_com",
"state": "2023-02-24T20:19:17+00:00"
}
]
An action
example which sends an HTML-formatted e-mail:
service: notify.smtp_gmail
data:
title: Certificates expiring soon
message: |
The following monitored certificates
will expire soon:
data:
html: |
<!DOCTYPE html> <html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Certificates expiring soon</title>
</head>
<body>
<p>The following monitored certificates will expire soon:</p>
{% for item in items %}
<p><a href="https://{{item.host}}:{{item.port}}"><span class="cert-expiry-host">{{item.host}}</span>:<span class="cert-expiry-port">{{item.port}}</span></a> expires in <span class="cert-expiry-time">{{item.rel_time}}</span>.</p>
{% endfor %}
</body>
</html>
Another action
example which creates a persistent notification:
service: notify.persistent_notification
data:
title: Certificates expiring soon
message: |
{% for item in items %}
<a href="https://{{item.host}}:{{item.port}}"><b>{{item.host}}:{{item.port}}</b></a> {{item.error}}.
{% endfor %}
Please find the blueprint on Github:
The fine print:
I am not a programmer and I have little to no experience with YAML or Jinja2, so I have probably made several basic mistakes. If you find any mistakes, feel free to point them out, preferably with explanations and corrections for me to learn from
I have published the code on Github, where you are welcome to clone/copy/whatever-it-is-called (I am no Github guru either), make pull requests (hopefully I will figure out how that works then) etc.