Learn Python because of Zabbix API, examples, pyzabbix

Install python pip on CentOS 7:
cd && curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" && python get-pip.py
yum install -y epel-release && yum -y install python-pip
Install python pip on debian:
apt -y install python-pip
Install python pip on RHEL:
yum -y install python-pip
Install pyzabbix module:
pip install pyzabbix
pip install config
Note down user 'zabbix' home dir:
grep zabbix /etc/passwd
# it should report '/var/lib/zabbix'
If directory not exist then create it:
mkdir -p /var/lib/zabbix
Set the credentials for pyzabbix if front-end is located on http://localhost/zabbix
cat << 'EOF' > /var/lib/zabbix/config.py
url = "http://127.0.0.1/zabbix"
username = "Admin"
password = "zabbix"
EOF
or if Zabbix server is directly on http://localhost/
cat << 'EOF' > /var/lib/zabbix/config.py
url = "http://127.0.0.1/"
username = "Admin"
password = "zabbix"
EOF
Set the right owner for config:
chown zabbix. /var/lib/zabbix/config.py
Find where the externalscripts directory is located:
find / -name externalscripts
Move to externalscripts directory:
cd $(find / -name externalscripts | head -1)
Sample snippets

No comments: