Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for...

17
Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep. Riga, Latvia

Transcript of Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for...

Page 1: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

Lightning Talk – ZABBIX-CLIRafael Martinez GuerreroCenter for Information Technology ServicesUniversity of Oslo

Zabbix conference 20169-10 Sep. Riga, Latvia

Page 2: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.
Page 3: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.
Page 4: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.
Page 5: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

/usr/bin/zabbix­cli/usr/bin/zabbix­cli­init

Page 6: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

zabbix­cli­init https://zabbix.example.org/

Page 7: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

Configuration file: $HOME/.zabbix­cli/zabbix­cli.conf

[.....]system_id=PRODlogging=ON[.....]

Logfile:$HOME/.zabbix­cli/zabbix­cli.log

Page 8: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

Interactive shell mode:

[user@host]# zabbix­cli#############################################################Welcome to the Zabbix command­line interface (v.1.5.4)#############################################################Type help or \? to list commands.

[zabbix­cli joshua@WOPR]$

Command­line mode:[user@host]# zabbix­cli <param> ­C <command>[user@host]# zabbix­cli ­­help

Page 9: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.
Page 10: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

help <command_name>

Page 11: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

[zabbix­cli joshua@WOPR]$ show_host­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­# Host: zabbix­srv01.uio.no# Filter: ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­[....]

[zabbix­cli joshua@WOPR]$ show_host zabbix­srv01.uio.no “”[....]

Page 12: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

[zabbix­cli joshua@WOPR]$ show_host zabbix*proxy* “”[....]

[zabbix­cli joshua@WOPR]$ show_alarms *ICMP* “” “” “”

[zabbix­cli joshua@WOPR]$ show_alarms *ICMP* “” Role­rhel5­servers,Role­rhel6­servers “”

Page 13: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

[user@host]$ zabbix­cli ­o json ­C “show_host zabbix­srv01.uio.no ''”{  "0": {    "groups": [      {        "groupid": "13",         "name": "All­hosts"      },       {        "groupid": "94",         "name": "Siteadmin­it­drift­gd­gid"      },[...................]       {        "groupid": "108",         "name": "Role­rhel7­servers"      }     ],     "host": "zabbix­srv01.uio.no",     "hostid": "10001",     "maintenance_status": "No maintenance (0)", [.....................] 

Page 14: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

for HOST in

`zabbix-cli -o json -C "show_host *zabbix*proxy*" | jq -a '.[].host'`;

do

echo $HOST;

zabbix-cli -C "update_host_inventory $HOST type 'Zabbix proxy'";

done

Page 15: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

[user@host]$ cat zabbix­bulk.txt

# HOSTGROUPScreate_hostgroup Zabbix­conf­test

#HOSTScreate_host zabbix­conf01.example.org Zabbix­conf­test .* 0create_host zabbix­conf02.example.org Zabbix­conf­test .* 0create_host zabbix­conf03.example.org Zabbix­conf­test .* 0

# TRIGGERSlink_template_to_host Template­icmp­ping zabbix­conf01.example.org

# DELETESremove_host zabbix­conf01.example.orgremove_host zabbix­conf02.example.orgremove_host zabbix­conf03.example.org

[user@host]$ zabbix­cli ­­file zabbix­bulk.txt

Page 16: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

Auth­file: $HOME/.zabbix­cli_auth

Format:USERNAME::PASSWORD

Token­file:$HOME/.zabbix­cli_auth_tokenFormat:USERNAME::SESSION_TOKEN

● OBS: .zabbix­cli_auth saves the password in plain text.● Zabbix­cli saves the API­auth­token of a session in $HOME/.zabbix­cli_auth_token only if use_auth_token_file=ON is defined in the configuration file.

Page 17: Lightning Talk – ZABBIX-CLI · Lightning Talk – ZABBIX-CLI Rafael Martinez Guerrero Center for Information Technology Services University of Oslo Zabbix conference 2016 9-10 Sep.

https://github.com/usit­gd/zabbix­cli