Skip to content

Instantly share code, notes, and snippets.

@kmpm
Last active August 22, 2016 14:09
Show Gist options
  • Select an option

  • Save kmpm/8360a6b1f35831bf969dfb739c9ad0f9 to your computer and use it in GitHub Desktop.

Select an option

Save kmpm/8360a6b1f35831bf969dfb739c9ad0f9 to your computer and use it in GitHub Desktop.
Zabbix Stuff

DNS Test

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
#!/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
//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