Inspired by BotKit samples for Webex Teams by Stève Sfartz mailto:stsfartz@cisco.com
Either if you deploy locally or to Heroku, you'll need to perform these two tasks first:
Create a Bot Account from the 'Webex for developers' bot creation page, and copy your bot's access token.
Create an AppDynamics account if you don't already have one and copy your AppD account name (TIP: for SaaS deployments, the account name is what comes before "saas.appdynamics.com" in the URL).
Note: If you just need to demostrate the functionality of the bot, you don't need an AppDynamics account. You can just checkout the demo
branch of this repository and launch a completely stand alone bot with dummy data.
Click below to quickly deploy the bot to Heroku. You will need the following information:
https://{app-name}.herokuapp.com
, where {app-name}
is the name you chose for your Heroku app).Note: Again, if you just need to demostrate the functionality of the bot, you don't need an AppDynamics account. You can just deploy the demo
branch of this repository to Heroku navigating first to the demo branch.
Choose your storage type. You have two options: local storage using JSON File Store (JFS) or Redis, a NO-SQL, in-memory data structure store. If you choose to use JFS, you don't have to install anything yourself. If you choose to use Redis you'll need to download and install it on your local machine, with the default settings (port 6379).
[Optional] Webex Teams uses a webhook to send incoming messages to your bot, but webhooks require a public IP address. If you don't have one, you can use ngrok to create a tunnel to your machine. Launch ngrok to expose port 3000 of your local machine to the internet:
ngrok http 3000
Pick the HTTPS address that ngrok is now exposing. Note that ngrok exposes HTTP and HTTPS protocols, make sure to pick the HTTPS address.
[Optional] Open the .env
file and modify the settings to accomodate your bot.
Note that you can also specify any of these settings via env variables. In practice, the values on the command line or in your machine env will prevail over .env file settings. In the example below, we do not modify any value in settings and specify all configuration values on the command line.
You're ready to run your bot
From a bash shell, type:
> git clone https://github.com/AltusConsulting/sparkbot-appd-botkit.git > cd sparkbot-appd-botkit > npm install > BOT_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io SECRET="not that secret" APPD_ACCOUNT=myappdaccount1234567890 node bot.js
If you're using Redis, this last command would be:
> BOT_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io SECRET="not that secret" APPD_ACCOUNT=myappdaccount1234567890 REDIS_URL=redis://localhost:6379/1 node bot.js
From a windows shell, type:
> git clone https://github.com/AltusConsulting/sparkbot-appd-botkit.git > cd sparkbot-appd-botkit > npm install > set BOT_TOKEN=0123456789abcdef > set PUBLIC_URL=https://abcdef.ngrok.io > set SECRET=not that secret > set APPD_ACCOUNT=myappdaccount1234567890 > node bot.js
If you're using Redis, you'll need to add an additional environment variable before launching the bot:
> set REDIS_URL=redis://localhost:6379/1
where:
To test that your bot is online, add it to your Webex Teams account as you will add any other contact and ask the bot for help with the help
command.
The notifications module allows you to subscribe to specific types of notifications (Errors, Warnings and Informational), so that when your AppDynamics instance detects an event in one of your monitored applications the AppD Bot will send you a message directly via Webex Teams.
You can subscribe to a notification by telling the AppD Bot:
subscribe
or, for short:
sub
The bot will then ask you what type of notification you want to subscribe to. You can subscribe to INFO, WARN or ERROR notifications.
You can subscribe to a notification by telling the AppD Bot:
unsubscribe
or, for short:
unsub
The bot will then ask you what type of notification you want to unsubscribe from.
You can ask the bot for a list of your current subscriptions:
show subscriptions
or, for short:
show sub
You can interactively query your AppDynamics instance to get information about applications, events and application metrics.
You can show the existing configured applications with the following command:
show applications
or, for short:
show apps
The bot will then show a list of the existing applications.
You can request the recent events for a specific application with the following command:
show events
or, for short:
show ev
The bot will then ask for the application for which you want to retrieve the events. Once you answer with one of the available applications the bot will then show a list of the most recent events for that specific application. For the time being this command retrieves events for the last week only. In the future this will be configurable.
You can request the metrics for a specific application with the following command:
show metrics for <app name>
for example, if there's an application called MyNodeApp, the command should be:
show metrics for MyNodeApp
The bot will then answer with all the Overall Application Performance metrics for the last 60 minutes. In the future, other metrics will be available as well and the time period will be configurable.
In order for notifications to be sent to your bot, you need to configure your AppD server accordingly. Here are the steps:
[
#foreach(${event} in ${fullEventList})
#set( $msg = $event.summaryMessage.replace("
", "\\n") )
{"app": "${event.application.name}",
"appid": "${event.application.id}",
"tier": "${event.tier.name}",
"node": "${event.node.name}",
"time": "${event.eventTime}",
"deeplink": "${event.deepLink}",
"name": "${event.displayName}",
"severity": "${event.severity}",
"message": "${msg}"}
#if($velocityCount != $fullEventList.size()) , #end
#end
]
Now you should begin receiving notifications from the AppD Bot on Webex Teams, once you subscribe to them.
Owner
Contributors
Categories
Products
AppDynamicsWebexProgramming Languages
JavaScriptLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community