We use Telegram and Slack to receive system monitoring message. We need to manage message and unify the methods. So we start to develop centralized server to easily send message to Telegram and Slack at once.
- Telegram
- Slack
- Discord
- Hangout
- Webhook
Automatically, default configuration files are created when application is executed. You can make default configuration files through just executing application and modify it for you. You can find it at config directory.
Perri has three configuration files.
It's application configuration file.
# Server port
port:
main_http: 59490
api_http: 59491
It's channel configuration file.
# Unique channel name
[channel_name]:
# Telegram
- type: "telegram"
bot_api_token: ""
chat_id: ""
display_tags: true
merge_duplicate_message: true
# Slack
- type: "slack"
incoming_webhook_url: ""
display_tags: true
merge_duplicate_message: true
# Discord
- type: "discord"
incoming_webhook_url: ""
display_tags: true
merge_duplicate_message: true
# Hangout
- type: "hangout"
incoming_webhook_url: ""
display_tags: true
merge_duplicate_message: true
# Webhook
- type: "webhook"
webhook_url: ""
display_tags: true
merge_duplicate_message: true
It's Logback configuration file that is famous logging library.
- You can send error log to Telegram.
- Uncomment Telegram configuration.
- Set value of
<botToken>
and<chatId>
.<appender name="TELEGRAM" class="com.github.paolodenti.telegram.logback.TelegramAppender"> <botToken></botToken> <chatId></chatId> ... </appender>
- Insert
<appender-ref ref="TELEGRAM"/>
into<root>
<root level="WARN"> <appender-ref ref="FILE"/> <appender-ref ref="TELEGRAM"/> </root>
- You can send error log to Slack.
- Uncomment Slack configuration.
- Set value of
<webhookUri>
.<appender name="SLACK_SYNC" class="com.github.maricn.logback.SlackAppender"> <webhookUri></webhookUri> ... </appender>
- Insert
<appender-ref ref="SLACK"/>
into<root>
<root level="WARN"> <appender-ref ref="FILE"/> <appender-ref ref="SLACK"/> </root>
- You can reload configuration but need not to restart application.
Perri has two servers. One is a main server that send message to messenger. The other is a restful API server that provide application information and additional functions.
http://example.com:{port}/{channel}?message={message}&tags={tag1,tag2,tag3}
- port
- Server port
- It's main_http in app_config.yml.
- channel
- Channel name
- It's channel in channel_config.yml
- message
- Sending message
- If message length are more than supported maximum length, truncate string with ellipsis.
- tags
- It's optional
- Tags of message
- Comma or space separated
- Max 20 tags (If tags count are more than maximum, ignore some tags )
- Max 30 characters per tag (If tag characters more than maximum, ignore tag)
http://example.com:59490/perri_default_channel?message=hello&tags=world,perri,tag
Send message to Telegram using bot id and chat id
Send message to Slack using incoming webhook url
https://api.slack.com/incoming-webhooks
Discord message to Discord using incoming webhook url
https://discordapp.com/developers/docs/resources/webhook
Hangout message to Hangout using incoming webhook url
https://developers.google.com/hangouts/chat/reference/message-formats/
Send message to specific url via an HTTP POST request.
{
"channel": "perri_default_channel",
"message": "webhook message",
"tags": "tag1,tag2,tag3",
"duplicated": 2
}
http://example.com:{port}/{domain}/{method}
http://example.com:59491/app/status
http://example.com:59491/app/hello
http://example.com:59491/app/ping
- Get application environments
{
"data":{
"applicationVersion": "1.4.0",
"hostname": "hostname",
"osVersion": "10.11.6",
"jarFile": "code13k-perri-1.0.0-alpha.1.jar",
"javaVersion": "1.8.0_25",
"ip": "192.168.0.121",
"javaVendor": "Oracle Corporation",
"osName": "Mac OS X",
"cpuProcessorCount": 4
}
}
- Get application status
{
"data":{
"threadInfo":{...},
"cpuUsage": 2.88,
"threadCount": 25,
"currentDate": "2018-10-02T01:15:21.290+09:00",
"startedDate": "2018-10-02T01:14:40.995+09:00",
"runningTimeHour": 0,
"vmMemoryUsage":{...}
}
}
- Hello, World
{"data":"world"}
- Ping-Pong
{"data":"pong"}