본문 바로가기

리눅스

zabbix_get 명령어(zabbix get)

반응형

zabbix_get 명령어

zabbix_get 명령어는 Zabbix 에이전트에 대한 정보를 요청하는 데 사용됩니다. 이 명령어를 사용하여 특정 키에 대한 값을 가져오거나 Zabbix 서버로부터 호스트 정보를 얻을 수 있습니다.

zabbix-get 패키지 설치

sudo yum install -y zabbix-get
which zabbix_get
$ which zabbix_get
/usr/bin/zabbix_get

zabbix_get 명령어

문법

zabbix_get [-hV] [-s <host name or IP>] [-p <port number>] [-I <IP address>] [-k <item key>]

호스트 정보 가져오기

zabbix_get -s [Zabbix Server IP] -k system.hostname

호스트 아이템 값 가져오기

zabbix_get -s [Zabbix Server IP] -k "system.uptime"

테스트 값 확인

zabbix_get -s [Zabbix Server IP] -k "agent.ping"
zabbix_get -s 127.0.0.1 -p 10050 -k """system.cpu.load[all,avg1]"""
728x90

[zabbix server : 10.255.255.100]

커스텀 키 값 가져오기

zabbix_get -s [Zabbix Server IP] -k [custom.key.name]
zabbix_get -s 10.255.255.200 -p 10050 -k "z_c[uptime]"
$ zabbix_get -s 10.255.255.200 -p 10050 -k "z_c[uptime]"
 13:20:38 up 1 day,  3:22,  1 user,  load average: 0.00, 0.01, 0.05
zabbix_get -s 10.255.255.200 -p 10050 -k "z_cs[tail /var/log/messages]"
$ zabbix_get -s 10.255.255.200 -p 10050 -k "z_cs[tail /var/log/messages]"
Jun 18 15:10:02 dev-213 systemd: Removed slice User Slice of root.
Jun 18 15:11:01 dev-213 systemd: Created slice User Slice of root.
Jun 18 15:11:01 dev-213 systemd: Started Session 2142 of user root.
Jun 18 15:11:02 dev-213 systemd: Time has been changed
Jun 18 15:11:02 dev-213 systemd: Removed slice User Slice of root.
Jun 18 15:11:11 dev-213 systemd: Created slice User Slice of root.
Jun 18 15:11:11 dev-213 systemd: Started Session c2 of user root.
Jun 18 15:11:11 dev-213 systemd: Removed slice User Slice of root.
Jun 18 15:11:13 dev-213 systemd: Created slice User Slice of root.
Jun 18 15:11:13 dev-213 systemd: Started Session c3 of user root.
zabbix_get -s 10.255.255.200 -p 10050 -k "z_ps.status[ssh]"
$ zabbix_get -s 10.255.255.200 -p 10050 -k "z_ps.status[ssh]"
1

[zabbix agent : 10.255.255.200]

zabbix_agentd.conf 편집

vim /etc/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0

DenyKey=system.run[*]

EnableRemoteCommands=1

LogRemoteCommands=1

Server=zbx.4wxyz.com

ServerActive=zbx.4wxyz.com

Hostname=dev-213

Timeout=30

Include=/usr/local/etc/zabbix_agentd.userparams.conf

zabbix_agentd.userparams.conf 편집

vim /usr/local/etc/zabbix_agentd.userparams.conf
UnsafeUserParameters=1

UserParameter=z_c[*],$1
UserParameter=z_cs[*],sudo $1

UserParameter=z_ps.status[*],ps -ef | grep $1 | awk '{if($$3 == 1) print $$0}' | wc -l
UserParameter=z_port.status[*],ss -lnp | grep $1 | wc -l
#UserParameter=z_port.status[*],ss -lnp | grep LISTEN | grep $1 | awk '{if($$3 == 1) print $$0}' | wc -l

UserParameter=z_nc.tcp.port[*],nc -4 -z "$1" "$2" -w "$3"; echo $?
UserParameter=z_nc.udp.port[*],nc --udp -4 -z "$1" "$2" -w "$3"; echo $?

UserParameter=z_uptime,uptime
UserParameter=z_cpu,mpstat | tail -1 | awk '{print 100-$NF}'
UserParameter=z_free,free -h
UserParameter=z_memory,free | awk '/Mem/{printf("used: %.2f%"), $3/$2*100} /buffers\/cache/{printf(", buffers: %.2f%"), $4/($3+$4)*100} /Swap/{printf(", swap: %.2f%\n"), $3/$2*100}'
UserParameter=z_disk,df -h | egrep -v '^Filesystem|tmpfs'

 

참고URL

- ZABBIX Documentation : 7 Get

 

728x90
반응형