Zabbix-CLI


Rafael Martinez Guerrero (University of Oslo)


Introduction

Zabbix-cli is a terminal client for managing Zabbix administration tasks via the Zabbix API.

The zabbix-cli code is distributed under the GNU General Public License 3 and it is written in Python. It has been developed and tested by members of the Department for IT Infrastructure at the Center for Information Technology at the University of Oslo, Norway.

Main features

  • Terminal client

  • Two execution modes available: Zabbix-CLI shell and commandline.

  • 54 zabbix-CLI commands available.

  • Multilevel configuration system.

  • Possibility to define Bulk updates. Several performance improvements are used when running in bulk modus.

  • Authentication-token, authentication-file and environment variables support for autologin.

  • Support for plain, CSV and JSON output.

  • Online help

  • Written in Python.

Configuration

Configuration file

Zabbix-cli has a multilevel configuration system.

This means that we do not override entire configuration files but we merge all the defined configuration files in our system and use the parameter values defined in the configuration file with higher priority if a parameter is defined in more than one file.

The ordered list with the files with higher on top:

  1. /usr/share/zabbix-cli/zabbix-cli.fixed.conf

  2. /etc/zabbix-cli/zabbix-cli.fixed.conf

  3. Configuration file defined with the parameter -c / --config when executing zabbix-cli

  4. $HOME/.zabbix-cli/zabbix-cli.conf

  5. /etc/zabbix-cli/zabbix-cli.conf

  6. /usr/share/zabbix-cli/zabbix-cli.conf

The default configuration file can be found in /usr/share/zabbix-cli/zabbix-cli.conf or etc/zabbix-cli.conf in the source code.

The easiest way to configurate your client will be running this command to create your own $HOME/.zabbix-cli/zabbix-cli.conf file.:

# zabbix-cli-init <zabbix API url>

The parameter zabbix_api_url must be defined in the configuration file. Without this parameter, zabbix-cli will not know where to connect. This parameter will be defined automatically if you have run the command zabbix-cli-init.

Remember to activate logging with logging=ON if you want to activate logging. The user running zabbix-cli must have read/write access to the log file defined with log_file. This parameter will be defined automatically with an OFF value if you have run the command zabbix-cli-init.

To see all the active configuration files in your system and the configuration parameters that zabbix-cli is using, use show_zabbixcli_config:

[zabbix-cli rafael@zabbix-ID]$ show_zabbixcli_config

+----------------------------------------------+
| Active configuration files                   |
+----------------------------------------------+
| */usr/share/zabbix-cli/zabbix-cli.fixed.conf |
| */etc/zabbix-cli/zabbix-cli.fixed.conf       |
| */root/.zabbix-cli/zabbix-cli.conf           |
| */etc/zabbix-cli/zabbix-cli.conf             |
| */usr/share/zabbix-cli/zabbix-cli.conf       |
+----------------------------------------------+

+--------------------------------------+---------------------------------------+
|              Configuration parameter | Value                                 |
+--------------------------------------+---------------------------------------+
|                       zabbix_api_url | https://zabbix.example.org            |
|                          cert_verify | ON                                    |
|                            system_id | zabbix-ID                             |
|                    default_hostgroup | All-hosts                             |
|              default_admin_usergroup | Zabbix-admin                          |
|        default_create_user_usergroup | All-users                             |
| default_notification_users_usergroup | All-notification-users                |
|            default_directory_exports | /home/user/zabbix_exports             |
|                default_export_format | XML                                   |
|    include_timestamp_export_filename | ON                                    |
|                           use_colors | ON                                    |
|                           use_paging | OFF                                   |
|                  use_auth_token_file | ON                                    |
|                              logging | ON                                    |
|                            log_level | INFO                                  |
|                             log_file | /home/user/.zabbix-cli/zabbix-cli.log |
+--------------------------------------+---------------------------------------+

Environment Authentication

You can define the ZABBIX_USERNAME and ZABBIX_PASSWORD environment variables to pass authentication credentials to zabbix-cli.

For example:

export ZABBIX_USERNAME=zbxuser
read -srp "Zabbix Password: " ZABBIX_PASSWORD; export ZABBIX_PASSWORD;
zabbix-cli

NOTE: It is important to remember that this method will save the password in clear text in a environment variable. This value will be available to other processes running in the same session.

Authentication file

You can define the file $HOME/.zabbix-cli_auth if you want to avoid to write your username and password everytime you use zabbix-cli. This can be useful if you are running zabbix-cli in non-interactive modus from scripts or automated jobs.

The format of this file is a line with this information:

USERNAME::PASSWORD

NOTE: The password will be saved in clear text so be careful with the information saved here and restrict access to this file only to your user. chmod 400 ~/.zabbix-cli_auth will be defined by zabbix-cli on this file the first time it uses it.

Authentication token file

The file $HOME/.zabbix-cli_auth_token will be created with information about the API-auth-token from the last login if the parameter use_auth_token_file=ON is defined in the configuration file.

The information in this file will be used, if we can, to avoid having to write the username and password everytime you use zabbix-cli. This can be useful if you are running zabbix-cli in non-interactive modus from scripts or automated jobs.

This authentication method will work as long as the API-auth-token saved is active in Zabbix. The Auto-logout attribute of the user will define how long the API-auth-token will be active.

If the API-auth-token is not valid, zabbix-cli will delete the file $HOME/.zabbix-cli_auth_token and you will have to login again with a valid username and password.

Zabbix-CLI shell

The Zabbix-CLI interactive shell can be started by running the program /usr/bin/zabbix-cli

[user@host]# zabbix-cli

#############################################################
Welcome to the Zabbix command-line interface (v2.1.0)
Connected to server https://zabbix.example.org (v4.0.6)
#############################################################
Type help or \? to list commands.

[zabbix-cli user@zabbix-ID]$ help

Documented commands (type help <topic>):
========================================
EOF                             show_alarms
acknowledge_event               show_global_macros
acknowledge_trigger_last_event  show_history
add_host_to_hostgroup           show_host
add_user_to_usergroup           show_host_inventory
add_usergroup_permissions       show_host_usermacros
clear                           show_hostgroup
create_host                     show_hostgroup_permissions
create_host_interface           show_hostgroups
create_hostgroup                show_hosts
create_maintenance_definition   show_items
create_notification_user        show_last_values
create_user                     show_maintenance_definitions
create_usergroup                show_maintenance_periods
define_global_macro             show_template
define_host_monitoring_status   show_templates
define_host_usermacro           show_trigger_events
export_configuration            show_triggers
help                            show_usergroup
import_configuration            show_usergroup_permissions
link_template_to_host           show_usergroups
load_balance_proxy_hosts        show_usermacro_host_list
move_proxy_hosts                show_usermacro_template_list
quit                            show_users
remove_host                     show_zabbixcli_config
remove_host_from_hostgroup      unlink_template_from_host
remove_maintenance_definition   update_host_inventory
remove_user                     update_host_proxy
remove_user_from_usergroup      update_usergroup_permissions
shell

Miscellaneous help topics:
==========================
shortcuts  support

NOTE: It is possible to use Zabbix-CLI in a non-interactive mode by running /usr/bin/zabbix-cli with the parameter --command <zabbix_command> or -C <zabbix_command> in the OS shell. This can be used to run zabbix-cli commands from shell scripts or other programs .e.g.

[user@host]# zabbix-cli -C "show_usergroups"

+---------+---------------------------+--------------------+-------------+
| GroupID | Name                      |     GUI access     |    Status   |
+---------+---------------------------+--------------------+-------------+
|      13 | DBA                       | System default (0) |  Enable (0) |
|       9 | Disabled                  | System default (0) | Disable (1) |
|      11 | Enabled debug mode        | System default (0) |  Enable (0) |
|       8 | Guests                    |    Disable (2)     | Disable (1) |
|      12 | No access to the frontend |    Disable (2)     |  Enable (0) |
|      49 | testgroup                 | System default (0) |  Enable (0) |
|      15 | Test users                | System default (0) |  Enable (0) |
|      16 | Test users intern         |    Internal (1)    |  Enable (0) |
|       7 | Zabbix administrators     |    Internal (1)    |  Enable (0) |
|      14 | Zabbix core               | System default (0) |  Enable (0) |
+---------+---------------------------+--------------------+-------------+

It is possible to use the parameter --file <zabbix_command_file> or -f <zabbix_command_file> to define a file with multiple zabbix-cli commands for scripting.

Some performance improvements get activated when executing zabbix-cli in this way. The perfomance gain when running multiple commands via an input file can be as high as 70% when creating new hosts in Zabbix.

[user@host]# cat zabbix_input_file.txt

# This a comment.
# Creating hosts.

create_host test000001.example.net All-manual-hosts .+ 1
create_host test000002.example.net All-manual-hosts .+ 1
create_host test000003.example.net All-manual-hosts .+ 1

# Deleting hosts

remove_host test000001.example.net
remove_host test000002.example.net
remove_host test000003.example.net

[user@host]# zabbix-cli -f zabbix_input_file.txt

[OK] File [/home/user/zabbix_input_file.txt] exists. Bulk execution of commands defined in this file started.

[Done]: Host (test000001.example.net) with ID: 14213 created
[Done]: Host (test000002.example.net) with ID: 14214 created
[Done]: Host (test000003.example.net) with ID: 14215 created
[Done]: Hosts (test000001.example.net) with IDs: 14213 removed
[Done]: Hosts (test000002.example.net) with IDs: 14214 removed
[Done]: Hosts (test000003.example.net) with IDs: 14215 removed

One can also use the parameters --output csv or --output json when running zabbix-cli in non-interactive modus to generate an output in CSV or JSON format.

[user@host ~]# zabbix-cli --output csv show_usergroups

"13","DBA","System default (0)","Enable (0)"
"9","Disabled","System default (0)","Disable (1)"
"11","Enabled debug mode","System default (0)","Enable (0)"
"8","Guests","Disable (2)","Disable (1)"
"12","No access to the frontend","Disable (2)","Enable (0)"
"49","testgroup","System default (0)","Enable (0)"
"15","Test users","System default (0)","Enable (0)"
"16","Test users intern","Internal (1)","Enable (0)"
"7","Zabbix administrators","Internal (1)","Enable (0)"
"14","Zabbix core","System default (0)","Enable (0)"

Remember that you have to use "" and escape some characters if running commands in non-interactive mode with parameters that have spaces or special characters for the shell, .e.g.

[user@host ~]# zabbix-cli -C "show_host * \"'available':'2','maintenance_status':'1'\" "

+--------+----------------------+-------------------------+-----------------------------------+--------------------+-----------------+-----------------+---------------+
| HostID | Name                 | Hostgroups              | Templates                         | Applications       |   Zabbix agent  |   Maintenance   |     Status    |
+--------+----------------------+-------------------------+-----------------------------------+--------------------+-----------------+-----------------+---------------+
|  10110 | test01.uio.no        | [8] Database servers    | [10102] Template App SSH Service  | CPU                | Unavailable (2) | In progress (1) | Monitored (0) |
|        |                      |                         | [10104] Template ICMP Ping        | Filesystems        |                 |                 |               |
|        |                      |                         | [10001] Template OS Linux         | General            |                 |                 |               |
|        |                      |                         |                                   | ICMP               |                 |                 |               |
|        |                      |                         |                                   | Memory             |                 |                 |               |
|        |                      |                         |                                   | Network interfaces |                 |                 |               |
|        |                      |                         |                                   | OS                 |                 |                 |               |
|        |                      |                         |                                   | Performance        |                 |                 |               |
|        |                      |                         |                                   | Processes          |                 |                 |               |
|        |                      |                         |                                   | SSH service        |                 |                 |               |
|        |                      |                         |                                   | Security           |                 |                 |               |
|        |                      |                         |                                   | Zabbix agent       |                 |                 |               |
+--------+----------------------+-------------------------+-----------------------------------+--------------------+-----------------+-----------------+---------------+
|  10484 | test02.uio.no        | [12] Web servers        | [10094] Template App HTTP Service | HTTP service       | Unavailable (2) | In progress (1) | Monitored (0) |
|        |                      | [13] PostgreSQL servers | [10073] Template App MySQL        | ICMP               |                 |                 |               |
|        |                      | [17] MySQL servers      | [10102] Template App SSH Service  | MySQL              |                 |                 |               |
|        |                      | [21] ssh servers        | [10104] Template ICMP Ping        | SSH service        |                 |                 |               |
|        |                      | [5] Discovered hosts    |                                   |                    |                 |                 |               |
|        |                      | [8] Database servers    |                                   |                    |                 |                 |               |
+--------+----------------------+-------------------------+-----------------------------------+--------------------+-----------------+-----------------+---------------+
|  10427 | test03.uio.no        | [12] Web servers        | [10094] Template App HTTP Service | HTTP service       | Unavailable (2) | In progress (1) | Monitored (0) |
|        |                      | [17] MySQL servers      | [10073] Template App MySQL        | ICMP               |                 |                 |               |
|        |                      | [21] ssh servers        | [10102] Template App SSH Service  | MySQL              |                 |                 |               |
|        |                      | [5] Discovered hosts    | [10104] Template ICMP Ping        | SSH service        |                 |                 |               |
|        |                      | [8] Database servers    |                                   |                    |                 |                 |               |
+--------+----------------------+-------------------------+-----------------------------------+--------------------+-----------------+-----------------+---------------+

Interactive shell commands

class zabbix_cli.cli.zabbixcli

This class implements the Zabbix shell. It is based on the python module cmd.

do_EOF()

Quit/terminate the Zabbix-CLI shell.

do_acknowledge_event()

This command acknowledges an event

acknowledge_events [eventIDs]
                   [message]
                   [close]

[eventIDs]

IDs of the events to acknowledge. One can define several values in a comma separated list.

[message]

Text of the acknowledgement message.

[close]

Whether to also close the event.

Values:

  • false - (default) Leave the event open.

  • true - Close the event.

do_acknowledge_trigger_last_event()

This command acknowledges the last event of a trigger.

acknowledge_trigger_last_event [triggerIDs]
                               [message]
                               [close]

[triggerIDs]

IDs of the triggers to acknowledge. One can define several values in a comma separated list.

[message]

Text of the acknowledgement message.

[close]

Whether to also close the event.

Values:

  • false - (default) Leave the event open.

  • true - Close the event.

do_add_host_to_hostgroup()

This command adds one/several hosts to one/several hostgroups

add_host_to_hostgroup [hostnames]
                      [hostgroups]

[hostnames]

Hostnames or IDs. One can define several values in a comma separated list.

[hostgroups]

Hostgroup names or IDs. One can define several values in a comma separated list.

do_add_user_to_usergroup()

This command adds one/several users to one/several usergroups

add_user_to_usergroup [usernames]
                      [usergroups]

[usernames]

Usernames or IDs. One can define several values in a comma separated list.

[usergroups]

Usergroup names or IDs. One can define several values in a comma separated list.

do_add_usergroup_permissions()

This command adds a permission for an usergroup on a hostgroup.

If the usergroup already have permissions on the hostgroup, nothing will be changed.

add_usergroup_permissions [usergroup]
                          [hostgroups]
                          [permission code]

[usergroup]

Usergroup that will get a permission on a hostgroup

[hostgroups]

Hostgroup names where the permission will apply.

One can define several values in a comma separated list.

[permission]

  • deny: Deny [usergroup] all access to [hostgroups]

  • ro: Give [usergroup] read access to [hostgroups]

  • rw: Give [usergroup] read and write access to [hostgroups]

do_clear()

Clears the screen and shows the welcome banner.

do_create_host()

This command creates a host.

create_host [hostname|IP]
            [hostgroups]
            [proxy]
            [status]

[hostname|IP]

Hostname or IP

[hostgroups]

Hostgroup names or IDs. One can define several values in a comma separated list.

Remember that the host will get added to all hostgroups defined with the parameter default_hostgroup in the zabbix-cli configuration file zabbix-cli.conf.

This command will fail if both default_hostgroup and [hostgroups] are empty.

[proxy]

Proxy server used to monitor this host. One can use regular expressions to define a group of proxy servers from where the system will choose a random proxy.

If this parameter is not defined, the system will assign a random proxy from the list of all available proxies.

If the system does not have proxy servers defined, the new host will be monitor by the Zabbix-server.

Some regular expressions that can be used:

  • proxy-(prod|test)+d\.example\.org

    proxy-prod1.example.org and proxy-test8.example.org will match this expression.

  • .+

    All proxies will match this expression.

[Status]

  1. ‘Monitored’ [*]

  2. ‘Unmonitored’

All host created with this command will get assigned a default interface of type Agent using the port 10050.

do_create_host_interface()

This command creates a hostinterface.

create_host_interface [hostname]
                      [interface connection]
                      [interface type]
                      [interface port]
                      [interface IP]
                      [interface DNS]
                      [default interface]

[hostname]

Hostname

[interface connection]

  1. Connect using host DNS name or interface DNS if provided [*]

  2. Connect using host IP address

[interface type]

  1. Zabbix agent

  2. SNMP [*]

  3. IPMI

  4. JMX

[interface port]

Interface port [161]

[interface IP]

IP address if interface connection is 1:

[interface DNS]

DNS if interface connection is 0: (hostname by default)

[default interface]

  1. Not default interface

  2. Default interface [*]

do_create_hostgroup()

This command creates a hostgroup

create_hostgroup [hostgroup]
do_create_maintenance_definition()

This command creates a ‘one time only’ maintenance definition for a defined period of time. Use the zabbix dashboard for more advanced definitions.

create_maintenance_definition [name]
                              [description]
                              [host/hostgroup]
                              [time period]
                              [maintenance type]

[name]

Maintenance definition name.

[description]

Maintenance description.

[host/hostgroup]

Host/s and/or hostgroup/s the that will undergo maintenance.

One can define more than one value in a comma separated list and mix host and hostgroup values.

[time period]

Time period when the maintenance must come into effect.

One can define an interval between two timestamps in ISO format or a time period in minutes, hours or days from the moment the definition is created.

2016-11-21T22:00 to 2016-11-21T23:00

Means 22:00 until 23:00 on 2016-11-21.

2 hours

Means the maintenance starts now and lasts for two hours.

[maintenance type]

Maintenance type.

Type values:

  1. (default) With data collection

  2. Without data collection

do_create_notification_user()

This command creates a notification user. These users can be used to send notifications when a zabbix event happens.

Sometimes we need to send a notification to a place not owned by any user in particular, e.g. an email list or jabber channel but Zabbix has not the possibility of defining media for a usergroup.

This is the reason we use notification users. They are users nobody owns, but that can be used by other users to send notifications to the media defined in the notification user profile.

Check the parameter default_notification_users_usergroup in your zabbix-cli configuration file. The usergroup defined here has to exists if you want this command to work.

create_notification_user [sendto]
                         [mediatype]
                         [remarks]

[sendto]

E-mail address, SMS number, jabber address, …

[mediatype]

One of the media types names defined in your Zabbix installation, e.g. Email, SMS, jabber, …

[remarks]

Comments about this user. e.g. Operations email. Max lenght is 20 characters.

do_create_user()

This command creates an user.

create_user [alias]
            [name]
            [surname]
            [passwd]
            [type]
            [autologin]
            [autologout]
            [groups]

[alias]

User alias (account name)

[name]

Name

[surname]

Surname

[passwd]

Password.

The system will generate an automatic password if this value is not defined.

[type]

  1. ‘User’ [*]

  2. ‘Admin’

  3. ‘Super admin’

  4. ‘Guest’

[autologin]

  1. ‘Disable’ [*]

  2. ‘Enable’

[autologout]

In seconds [86400]

[groups]

Usergroup names where this user will be registered.

One can define several values in a comma separated list.

do_create_usergroup()

This command creates an usergroup.

create_usergroup [group name]
                 [GUI access]
                 [Status]

[group name]

Usergroup name

[GUI access]

  1. ‘System default’ [*]

  2. ‘Internal’

  3. ‘Disable’

[Status]

  1. ‘Enable’ [*]

  2. ‘Disable’

do_define_global_macro()

This command defines a global Zabbix macro

define_global_macro [macro name]
                    [macro value]

[macro name]

Name of the zabbix macro. The system will format this value to use the macro format definition needed by Zabbix. e.g. site_url will be converted to ${SITE_URL}.

[macro value]

Default value of the macro

do_define_host_monitoring_status()

This command defines the monitoring status of a host

defines_host_monitoring_status [hostname]
                               [on/off]

[hostname]

Hostname that will get the monitoring status updated.

do_define_host_usermacro()

This command defines a host usermacro

defines_host_usermacro [hostname]
                       [macro name]
                       [macro value]

[hostname]

Hostname that will get the usermacro locally defined.

[macro name]

Name of the zabbix macro. The system will format this value to use the macro format definition needed by Zabbix. e.g. site_url will be converted to ${SITE_URL}.

[macro value]

Default value of the macro

do_export_configuration()

This command exports the configuration of different Zabbix components to a JSON or XML file. Several parameters in the zabbix-cli.conf configuration file can be used to control some export options.

export_configuration [export_directory]
                     [object type]
                     [object name]

[export directory]

Directory where the export files will be saved.

[object type]

Possible values:

  • groups

  • hosts

  • images

  • maps

  • templates

  • screens (before Zabbix 6.0)

  • mediaTypes (after Zabbix 6.0)

One can use the special value #all# to export all object type groups.

[object name]

Object name or Zabbix-ID. One can define several values in a comma separated list.

One can use the special value #ALL# to export all objects in a object type group. This parameter will be defined automatically as #all# if [object type] == #all#.

do_import_configuration()

This command imports the configuration of a Zabbix component.

We use the options createMissing=True and updateExisting=True when importing data. This means that new objects will be created if they do not exists and that existing objects will be updated if they exist.

import_configuration [import file]
                     [dry run]

[import file]

File with the JSON or XML code to import. This command will use the file extension (.json or .xml) to find out the import format.

This command finds all the pathnames matching a specified pattern according to the rules used by the Unix shell. Tilde expansion, *, ?, and character ranges expressed with [] will be correctly matched. For a literal match, wrap the meta-characters in brackets. For example, [?] matches the character ?.

[dry run]

If this parameter is used, the command will only show the files that would be imported without running the import process.

  1. Dry run deactivated

  2. Dry run activated [*]

This command links one/several templates to one/several hosts

link_template_to_host [templates]
                      [hostnames]

[templates]

Template names or IDs. One can define several values in a comma separated list.

[hostnames]

Hostnames or IDs. One can define several values in a comma separated list.

This command links one/several templates to one/several hostgroups

link_template_to_hostgroup [templates]
                           [hostgroups]

[templates]

Template names or IDs. One can define several values in a comma separated list.

[hostgroups]

Hostgroups or IDs. One can define several values in a comma separated list.

do_load_balance_proxy_hosts()

This command will spread hosts among the given proxies.

load_balance_proxy_hosts [proxy list]
                         [weight]

[proxy list]

Comma delimited list with the proxies that will share the monitoring task for a group of hosts.

The group of hosts is obtained from the hosts assigned to the proxies in [proxy list].

[weight]

Optional weight distribution for the proxy list. I.e.:

load_balance_proxy_hosts p1,p2 1,2

That would place twice as many hosts on proxy p2.

load_balance_proxy_hosts p1,p2,p3 20,40,40

In this example, p1 would get 20% of hosts, whereas p2 and p3 get 40% each.

If not provided, the load is spread evenly among all provided proxies.

do_move_proxy_hosts()

This command moves all hosts monitored by a proxy (src) to another proxy (dst). Optionally only move hosts matching host_filter.

move_proxy_hosts [proxy_src]
                 [proxy_dst]
                 [host_filter]

[proxy_src]

Source proxy server.

[proxy_dst]

Destination proxy server.

[host_filter]

Optional pattern for which hosts to move. For example:

move_proxy_hosts p1 p2 p01-*.example.org

Moves all hosts belonging to proxy p1 whose hostname start with p01- and ends with .example.org to the proxy p2.

If left empty, all hosts residing on proxy_src will be moved.

do_quit()

Quits/terminate the Zabbix-CLI shell.

do_remove_host()

This command removes a host.

remove_host [hostname]

[hostname]

Hostname

do_remove_host_from_hostgroup()

This command removes one/several hosts from one/several hostgroups

remove_host_from_hostgroup [hostnames]
                           [hostgroups]

[hostnames]

Hostnames or IDs. One can define several values in a comma separated list.

[hostgroups]

Hostgroup names or IDs. One can define several values in a comma separated list.

do_remove_maintenance_definition()

This command removes one or several maintenance definitions

remove_maintenance_definitions [definitionID]

[definitionID]

Definition ID. One can define more than one value in a comma separated list.

do_remove_user()

This command removes an user.

remove_user [username]

[username]

Username to remove

do_remove_user_from_usergroup()

This command removes an user from one/several usergroups

remove_user_from_usergroup [username]
                           [usergroups]

[username]

Username to remove

[usergroups]

Usergroup names from where the username will be removed. One can define several values in a comma separated list.

do_shell()

This command runs a command in the operative system

shell [command]

[command]

Any command that can be run in the operative system.

do_show_alarms()

This command shows all active alarms with the last event unacknowledged.

show_alarms [description]
            [filters]
            [hostgroups]
            [Last event unacknowledged]

[description]

Type of alarm description to search for. Leave this parameter empty to search for all descriptions. One can also use wildcards.

[filters]

One can filter the result by host and priority. No wildcards can be used.

Priority values:

  1. (default) not classified;

  2. information;

  3. warning;

  4. average;

  5. high;

  6. disaster.

[hostgroups]

One can filter the result to get alarms from a particular hostgroup or group og hostgroups. One can define several values in a comma separated list.

[Last event unacknowledged]

One can filter the result after the acknowledged value of the last event of an alarm.

Values:

  • true - (default) Show only active alarms with last event unacknowledged.

  • false - Show all active alarms, also those with the last event acknowledged.

e.g.: Get all alarms with priority High that contain the word disk in the description for the host host.example.org and the last event unacknowledged:

show_alarms *disk* "'host':'host.example.org','priority':'4'" * true
do_show_global_macros()

This command shows all global macros

show global_macros
do_show_history()

This command shows the list of commands that have been entered during the Zabbix-CLI shell session.

show_history
do_show_host()

This command shows hosts information

show_host [HostID / Hostname]
          [Filter]

[HostID / Hostname]

One can search by HostID or by Hostname. One can use wildcards if we search by Hostname

[Filter]

  • Zabbix agent: available:

    1. Unknown

    2. Available

    3. Unavailable

  • Maintenance: maintenance_status:

    1. No maintenance

    2. In progress

  • Status: status:

    1. Monitored

    2. Not monitored

e.g.: Show all hosts with Zabbix agent: Available AND Status: Monitored:

show_host * "'available':'1','status':'0'"
do_show_host_inventory()

This command shows hosts inventory

show_host_inventory [Hostname]

[Hostname]

Hostname.

do_show_host_usermacros()

This command shows all usermacros for a host

show_host_usermacros [hostname]

[hostname]

Hostname

do_show_hostgroup()

This command shows hostgroup information

show_hostgroup [hostgroup]

[hostgroup]

Hostgroup name. One can use wildcards.

do_show_hostgroup_permissions()

This command shows which usergroups has access to a hostgroup

show_hostgroup_permissions [hostgroup]

[hostgroup]

Hostgroup name. One can use wildcards.

do_show_hostgroups()

This command shows all hostgroups defined in the system.

show_hostgroups
do_show_hosts()

This command shows all hosts defined in the system.

show_hosts
do_show_items()

This command shows items that belong to a template

show_items [template]

[template]

Template name or zabbix-templateID

do_show_last_values()

Shows the last values of given item.

show_last_values [item_name]
                 [group]

[item_name]

Name of the items to get. Supports wildcard.

[group]

Whether the output should group items with the same values.

  1. (default) Do not group items.

  2. Group items.

do_show_maintenance_definitions()

This command shows maintenance definitions global information. The logical operator AND will be used if one defines more than one parameter.

show_maintenance_definitions [definitionID]
                             [hostgroup]
                             [host]

[definitionID]

Definition ID. One can define more than one value.

[hostgroup]

Hostgroup name. One can define more than one value.

[host]

Hostname. One can define more than one value.

do_show_maintenance_periods()

This command shows maintenance periods global information.

show_maintenance_periods [definitionID]

[definitionID]

Definition ID. One can define more than one value.

do_show_template()

This command show templates information

show_template [Template name]

[Template name]

One can search by template name. We can use wildcards.

do_show_templates()

This command shows all templates defined in the system.

show_templates
do_show_trigger_events()

This command shows the events generated by a trigger.

show_trigger_events [triggerID]
                    [count]

[triggerID]

ID of the trigger we want tho show.

[count]

Number of events to show (Default: 1)

do_show_triggers()

This command shows triggers that belong to a template

show_triggers [template]

[template]

Template name or zabbix-templateID

do_show_usergroup()

This command shows user group information.

show_usergroup [usergroup]

[usergroup]

User group name. One can use wildcards.

do_show_usergroup_permissions()

This command show usergroup permissions information

show_usergroup_permissions [usergroup]

[usergroup]

Usergroup that will be displayed.

do_show_usergroups()

This command shows all usergroups defined in the system.

show_usergroups
do_show_usermacro_host_list()

This command shows all host with a defined usermacro

show_usermacro_host_list [usermacro]

[usermacro]

Usermacro name. The system will format this value to use the macro format definition needed by Zabbix. e.g. site_url will be converted to ${SITE_URL}.

do_show_usermacro_template_list()

This command shows all templates with a defined macro

show_usermacro_template_list [usermacro]

[usermacro]

Usermacro name. The system will format this value to use the macro format definition needed by Zabbix. e.g. site_url will be converted to ${SITE_URL}.

do_show_users()

This command shows users information.

show_users
do_show_zabbixcli_config()

This command shows information about the configuration used by this zabbix-cli instance.

show_zabbixcli_config

This command unlink one/several templates from one/several hosts

unlink_template_from_host [templates]
                          [hostnames]

[templates]

Templates names or IDs. One can define several values in a comma separated list.

[hostnames]

Hostnames or IDs. One can define several values in a comma separated list.

This command unlink one/several templates from one/several hostgroups

unlink_template_from_hostgroup [templates]
                               [hostgroups]

[templates]

Templates names or IDs. One can define several values in a comma separated list.

[hostgroups]

Hostgroups or IDs. One can define several values in a comma separated list.

do_update_host_inventory()

This command updates one hosts’ inventory

update_host_inventory [hostname]
                      [inventory_key]
                      [inventory value]

Inventory key is not the same as seen in web-gui. To look at possible keys and their current values, use:

zabbix-cli --use-json-format show_host_inventory <hostname>"
do_update_host_proxy()

This command defines the proxy used to monitor a host

update_host_proxy [hostname]
                  [proxy]

[hostname]

Hostname to update

[proxy]

Zabbix proxy server that will monitor [hostname].

do_update_template_groups()

This command changes the group memberships of a template.

update_template_groups [template]
                       [groups_to_remove]
                       [groups_to_add]

[template]

The template to change.

[groups_to_remove]

The groups to remove. Can be empty.

One can define several values in a comma separated list.

[groups_to_add]

The groups to add. Can be empty.

One can define several values in a comma separated list.

do_update_usergroup_permissions()

This command updates the permissions for an usergroup on a hostgroup.

update_usergroup_permissions [usergroup]
                             [hostgroups]
                             [permission code]

[usergroup]

Usergroup that will get a permission on a hostgroup

[hostgroups]

Hostgroup names where the permission will apply.

One can define several values in a comma separated list.

[permission]

  • deny: Deny [usergroup] all access to [hostgroups]

  • ro: Give [usergroup] read access to [hostgroups]

  • rw: Give [usergroup] read and write access to [hostgroups]

Authors

In alphabetical order:


Rafael Martinez Guerrero
PostgreSQL-es / University Center for Information Technology (USIT), University of Oslo, Norway

License and Contributions

Zabbix-CLI is the property of USIT-University of Oslo, and its code is distributed under GNU General Public License 3.

Copyright © 2014-2017 USIT-University of Oslo.