146 lines
2.8 KiB
TypeScript
146 lines
2.8 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.libnotify
|
|
{
|
|
|
|
/**
|
|
*/
|
|
function parameters_schema(
|
|
) : _heimdall.helpers.json_schema.type_schema
|
|
{
|
|
return {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"icon": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"required": [
|
|
]
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function normalize_order_node(
|
|
node : any
|
|
) : any
|
|
{
|
|
return Object.assign(
|
|
{
|
|
"icon": "/usr/local/share/icons/heimdall.png",
|
|
},
|
|
node
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
async function notify(
|
|
parameters : any,
|
|
name : string,
|
|
check : type_check,
|
|
state : type_item_state,
|
|
info : any
|
|
) : Promise<void>
|
|
{
|
|
const condition_translate = function (condition : _heimdall.enum_condition): string
|
|
{
|
|
switch (condition) {
|
|
case _heimdall.enum_condition.unknown: return "normal";
|
|
case _heimdall.enum_condition.ok: return "low";
|
|
case _heimdall.enum_condition.concerning: return "normal";
|
|
case _heimdall.enum_condition.critical: return "critical";
|
|
}
|
|
};
|
|
|
|
let parts : Array<string> = [];
|
|
parts.push(
|
|
"notify-send"
|
|
);
|
|
// app name
|
|
parts.push(
|
|
lib_plankton.string.coin(
|
|
"--app-name={{app_name}}",
|
|
{
|
|
"app_name": "heimdall",
|
|
}
|
|
)
|
|
)
|
|
// urgency
|
|
parts.push(
|
|
lib_plankton.string.coin(
|
|
"--urgency={{urgency}}",
|
|
{
|
|
"urgency": condition_translate(state.condition),
|
|
}
|
|
)
|
|
)
|
|
// icon
|
|
if (! ("icon" in parameters)) {
|
|
// do nothing
|
|
}
|
|
else {
|
|
parts.push(
|
|
lib_plankton.string.coin(
|
|
"--icon={{icon}}",
|
|
{
|
|
"icon": parameters.icon,
|
|
}
|
|
)
|
|
);
|
|
}
|
|
// summary
|
|
parts.push(
|
|
lib_plankton.string.coin(
|
|
"{{condition}} | {{title}}",
|
|
{
|
|
"title": check.name,
|
|
"condition": _heimdall.condition_show(state.condition).toUpperCase(),
|
|
}
|
|
)
|
|
);
|
|
// body
|
|
parts.push(
|
|
JSON.stringify(info)
|
|
);
|
|
|
|
await _heimdall.helpers.misc.shell_exec(parts[0], parts.slice(1));
|
|
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
register_implementation(
|
|
"libnotify",
|
|
{
|
|
"parameters_schema": parameters_schema,
|
|
"normalize_order_node": normalize_order_node,
|
|
"notify": notify,
|
|
}
|
|
);
|
|
|
|
}
|