Skip to content

Instantly share code, notes, and snippets.

@kmpm
Last active August 24, 2016 10:17
Show Gist options
  • Save kmpm/d8fc218e095ca74a53134ed883c71402 to your computer and use it in GitHub Desktop.
Save kmpm/d8fc218e095ca74a53134ed883c71402 to your computer and use it in GitHub Desktop.
Zabbix >= 3.0

How to install zabbix (~3.0) server/client/proxy on Ubuntu 16.04

This will assume that you are to be using MySQL for all databases.

Zabbix Client

Test DNS lookups

This requires config for zabbix agent as well as the dnstest.php script somewhere on the path, for example /usr/local/bin/dnstest.php.

Content for /etc/zabbix/zabbix_agent.d/userparameter_dnstest.conf

UserParameter=dns.ping[*],dnstest.php $1 $2

Zabbix Proxy

  • Install dependencies sudo apt install mysql-server libcurl3 libssh2-1 libsnmp30 libodbc1 fping libopenipmi0 libmysqlclient20 snmp-mibs-downloader
  • Download http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix/zabbix-proxy-mysql_3.0.4-1+xenial_amd64.deb or other suitable package from zabbix. Try to get the latest available one.
  • Install downloaded package sudo dpkg -i zabbix-proxy-mysql_3.0.4-1+xenial_amd64.deb
  • Install updates sudo apt-get update
  • Comment out mibs : in /etc/snmp/snmp.conf to enable all downloaded mibs

zabbix_proxy.conf

Edit /etc/zabbix/zabbix_proxy.conf in your favourite editor.

Server=<ip to zabbix-server>
Hostname=<hame of zabbix proxy configured in server>
DBPassword=<password>

Create Database

echo "create database zabbix_proxy character set utf8 collate utf8_bin;" | mysql -uroot -p<password>  
echo "grant all privileges on zabbix_proxy.* to zabbix@localhost identified by '<password>';" | mysql -uroot -p<password> 

cd /usr/share/doc/database/mysql
cd /usr/share/doc/zabbix-proxy-mysql
zcat schema.sql.gz | mysql -uzabbix -p<password> zabbix_proxy

Start

sudo systemctl restart zabbix-proxy.service
#check for errors
sudo tail -f /var/log/zabbix/zabbix_proxy.log
#!/usr/bin/php
<?php
//This file should be used together with userparameters in zabbix
//to test if there is a valid response from a DNS server.
//Save to /usr/local/bin/dnstest.php and chmod +x to make it executable.
//
//first parameter is the dns server
//second parameter is the address to resolve
// Define defaults
$result=0;
if(count($_SERVER["argv"]) > 1 and $_SERVER["argv"][1]) {
$ns_server = $_SERVER["argv"][1];
}
else {
echo "You need to supply a DNS server to check. Quitting.\n";
exit;
}
if(count($_SERVER["argv"]) < 3) {
echo "You need to supply at least 1 host to check. Quitting.\n";
exit;
}
$hosts = array_slice($_SERVER["argv"], 2);
// Do query
foreach($hosts as $host)
{
#echo "host=".$host."\n";
$out = shell_exec("dig +time=1 +tries=1 +short @".$ns_server." ".$host);
#echo "out=".$out."\n";
#echo "filter=".filter_var($out, FILTER_VALIDATE_IP)."\n";
if(strlen($out)>7) {
$result= $result+0; // success
} else {
$result= $result+1; // failure
}
# echo "result=".$result."\n";
}
if($result > 0)
{
$result=0;
} else {
$result=1;
}
echo $result;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment