160 lines
3.1 KiB
TypeScript
160 lines
3.1 KiB
TypeScript
/*
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
<info@greenscale.de>
|
|
|
|
»heimdall« is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
»heimdall« is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
namespace _heimdall.notification_kinds.email
|
|
{
|
|
|
|
/**
|
|
*/
|
|
function parameters_schema(
|
|
) : _heimdall.helpers.json_schema.type_schema
|
|
{
|
|
return {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"access": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"host": {
|
|
"type": "string"
|
|
},
|
|
"port": {
|
|
"type": "integer"
|
|
},
|
|
"username": {
|
|
"type": "string"
|
|
},
|
|
"password": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"required": [
|
|
"host",
|
|
"port",
|
|
"username",
|
|
"password"
|
|
]
|
|
},
|
|
"sender": {
|
|
"type": "string"
|
|
},
|
|
"receivers": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"tags": {
|
|
"description": "list of strings, which will be placed in the e-mail subject",
|
|
"type": "array",
|
|
"items": {
|
|
"type": "string"
|
|
},
|
|
"default": []
|
|
}
|
|
},
|
|
"required": [
|
|
"access",
|
|
"sender",
|
|
"receivers"
|
|
]
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function normalize_order_node(
|
|
node : any
|
|
) : any
|
|
{
|
|
return Object.assign(
|
|
{
|
|
},
|
|
node
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
async function notify(
|
|
parameters : any,
|
|
name : string,
|
|
check : type_check,
|
|
state : type_item_state,
|
|
info : any
|
|
) : Promise<void>
|
|
{
|
|
const nm_nodemailer = require("nodemailer");
|
|
|
|
const now : Date = new Date(Date.now());
|
|
const transporter = nm_nodemailer.createTransport(
|
|
{
|
|
"host": parameters.access.host,
|
|
"port": parameters.access.port,
|
|
"secure": true,
|
|
"auth": {
|
|
"user": parameters.access.username,
|
|
"pass": parameters.access.password,
|
|
}
|
|
}
|
|
);
|
|
const send_result = await transporter.sendMail(
|
|
{
|
|
"from": parameters.sender,
|
|
"to": parameters.receivers.join(","),
|
|
"subject": lib_plankton.string.coin(
|
|
"{{tags}} {{title}}",
|
|
{
|
|
"tags": (
|
|
parameters.tags
|
|
.concat([_heimdall.condition_show(state.condition)])
|
|
.map(tag => lib_plankton.string.coin("[{{tag}}]", {"tag": tag.toUpperCase()}))
|
|
.join(" ")
|
|
),
|
|
"title": check.name,
|
|
}
|
|
),
|
|
"text": JSON.stringify(info, undefined, "\t"),
|
|
"headers": {
|
|
"Date": now.toUTCString(),
|
|
}
|
|
}
|
|
);
|
|
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
register_implementation(
|
|
"email",
|
|
{
|
|
"parameters_schema": parameters_schema,
|
|
"normalize_order_node": normalize_order_node,
|
|
"notify": notify,
|
|
}
|
|
);
|
|
|
|
}
|