Deploy Zabbix 4.0 with Grafana dashboards in Docker-compose
This guide is about how to deploy a Zabbix monitoring system with Grafana to display graphs.
The whole installation will be divided into 3 parts. The first step is setting up Zabbix, the second step is connecting Zabbix to Grafana, and the third step is creating Telegram bot and connect to Zabbix for notifications.
Prerequisites:
Clone this repo to your host:
git clone https://github.com/moovs/zabbix-grafana.git
Build and start docker-compose file:
cd /path/to/zabbix-grafana
docker-compose up -d --build
Move telegram script to alertscripts:
mv telegram alertscripts/
Set right permission to telegram script and make it executable:
cd alertscripts/
chown -R zabbix telegram
chmod +x telegram
Step 1. Zabbix setup.
Login to Zabbix web interface with default 80 port:
the default user is “admin” and the password is “zabbix”
Change admin password:
- navigate to
Administration
thenUsers
selectAdmin
and clickChange password
If you want to monitor your instance with Zabbix, you need to install zabbix-agent on this host:
in this case, we install Zabbix agent of the 4.0 version:
wget https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb
dpkg -i zabbix-release_4.0-2+stretch_all.deb
apt-get update
apt-get install zabbix-agent
Update Zabbix agent config:
- after that you need to change point
Server=
in/etc/zabbix/zabbix_agentd.conf
config to IP address your zabbix-server containerServer=172.16.238.10
and restart zabbix-agent/etc/init.d/zabbix-agent restart
Change Zabbix server IP address:
- and the last step, go to
Configuration
thenHosts
click onZabbix server
and change IP address to IP address your host:
Check monitoring data:
- after few minutes, monitoring data will start flowing in, to check host graphs go to
Moniroting
thenGraphs
:
Step 2. Grafana setup.
Login to Grafana:
- login to Grafana web interface with default 3000 port login with default credentials and change admin password:
default login and password is
admin
Enable Zabbix plugin:
- go to
Zabbix
inInstalled Apps
and enable Zabbix plugin or just clickEnable now
:
Configure the data source as follows:
- enter a name for this new data source in the
Name
field. - fill in the
Url
field with the full path to the Zabbix API, which will be http://your_zabbix_server_ip_address/api_jsonrpc.php. - fill in the
Username
andPassword
fields inZabbix API details
block with theusername
andpassword
for Zabbix.
- click
Save & Test
to save and test your configuration. If you did everything correctly you will see the following message:
- here you may import some dashboards for vizualizations, just click to
Dashboards
and importZabbix Server Dashboard
andZabbix Template Linux Server
:
- to see them go to
Home
:
- and select your dashboards to see graphs:
Step 3. Сonnecting and setting up a Telegram to Zabbix.
If you want send alert notifications to Telegram channel you need create Telegram bot.
Create Telegram Bot.
- firstly go to
BotFather
in your Telegram. - in
BotFather
type/start
see informations about what you can do or just type/newbot
for create your bot. - the next you will be asked to give a name and username to your bot.
it must end in
bot
. Like this, for example: TetrisBot or tetris_bot.
- after that you received your bot token to access the HTTP API, copy this token in you
Telegram
script in lineBOT_TOKEN
- get the list of updates for your BOT for that follow this link and substitute your
bot token
https://api.telegram.org/bot<YourBOTToken>/getUpdates
- login to the Telegram web in your browser and find your bot by username and click on
Start
button. - create your new group and add here your bot.
- now refresh this link to see you
group chat id
.
your group chat id will be start with minus sign like this
-635324858
- after that you can send test notification in your chat group:
docker exec -ti zabbix_server bash
cd /usr/lib/zabbix/alertscripts/
./telegram -635324858 test mesage
if you received test message you can move on.
Create Media type in Zabbix.
- after everything done you need go to Zabbix web interface to
Administration
>Media types
and chooseCreate media type
:
- enter a name for media type in the
Name
andScript name
fields and chooseScript
inType
fields. - fill in
Script parameters
fields next parameters:{ALERT.SENDTO}
,{ALERT.SUBJECT}
and{ALERT.MESSAGE}
. - then go to
User profile: Zabbix Administrator
, click onhuman icon
in the right corner and chooseMedia
tab:
- choose
Type
telegram in the fieldSend to
substitute your group chat id-635324858
and clickadd
thenUpdate
. - the next go to
Configuration
thenActions
and chooseHost
,equals
and name of your serverZabbix server
and clickAdd
button thenUpdate
:
- don't forget
Enable
it onActions
page:
- now you can test you alerting system, go to instance with Zabbix server and stop your zabbix_agent:
service zabbix-agent stop
and after waiting a few minutes you revieved alert massage to your group in Telegram: