ZABBIX 1.8 – 7 Tutorials

Please Like Us!!!

7 Tutorials

This section contains step-by-step instructions for most common tasks.

1 Extending Zabbix Agents

This tutorial provides step-by-step instructions how to extend functionality of Zabbix agent.

Step 1

Write a script or command line to retrieve required parameter.

For example, we may write the following command in order to get total number of queries executed by a MySQL server:

mysqladmin -uroot status|cut -f4 -d":"|cut -f1 -d"S"

When executed, the command returns total number of SQL queries.

Step 2

Add this command to agent's configuration file.

Add the command to zabbix_agentd.conf:

UserParameter=mysql.questions,mysqladmin -uroot status|cut -f4 -d":"|cut -f1 -d"S"

mysql.questions is an unique identifier. It can be any string, for example, queries.

Test this parameter by using zabbix_get utility.

Step 3

Restart Zabbix agent.

Agent will reload configuration file.

Step 4

Add new item for monitoring.

Add new item with Key=mysql.questions to the monitored host. Type of the item must be either Zabbix Agent or Zabbix Agent (active).

Be aware that type of returned values must be set correctly on Zabbix server. Otherwise Zabbix won't accept them.

2009/08/13 13:38
· Alexei

2 Monitoring of log files

This tutorial provides step-by-step instructions how to setup monitoring of log files. It is assumed that a host is configured already in Zabbix frontend.

Step 1

Configure Zabbix agent.

Follow standard instructions in order to install and configure agent on monitored host. Make sure that parameter Hostname matches host name of the host configured in Zabbix frontend.

Also make sure that parameter DisableActive is not set in zabbix_agentd.conf

Step 2

Add a new item for monitoring of a log file.

Pay attention to the following parameters of the item:

PARAMETER Description
Type Must be set to 'Zabbix agent (active)'.
Key Must be set to 'log[file<,regexp>]'. For example: log[/var/log/syslog], log[/var/log/syslog,error]. Make sure that the file has read permissions for user 'zabbix' otherwise the item status will be set to 'unsupported'. Zabbix agent will filter entries of log file by the regexp if present.
Type of information Must be set to 'log'.
Update interval (in sec) The parameter defines how often Zabbix agent will check for any changes in the log file. Normally must be set to 1 second in order to get new records as soon as possible.
2009/08/13 13:40
· Alexei

3 Remote commands

This tutorial provides step-by-step instructions on how to setup remote execution of pre-defined commands in case on an event. It is assumed that Zabbix is configured and operational.

Step 1

On Zabbix agent, enable remote commands. In zabbix_agentd.conf make sure that parameter EnableRemoteCommands is set to 1 and uncommented. Restart agent daemon if changing this parameter.

Step 2

Configure new action by going to Configuration → Actions and in the New action block choose operation type Remote command.

Pay attention to the following parameters of the action:

PARAMETER Description
Action type Must be set to 'Remote command'.
Remote command Each line must contain an command for remote execution. For example: host:sudo /etc/init.d/apache restart. Remote command may contain macros!

Note the use of sudo – Zabbix user does not have permissions to restart system services by default. See below for hints on how to configure sudo.

Syntax of remote commands:

REMOTE COMMAND Description
{HOSTNAME}:<command> Command 'command' will be executed on the host where the event happened.
<host>:<command> Command 'command' will be executed on host 'host'.
<group>#<command> Command 'command' will be executed on all hosts of host group 'group'.

Zabbix agent executes commands in background. Zabbix does not check if a command has been executed successfully.

Remote commands in Zabbix < 1.4 are limited to 44 characters, in Zabbix >= 1.4 they are limited to 255 characters.

Syntax of IPMI remote commands:

REMOTE COMMAND Description
{HOSTNAME}:IPMI <ipmi control> [value] The syntax is for execution of IPMI command on the host where the event happened. Supported values: “on”, “off” or number (1, by default).
<host>:IPMI <ipmi control> [value] The syntax is for execution of IPMI command on a single host.
<group>#IPMI <ipmi control> [value] The syntax is for execution of IPMI command for all hosts of a host group.
Access permissions

Make sure that user 'zabbix' has execute permissions for configured commands. One may be interested in using sudo to give access to privileged commands. To configure access, execute as root:

# visudo

Example lines that could be used in sudoers file:

# allows 'zabbix' user to run all commands without password.
zabbix ALL=NOPASSWD: ALL
# allows 'zabbix' user to restart apache without password.
zabbix ALL=NOPASSWD: /etc/init.d/apache restart

On some systems sudoers file will prevent non-local users from executing commands. To change this, comment out requiretty option in /etc/sudoers.

On recent systems it might be required to set Defaults visiblepw in /etc/sudoers.

Example 1

Restart of Windows on certain condition.

In order to automatically restart Windows in case of a problem detected by Zabbix, define the following actions:

PARAMETER Description
Action type 'Remote command'
Remote command host:c:\windows\system32\shutdown.exe -r -f
Replace 'host' with Zabbix hostname of Windows server.
Example 2

Restart the host by using IPMI control.

PARAMETER Description
Action type 'Remote command'
Remote command {HOSTNAME}:IPMI reset on
Example 3

Power off the host by using IPMI control.

PARAMETER Description
Action type 'Remote command'
Remote command {HOSTNAME}:IPMI power off
2009/08/13 13:50
· Alexei

4 Monitoring of Windows Services

This tutorial provides step-by-step instructions how to setup monitoring of Windows services. It is assumed that ZABBIX server and ZABBIX agent are configured and operational.

Step 1

Get service name

You can get that name by going to the services mmc and bring up the properties of the service you want to monitor it's up/down status. In the General tab you should see a field called Service name. The value that follows that you put in the brackets above. For example, if I wanted to monitor the “workstation” service then my service would be lanmanworkstation.

Step 2

Add item for monitoring of the service

Add item with a key service_state[lanmanworkstation], value type Integer, value mapping Windows service state.

2009/08/13 13:50
· Alexei

Data source: Zabbix

Reviews & Comments

Enjoy!