128 lines
2.1 KiB
TypeScript
128 lines
2.1 KiB
TypeScript
|
|
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);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
*/
|
||
|
|
export function notification_kind_implementation(
|
||
|
|
) : type_notification_kind
|
||
|
|
{
|
||
|
|
return {
|
||
|
|
"parameters_schema": parameters_schema,
|
||
|
|
"normalize_order_node": normalize_order_node,
|
||
|
|
"notify": notify,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|