2022-11-30 10:26:27 +01:00
|
|
|
class implementation_notification_channel_libnotify(interface_notification_channel):
|
|
|
|
|
|
2022-11-30 23:03:24 +01:00
|
|
|
'''
|
|
|
|
|
[implementation]
|
|
|
|
|
'''
|
|
|
|
|
def parameters_schema(self):
|
|
|
|
|
return {
|
|
|
|
|
"type": "object",
|
|
|
|
|
"additionalProperties": False,
|
|
|
|
|
"properties": {
|
|
|
|
|
"icon": {
|
|
|
|
|
"type": "string"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"required": [
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-11-30 10:26:27 +01:00
|
|
|
'''
|
|
|
|
|
[implementation]
|
|
|
|
|
'''
|
|
|
|
|
def normalize_conf_node(self, node):
|
|
|
|
|
return dict_merge(
|
|
|
|
|
{
|
2022-11-30 23:03:24 +01:00
|
|
|
"icon": "/usr/local/share/icons/heimdall.png",
|
2022-11-30 10:26:27 +01:00
|
|
|
},
|
|
|
|
|
node
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
[implementation]
|
|
|
|
|
'''
|
2022-11-30 23:14:38 +01:00
|
|
|
def notify(self, parameters, name, data, state, info):
|
2022-11-30 10:26:27 +01:00
|
|
|
def condition_translate(condition):
|
|
|
|
|
if (condition == enum_condition.unknown):
|
|
|
|
|
return "normal"
|
|
|
|
|
elif (condition == enum_condition.ok):
|
|
|
|
|
return "low"
|
|
|
|
|
elif (condition == enum_condition.warning):
|
|
|
|
|
return "normal"
|
|
|
|
|
elif (condition == enum_condition.critical):
|
|
|
|
|
return "critical"
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError("impossible condition")
|
|
|
|
|
parts = []
|
|
|
|
|
parts.append(
|
|
|
|
|
"notify-send"
|
|
|
|
|
)
|
|
|
|
|
## app name
|
|
|
|
|
parts.append(
|
|
|
|
|
string_coin(
|
|
|
|
|
"--app-name={{app_name}}",
|
|
|
|
|
{
|
|
|
|
|
"app_name": "heimdall",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
## urgency
|
|
|
|
|
parts.append(
|
|
|
|
|
string_coin(
|
|
|
|
|
"--urgency={{urgency}}",
|
|
|
|
|
{
|
|
|
|
|
"urgency": condition_translate(state["condition"]),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
## icon
|
|
|
|
|
if ("icon" not in parameters):
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
parts.append(
|
|
|
|
|
string_coin(
|
|
|
|
|
"--icon={{icon}}",
|
|
|
|
|
{
|
|
|
|
|
"icon": parameters["icon"],
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
## summary
|
|
|
|
|
parts.append(
|
|
|
|
|
string_coin(
|
|
|
|
|
"{{condition}} | {{title}}",
|
|
|
|
|
{
|
|
|
|
|
"title": data["title"],
|
|
|
|
|
"condition": condition_encode(state["condition"]).upper(),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
## body
|
|
|
|
|
parts.append(
|
2022-11-30 23:14:38 +01:00
|
|
|
"(no info)"
|
|
|
|
|
if (info == "") else
|
|
|
|
|
info
|
2022-11-30 10:26:27 +01:00
|
|
|
)
|
|
|
|
|
_subprocess.run(parts)
|
|
|
|
|
|