SnowAlert
SnowAlert copied to clipboard
Document SNS handler with example
Dear Team,
I am trying to call sns handler for the alert but while running the snowalert run all command I am getting an error following are the details:
If there is any documentation link on using handler part can you please share across the same.
SQL - Alert CREATE OR REPLACE VIEW snowalert.rules.ETL_BATCH_CODW_COMPANYOPS_FINACE_issue_alert_query COPY GRANTS COMMENT='Alerts on unknown transaction type @tags snowflake,msft trans issue' AS SELECT 'SnowAlert' AS environment , array_construct('ETL_BATCH_CODW_COMPANYOPS_FINACE_ERROR') AS sources , BATCH_NAME AS object , 'BATCH GOT FAILED' AS title , CURRENT_TIMESTAMP() AS event_time , CURRENT_TIMESTAMP() AS alert_time , BATCH_NAME || ' Got Failed' AS description , OBJECT_CONSTRUCT( 'type', 'sns', 'topic', 'snowalert_topic', 'message', description ) as HANDLERS , 'snowalert' AS actor , 'login' AS action , 'SnowAlert' AS detector , OBJECT_CONSTRUCT(*) AS event_data , 'low' AS severity , 'etl batch issue' AS query_name , null AS query_id FROM SNOWALERT.DATA.V_ETL_BATCH_CODW_COMPANYOPS_FINACE_ERROR
Error Message:
[6] ./run.py:77 in
./
./
ModuleNotFoundError: No module named 'runners.handlers.message'
[6] handler failed
[6] ./run.py:77 in
./
./
ModuleNotFoundError: No module named 'runners.handlers.topic'
[6] handler failed
[6] Updating alert table:
[6] UPDATE results.alerts SET handled=%s WHERE alert:ALERT_ID='5a31b4fa-81ac-4a47-a034-df23378a4284'
[6] ./run.py:77 in
./
./
ModuleNotFoundError: No module named 'runners.handlers.type'
Thanks, Bhaskar
The handers should be an array of objects, so instead of —
OBJECT_CONSTRUCT(
'type', 'sns',
'topic', 'snowalert_topic',
'message', description
) AS handlers
try —
ARRAY_CONSTRUCT(
OBJECT_CONSTRUCT(
'type', 'sns',
'topic', 'snowalert_topic',
'message', description
)
) AS handlers
This way, you can add a list of handlers. Let's keep this issue open to have this use-case handled gracefully, as the runners should understand a single object instead of an array there, as well.
Thanks it was working after changing the code.
Hi, For the same above example i can see the SNS got the message present in the Handlers array but not the event data. how can the event data be sent to SNS.
just as the description
is passed in as the message
in the example above, you should be able to pass the event_data
(or a piece of it?) into the handler.
Some thing like this. where event data is part of the handler
ARRAY_CONSTRUCT( OBJECT_CONSTRUCT( 'type', 'sns', 'topic', 'snowalert_topic', 'message', description, 'event_data',object_construct(*) ) ) AS handlers
No, because the SNS handler module does not have an event_data
parameter in its handle
method.
Can you share a Sample for SNS where event data is also passed to the SNS Handler.
Sorry, we don't use that handler, so the code is the docs for it unless you can provide one.
Whatever key/values you parametrize the handler object with get passed to the handle
method. There's a few options explained in the hander docs here.
I can keep the issue open as a documentation request.