# Send Synology and QNAP notification to Slack ## 1. Create a slack webhook https://api.slack.com/messaging/webhooks ## 2. Setup for Synology 2. Goto > Control Panel > Notification > SMS 2.1 then enable it 2.2 and add SMS service provider ![](https://i.imgur.com/ekAH2pl.png) 2.3 Skip request Header 2.4 Create two parameters: `text` and `phone_number` and bind it ![](https://i.imgur.com/ns55SgS.png) 2.6 Done. Set a random phone number, Slack API will ignore the invalid field without error ![](https://i.imgur.com/fxZUUuS.png) 2.7 Test it 2.8 (Optional) You may check/uncheck the notifcations in Advanced panel ![](https://i.imgur.com/Xnremwy.png) ## 3. Setup for Qnap 3. Goto > Control Panel > Notification Center > Serivce Account > SMS > Add SMSC serice ![](https://i.imgur.com/Q7qen5N.png) Because QNAP is NOT KIND, we need to create a small proxy (You can run in lambda or somewhere). Here, I setup a secret proxy URL: `https://your_api_url:port/qnap_notify/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?text=@@Text@@&p=@@PhoneNumber@@` And my proxy is written in Python ``` python from aiohttp import web, ClientSession async def proxy(request): async with ClientSession() as session: rep = await session.post("https://hooks.slack.com/services/Txxxxxxxx/Bxxxxxxxxx/2xxxxxxxxxxxxx", json={'text': request.query.get("text", "")}) return web.json_response({"status": "ok", 'data': await rep.text()}) if __name__ == "__main__": app = web.Application() app.add_routes([web.get('/qnap_notify/xxxxxxxxxx', proxy)]) web.run_app(app, port=80) ``` 3.3 Remeber to test it 3.4 Bind to notifcation rule. (Phone number doesn't matter) ![](https://i.imgur.com/ljqRWU7.png) ## Note ### Nginx Because Nginx didn't decode the url-encoded string in $var variable. ``` nginx location /qnap_notify/xxxxxx { resolver 8.8.8.8; proxy_pass https://hooks.slack.com/services/xxx; proxy_method POST; proxy_set_body '{"text": "$arg_text"}'; proxy_set_header Content-type application/json; } ``` 3rd modules [set-misc-nginx-module](https://github.com/openresty/set-misc-nginx-module) can be helpful, however you might build the nginx by your own. I follow this [Nginx Dockerfile](https://stackoverflow.com/questions/57739560/what-do-i-need-to-change-in-nginx-official-dockers-image-to-have-the-set-misc-n) with latest nginx 1.21.5. ``` nginx load_module /nginx-1.21.5/objs/ndk_http_module.so; load_module /nginx-1.21.5/objs/ngx_http_set_misc_module.so; events {} http{ server { listen 80; location /my { proxy_pass http://xxxxxxxxxx; proxy_method POST; # set_unescape_uri in defined in set-misc-nginx-module set_unescape_uri $text $arg_text; proxy_set_body '{"text": "$text"}'; proxy_set_header Content-type application/json; } } } ``` my scripts ``` bash apt update apt-get install -y openssh-client git wget libxml2 libxslt1-dev libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev libtool automake gcc g++ make cd / wget "http://nginx.org/download/nginx-1.21.5.tar.gz" tar xvf nginx-1.21.5.tar.gz git clone https://github.com/vision5/ngx_devel_kit git clone https://github.com/openresty/set-misc-nginx-module cd nginx-1.21.5 ./configure --with-compat --with-http_ssl_module --add-dynamic-module=/ngx_devel_kit --add-dynamic-module=/set-misc-nginx-module make -j 30 nginx -s reload ``` ### slackbot If you already have a slackbot (https://github.com/slackapi/bolt-python) deployed, you can still add it inside your script: ``` python app.server().web_app.add_routes([web.get("/qnap_notify/xxxxx", proxy)]) ```