manasesjesus / c8y_microservice-nodejs

Cumulocity IoT - Microservice developed using Node.js and Docker. It notifies a Slack channel when there are alarms in the subscribed tenants.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cumulocity IoT Microservice

Codacy Badge

Cumulocity IoT microservice developed using Node.js and Docker. It notifies a Slack channel when there are alarms in the subscribed tenants.

Prerequisites

  • Local Docker installation.
  • A Cumulocity IoT account. Create a free trial to test this example.
  • Slack channel to post messages to, Slack app and OAuth token.
  • A .env file in the root directory with the following content:
PORT=80
SLACK_OAUTH_TOKEN=<YOUR-TOKEN-GOES-HERE>
SLACK_CHANNEL_ID=<YOUR-CHANNEL_ID-GOES-HERE>

Build

Execute the following commands to build the Docker image and save it as image.tar:

$ docker build -t mynode-microservice .
$ docker save mynode-microservice > "image.tar"

Then pack image.tar together with the manifest cumulocity.json into a ZIP file.

$ zip mynode-microservice cumulocity.json image.tar

The resulting mynode-microservice.zip file contains the microservice and it is ready to be uploaded to the Cumulocity IoT platform.

Deployment

Deploy the microservice application (refer to Adding own applications in the Cumulocity IoT's User guide) and subscribe it afterwards. It may take some minutes for the ZIP file to be uploaded.

Execution

Use a web browser or a terminal command (e.g. cURL) to make a GET request to the microservice endpoints.

GET <tenant-domain>.cumulocity.com/service/mynode-microservice/environment

The Slack channel will get the posted messages every time a new alarm is raised on the subscribed tenants.

Slack app posting alarms

About

Cumulocity IoT - Microservice developed using Node.js and Docker. It notifies a Slack channel when there are alarms in the subscribed tenants.

License:MIT License


Languages

Language:JavaScript 97.7%Language:Dockerfile 2.3%