82 lines
1.4 KiB
Python
82 lines
1.4 KiB
Python
|
|
class implementation_notification_channel_libnotify(interface_notification_channel):
|
||
|
|
|
||
|
|
'''
|
||
|
|
[implementation]
|
||
|
|
'''
|
||
|
|
def normalize_conf_node(self, node):
|
||
|
|
return dict_merge(
|
||
|
|
{
|
||
|
|
"icon": None,
|
||
|
|
},
|
||
|
|
node
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
'''
|
||
|
|
[implementation]
|
||
|
|
'''
|
||
|
|
def notify(self, parameters, name, data, state, output):
|
||
|
|
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(
|
||
|
|
"(no infos)"
|
||
|
|
if (output == "") else
|
||
|
|
output
|
||
|
|
)
|
||
|
|
_subprocess.run(parts)
|
||
|
|
|