Custom formatter
Last updated
Last updated
In order to create a custom formatter, please implement abstract class AbstractFormatter
.
Please also implement abstract method format
. It accepts an instance of CheckResult and can return anything. It can be formatted string, it can be list with blocks of formatted strings. It can also be something else, which is relevant for your custom notification channel.
CheckResult contains a lot of useful information, which can be used for formatting. Like query meta-data, query plan, information about locks, etc.
You may use existing formatters as an example and a good starting point to create your own implementation:
Make sure to "escape" potentially unsafe values, especially SQL query text. It might contain any UTF-8 characters and might break formatting of your notifications if not careful.
Make sure to "truncate" too long values, especially SQL query text. It can be as long as 1Mb, which exceeds the amount of information which a person can process while reading notification. Keeping a few starting lines and truncating everything else is a good starting point.
You may use special debug methods dataclass_to_json_str(obj)
and dataclass_to_dict_recursive(obj)
, which are exposed by snowkill
package.
These methods are capable of converting SnowKill data structures to human-readable JSON string or to Python dictionary.