File: README.md

package info (click to toggle)
zabbix-cli 3.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,860 kB
  • sloc: python: 18,557; makefile: 3
file content (389 lines) | stat: -rw-r--r-- 10,829 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# Zabbix-cli

[![PyPI](https://img.shields.io/pypi/v/zabbix-cli-uio)](https://pypi.org/project/zabbix-cli-uio/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/zabbix-cli-uio)](<https://pypi.org/project/zabbix-cli-uio/>)
[![PyPI - License](https://img.shields.io/pypi/l/zabbix-cli-uio)](<https://pypi.org/project/zabbix-cli-uio/>)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/unioslo/zabbix-cli/test.yml?branch=master&label=tests)

<p align="center">
  <table>
    <tr>
        <td>
            <img width="100%" src="https://github.com/unioslo/zabbix-cli/blob/master/resources/help.png?raw=true">
        </td>
        <td>
            <img width="100%" src="https://github.com/unioslo/zabbix-cli/blob/master/resources/hosts.png?raw=true">
        </td>
    </tr>
    <tr>
        <td>
            <img width="100%" src="https://github.com/unioslo/zabbix-cli/blob/master/resources/host-inventory.png?raw=true">
        </td>
        <td>
            <img width="100%" src="https://github.com/unioslo/zabbix-cli/blob/master/resources/proxies.png?raw=true">
        </td>
    </tr>
  </table>
</p>

**Zabbix-CLI v3 has been completely rewritten from the ground up. The old version can be found [here](https://github.com/unioslo/zabbix-cli/tree/2.3.2).**

## About

Zabbix-cli is a command line interface for performing common administrative tasks tasks in [Zabbix monitoring system](https://www.zabbix.com/) via the [Zabbix API](https://www.zabbix.com/documentation/current/en/manual/api).

The zabbix-cli code is written in [Python](https://www.python.org/) and distributed under the GNU General Public License v3. It has been developed and tested by [University Center for Information Technology](https://www.usit.uio.no/) at [the University of Oslo, Norway](https://www.uio.no/).

The project home page is on [GitHub](https://github.com/unioslo/zabbix-cli). Please report any issues or improvements there.

The manual is available online at <https://unioslo.github.io/zabbix-cli/>.

## Install

### From source

> [!NOTE]
> We are in the process of acquiring the name `zabbix-cli` on PyPI. Until then, installation must be done via the mirror package `zabbix-cli-uio`.

#### [uv](https://docs.astral.sh/uv/getting-started/installation/)

```bash
uv tool install zabbix-cli-uio
```

#### [uvx](https://docs.astral.sh/uv/#tool-management)

```bash

uvx --from zabbix-cli-uio zabbix-cli
```

#### [pipx](https://pipx.pypa.io/stable/)

```bash
pipx install zabbix-cli-uio
```

### Homebrew

A homebrew package exists, but it is maintained by a third party. It can be installed with:

```bash
brew install zabbix-cli
```

### Binary

Binaries built with PyInstaller can be found on the [releases page](https://github.com/unioslo/zabbix-cli/releases). We build binaries for Linux (x86), macOS (ARM & x86) and Windows (x86) for each release.

## Quick start

Running `zabbix-cli` for the first time will prompt for a Zabbix URL, username and password. The URL should be the URL of the Zabbix web server without the `/api_jsonrpc.php` path.

Running without arguments will start the REPL:

```bash
zabbix-cli
```

<img width="60%" src="https://github.com/unioslo/zabbix-cli/blob/master/resources/open-autocomplete.png?raw=true">

## Usage

Zabbix-cli is a command line interface for Zabbix. It can be used in three ways:

1. **Interactive mode**: Start the REPL by running `zabbix-cli`. This will start a shell where you can run multiple commands in a persistent session.
2. **Single command**: Run a single command by running `zabbix-cli COMMAND`. This will run the command and print the output.
3. **Batch mode**: Run multiple commands from a file by running `zabbix-cli -f FILE`. The file should contain one command per line.

Command reference can be found in the [online user guide](https://unioslo.github.io/zabbix-cli/commands/) or by running `zabbix-cli --help`.

### Authentication

By default, the application will prompt for a username and password. Once authenticated, the application stores the session token in a file for future use.

For more information about the various authentication methods, see the [authentication guide](https://unioslo.github.io/zabbix-cli/guide/authentication/).

### Configuration

Zabbix-cli needs a config file. It is created when the application is started for the first time. The config file can be created manually with the `init` command:

```bash
zabbix-cli init --zabbix-url https://zabbix.example.com/
```

For more detailed information about the configuration file, see the [configuration guide](https://unioslo.github.io/zabbix-cli/guide/configuration/).

### Formats

Zabbix-cli supports two output formats: table and JSON. The default format is table, but it can be changed with the `--format` parameter:

```bash
# Show hosts in table format (default)
zabbix-cli show_hosts

# Show hosts in JSON format
zabbix-cli --format json show_hosts

# Set format in REPL mode
> --format json show_hosts
```

The default format can be configured with the `app.output.format` config option:

```toml
[app.output]
format = "json"
```

#### Table

<img width="60%" alt="format-table" src="https://github.com/user-attachments/assets/207fa12b-39c6-45b9-9f0e-7f217c723461">

The default rendering mode is a [Rich](https://github.com/Textualize/rich) table that adapts to the width of the terminal.

#### JSON

<img width="60%" alt="format-json" src="https://github.com/user-attachments/assets/680f507b-dc2a-41b2-87c4-c3a443d83979">

The JSON output format is always in this format, where `ResultT` is the expected result type:

```json
{
  "message": "",
  "errors": [],
  "return_code": "Done",
  "result": ResultT
}
```

The type of the `result` field varies based on the command run. For `show_host` it is a single Host object, while for `show_hosts` it is an _array_ of Host objects.

<details>
  <summary><code>show_host foo.example.com*</code></summary>

```json
{
  "message": "",
  "errors": [],
  "return_code": "Done",
  "result": {
    "hostid": "10648",
    "host": "foo.example.com",
    "description": "",
    "groups": [
      {
        "groupid": "22",
        "name": "All-hosts",
        "hosts": [],
        "flags": 0,
        "internal": null,
        "templates": []
      },
      {
        "groupid": "46",
        "name": "Source-foosource",
        "hosts": [],
        "flags": 0,
        "internal": null,
        "templates": []
      },
      {
        "groupid": "47",
        "name": "Hostgroup-bob-hosts",
        "hosts": [],
        "flags": 0,
        "internal": null,
        "templates": []
      },
      {
        "groupid": "48",
        "name": "Importance-X",
        "hosts": [],
        "flags": 0,
        "internal": null,
        "templates": []
      },
      {
        "groupid": "49",
        "name": "Hostgroup-alice-hosts",
        "hosts": [],
        "flags": 0,
        "internal": null,
        "templates": []
      }
    ],
    "templates": [],
    "inventory": {},
    "monitored_by": "proxy",
    "proxyid": "2",
    "proxy_groupid": "0",
    "maintenance_status": "0",
    "active_available": "0",
    "status": "0",
    "macros": [],
    "interfaces": [
      {
        "type": 1,
        "ip": "",
        "dns": "foo.example.com",
        "port": "10050",
        "useip": 0,
        "main": 1,
        "interfaceid": "49",
        "available": 0,
        "hostid": "10648",
        "bulk": null,
        "connection_mode": "Dns",
        "type_str": "Agent"
      }
    ],
    "proxy": {
      "proxyid": "2",
      "name": "proxy-prod02.example.com",
      "hosts": [],
      "status": null,
      "operating_mode": 0,
      "address": "127.0.0.1",
      "proxy_groupid": "1",
      "compatibility": 0,
      "version": 0,
      "local_address": "192.168.0.1",
      "local_port": "10051",
      "mode": "Active",
      "compatibility_str": "Undefined"
    },
    "zabbix_agent": "Unknown"
  }
}
```

</details>

<details>
  <summary><code>show_hosts foo.*</code></summary>

```json
{
  "message": "",
  "errors": [],
  "return_code": "Done",
  "result": [
    {
      "hostid": "10648",
      "host": "foo.example.com",
      "description": "",
      "groups": [
        {
          "groupid": "22",
          "name": "All-hosts",
          "hosts": [],
          "flags": 0,
          "internal": null,
          "templates": []
        },
        {
          "groupid": "46",
          "name": "Source-foosource",
          "hosts": [],
          "flags": 0,
          "internal": null,
          "templates": []
        },
        {
          "groupid": "47",
          "name": "Hostgroup-bob-hosts",
          "hosts": [],
          "flags": 0,
          "internal": null,
          "templates": []
        },
        {
          "groupid": "48",
          "name": "Importance-X",
          "hosts": [],
          "flags": 0,
          "internal": null,
          "templates": []
        },
        {
          "groupid": "49",
          "name": "Hostgroup-alice-hosts",
          "hosts": [],
          "flags": 0,
          "internal": null,
          "templates": []
        }
      ],
      "templates": [],
      "inventory": {},
      "monitored_by": "proxy",
      "proxyid": "2",
      "proxy_groupid": "0",
      "maintenance_status": "0",
      "active_available": "0",
      "status": "0",
      "macros": [],
      "interfaces": [],
      "proxy": {
        "proxyid": "2",
        "name": "proxy-prod02.example.com",
        "hosts": [],
        "status": null,
        "operating_mode": 0,
        "address": "127.0.0.1",
        "proxy_groupid": "1",
        "compatibility": 0,
        "version": 0,
        "local_address": "192.168.0.1",
        "local_port": "10051",
        "mode": "Active",
        "compatibility_str": "Undefined"
      },
      "zabbix_agent": "Unknown"
    }
  ]
}
```

</details>

## Development

Zabbix-cli currently uses [uv](https://docs.astral.sh/uv/)  and [Hatch](https://hatch.pypa.io/latest/) for project management and packaging. To start off, clone the repository:

```bash
git clone https://github.com/unioslo/zabbix-cli.git
```

Then make a virtual environment using uv:

```bash
uv venv
```

This will create a new virtual environment, install the required dependencies and enter the environment.

### Testing

Run unit tests (without coverage):

```bash
hatch run test
```

Generate coverage report:

```bash
hatch run cov
```

### Documentation

To serve the documentation locally:

```bash
hatch run docs:serve
```

This will start a local web server on `http://localhost:8001` that is automatically refreshed when you make changes to the documentation. However, some hooks are only run on startup, such as the creation of pages for each command. Changes to command examples or docstrings will require a restart.