Telegram bot for InfluxDB.
Features:
- Browse InfluxDB schema
- Read values from InfluxDB
- Create chart visualizations from InfluxDB field values
- Save action shortcuts as buttons
- Define and receive notifications
-
Install npm dependencies:
npm i
-
Fill the required env variables listed in Configuration.
-
Start the bot in development mode:
npm run dev
The bot has a deployment template in order to deploy the bot to Fly.io.
-
Launch new Fly app:
flyctl launch
-
Copy
fly.toml.example
tofly.toml
. -
Set the required env variables:
- Deployment environment (
fly.toml
):[env] <key> = <value> <key> = <value> ...
- Secrets (Fly CLI):
flyctl secrets set <key>=<value> <key>=<value> ...
- Deployment environment (
-
Deploy the bot:
flyctl deploy
NOTE: To persist actions and notifications, add a mount for persistent storage!
Env variable | Description |
---|---|
TG_API_TOKEN |
Telegram API token |
TG_ALLOWED_USERNAMES |
Comma-separated list of allowed Telegram usernames |
INFLUX_URL |
InfluxDB URL |
INFLUX_TOKEN |
InfluxDB API token |
INFLUX_ORG |
InfluxDB organization |
TZ |
Timezone for date-fns |
The bot implements the following commands:
Command | Description |
---|---|
/help |
Get link to this section. |
buckets |
List all buckets. |
measurements |
List all measurements in a bucket. |
fields |
List all fields of a measurement. |
tags |
List all tags of a measurement. |
tag |
List all values of a tag. |
get |
Read values for a field. |
chart |
Create a chart visualization of field values. |
actions |
Run saved actions. |
actions_add |
Save new actions. |
actions_remove |
Remove saved actions. |
actions_get |
View saved actions. |
notifications |
View current notifications. |
notifications_add |
Add new notifications. |
notifications_remove |
Remove notifications. |
NOTE: Brackets [...]
indicate optional parameters!
Usage: /buckets
List all InfluxDB buckets.
Usage: /measurements <bucket> [<config>]
List all measurements in InfluxDB bucket.
Params:
bucket
: InfluxDB bucket nameconfig
: SeeInfluxTimespanParams
in<config>
.- Specify InfluxDB query timespan.
Usage: /fields <bucket> <measurement> [<config>]
List all fields of InfluxDB measurement.
Params:
bucket
: InfluxDB bucket namemeasurement
: InfluxDB measurement nameconfig
: SeeInfluxTimespanParams
in<config>
.- Specify InfluxDB query timespan.
Usage: /tags <bucket> <measurement> [<config>]
List all tags of InfluxDB measurement.
Params:
bucket
: InfluxDB bucket namemeasurement
: InfluxDB measurement nameconfig
: SeeInfluxTimespanParams
in<config>
.- Specify InfluxDB query timespan.
Usage: /tag <bucket> <measurement> <tag> [<config>]
List all tags of InfluxDB measurement.
Params:
bucket
: InfluxDB bucket namemeasurement
: InfluxDB measurement nametag
: InfluxDB tag nameconfig
: SeeInfluxTimespanParams
in<config>
.- Specify InfluxDB query timespan.
Usage: /get <bucket> <measurement> <field> <where> [<config>]
Read the latest values for InfluxDB field. The values can be filtered by specifying InfluxDB tag filter.
Params:
bucket
: InfluxDB bucket namemeasurement
: InfluxDB measurement namefield
: InfluxDB field namewhere
: InfluxDB tag filter consisting of tag-value pairs.- Tags and values are separated by equal sign (
=
) and pairs by commas (,
). *
can be used to match all values.- Example:
host=name,region=finland
can be used to find the values from specific host and region.
- Tags and values are separated by equal sign (
config
: SeeInfluxTagParams
in<config>
.- Specify InfluxDB query timespan.
- Specify the shown InfluxDB tags in the command response.
Usage: /chart <type> <bucket> <measurement> <field> <where> [<config>]
Create Chart.js visualization of InfluxDB field. The command returns InfluxDB fields as graph labels and tags as image caption. The graph values are aggregated by default.
Params:
type
: Graph type (line
orbar
)bucket
: InfluxDB bucket namemeasurement
: InfluxDB measurement namefield
: InfluxDB field namewhere
: InfluxDB tag filter consisting of tag-value pairs.- Tags and values are separated by equal sign (
=
) and pairs by commas (,
). *
can be used to match all values.- Example:
host=name,region=finland
can be used to find the values from specific host and region.
- Tags and values are separated by equal sign (
config
: SeeInfluxAggregateParams
andChartConfig
in<config>
.- Specify InfluxDB query timespan.
- Specify the shown InfluxDB tags in the command response.
- Specify InfluxDB aggregate timespan.
- Specify whether to query raw values from InfluxDB.
Usage: /actions
Run saved action.
Usage: /actions_add <name> <command...>
Save new action.
Params:
name
: Name of the actioncommand
: Command bound to the action
Example:
/actions_add "Example Action" /get my-bucket my-measurement my-field *
Usage: /actions_remove
Remove saved action.
Usage: /actions_get
View saved action.
Usage: /notifications
View current notification.
Usage: /notifications_add <name> <operator> <value> <intervalSeconds> <bucket> <measurement> <field> <where>
Add new notification.
The notifications will be checked in intervals, and the bot will send a message if the notification condition is met.
Params:
name
: Name of the notificationoperator
: Operator for the notification condition>
: Greater than<
: Less than>=
: Greater than or equal<=
: Less than or equal==
: Equal!=
: Not equal
value
: Value for the notification conditionintervalSeconds
: Notification check interval in secondsbucket
: InfluxDB bucket namemeasurement
: InfluxDB measurement namefield
: InfluxDB field namewhere
: InfluxDB tag filter consisting of tag-value pairs.- Tags and values are separated by equal sign (
=
) and pairs by commas (,
). *
can be used to match all values.- Example:
host=name,region=finland
can be used to find the values from specific host and region.
- Tags and values are separated by equal sign (
Usage: /notifications_remove
Remove notification.
<config>
consists of additional parameters for a bot command.
Configuration "object" consists of multiple key-value pairs:
- Keys and values are separated by equal sign (
=
). - If the value is a list, the list items are separated by commas (
,
). - Pairs are separated by semicolons (
;
). - Exaple:
firstKey=value;secondKey=secondValue1,secondValue2;thirdKey=thirdValue
The config can be one of the following:
Specify InfluxDB query timespan.
Keys:
start
: Start time of the query as a relative InxluxDB time or an absolute UTC time without milliseconds.- Relative format:
-7d
,-1h
,-5m
- Absolute format:
2023-02-28T19:00:00Z
- Default:
-7h
- Relative format:
end
: End time of the query as a relative InxluxDB time or an absolute UTC time without milliseconds.- Relative format:
1d
,-2h
,-10m
- Absolute format:
2023-02-28T19:00:00Z
- Relative format:
Specify returned InfluxDB tags.
Keys:
tags
: Comma-separated list of InfluxDB tags to return.
Specify InfluxDB aggregate properties. The used aggregate function is mean/average.
Keys:
aggregate
: InfluxDB aggregate timespan.- Default:
1h
- Default:
raw
: Whether to query raw values from InfluxDB (= disable aggregation).
Specify Chart.js properties.
Keys:
min
: Minimum y-value for the graph.max
: Maximum y-value for the graph.color
: Graph color offset (different offsets produce different color schemes).seconds
: Whether to show seconds in the x-axis labels.
MIT License Copyright (c) 2023 Iiro Kiviluoma