I am having one heck of a time passing a dns name to a script to do an nslookup for the purpose of testing to the root servers for connectivity. I've tried this with both bash and php and I keep getting the same results.
On my Zabbix server I have zabbix_agentd running. It is called quite a few scripts which do not require parameters. Those scripts test our NTP and DNS servers. This one should query any of a-h.root-servers.net, just to verify a response from the server.
Here is the zabbix_agentd.conf entry for the script:
Here is the Action defined to execute the test:
Here is what the host entry error says:
The server log says:
The client log says nothing of the incident. I took care to list the host ips and hostname in the zabbix_agentd.conf script.
I set the owner of the scripts to zabbix and set +x. The other scripts have been running just dandy. They do not require a parameter.
I must be missing something stupid. I code in php, perl, bash, cscript, etc. and this just cannot be this hard.
It sure would be useful if this were in the zabbix manual with a few examples.
Here is the script
Works just fine from the command line.
On my Zabbix server I have zabbix_agentd running. It is called quite a few scripts which do not require parameters. Those scripts test our NTP and DNS servers. This one should query any of a-h.root-servers.net, just to verify a response from the server.
Here is the zabbix_agentd.conf entry for the script:
Code:
UserParameter=ROOTS[*],/usr/local/www/data/netmon/scripts/roots.php $1
Code:
Description: A.ROOTS
Type : Zabbix Agent
Key : ROOTS[{HOST.CONN}]
Type of information: Numeric (integer 64 bit)
Code:
Got empty string from [a.root-servers.net]. Assuming that agent dropped connection because of access permissions
Code:
Item [a.root-servers.net:ROOTS[a.root-servers.net]] error: Got empty string from [a.root-servers.net]. Assuming that agent dropped connection because of access permissions
I set the owner of the scripts to zabbix and set +x. The other scripts have been running just dandy. They do not require a parameter.
I must be missing something stupid. I code in php, perl, bash, cscript, etc. and this just cannot be this hard.
It sure would be useful if this were in the zabbix manual with a few examples.
Code:
############ GENERAL PARAMETERS ################# # List of comma delimited IP addresses (or hostnames) of ZABBIX servers. # No spaces allowed. First entry is used for sending active checks. # Note that hostnames must resolve hostname->IP address and # IP address->hostname. Server=127.0.0.1,192.168.1.59,172.22.221.100 # Server port for sending active checks #ServerPort=10051 # Unique hostname. Required for active checks. Hostname=helpdeskii # Listen port. Default is 10050 #ListenPort=10050 # IP address to bind agent # If missing, bind to all available IPs #ListenIP=127.0.0.1 # Number of pre-forked instances of zabbix_agentd. # Default value is 5 # This parameter must be between 1 and 16 StartAgents=5 # How often refresh list of active checks. 2 minutes by default. #RefreshActiveChecks=120 # Disable active checks. The agent will work in passive mode listening server. DisableActive=1 # Enable remote commands for ZABBIX agent. By default remote commands disabled. #EnableRemoteCommands=1 # Specifies debug level # 0 - debug is not created # 1 - critical information # 2 - error information # 3 - warnings (default) # 4 - for debugging (produces lots of information) DebugLevel=3 # Name of PID file PidFile=/var/tmp/zabbix_agentd.pid # Name of log file. # If not set, syslog will be used LogFile=/var/log/zabbix_agentd.log # Spend no more than Timeout seconds on processing # Must be between 1 and 30 Timeout=30 ####### USER-DEFINED MONITORED PARAMETERS ####### # Format: UserParameter=<key>,<shell command> # Note that shell command must not return empty string or EOL only #UserParameter=system.test,who|wc -l ### Set of parameter for monitoring MySQL server (v3.23.42 and later) ### Change -u<username> and add -p<password> if required UserParameter=DNSL,/usr/local/www/data/netmon/scripts/dnschk.php 192.168.1.10 UserParameter=DNSN,/usr/local/www/data/netmon/scripts/dnschk.php 192.168.6.10 UserParameter=DNSE,/usr/local/www/data/netmon/scripts/dnschk.php 192.168.4.10 UserParameter=DNST,/usr/local/www/data/netmon/scripts/dnschk.php 192.168.10.10 UserParameter=DNSW,/usr/local/www/data/netmon/scripts/dnschk.php 192.168.2.10 UserParameter=NTPtime1,/usr/local/www/data/netmon/scripts/ntpchk.php 192.168.1.59 UserParameter=ROOTS[*],/usr/local/www/data/netmon/scripts/roots.php $1
Code:
#!/usr/local/bin/php
<?php
// dnslookup
// DNS lookup scripts for Zabbix monitor. Conditional return
// of 1=success | 0=failed
$result=0;
if($_SERVER["argv"][1])
{
$dns_server = $_SERVER["argv"][1];
} else {
echo "You need to supply a DNS server to check. Quitting.\n";
exit;
}
// Do query
if(shell_exec('host -tSOA . $dns_server | grep "has SOA" | wc -l')==1)
{
$result= 1; // success
} else {
$result= 0; // failure
}
echo $result;
?>
Comment