Zabbix server is not receiving the right result from Zabbix agent - zabbix

I am experiencing an issue with our Zabbix monitoring (Zabbix server 5) running on CentOS7. The Zabbix agent executes user parameter which includes sql query and getting a result from Production DB. The structure of the user parameter is the same as the other alerts (only the SQL queries are different) and some of them are working fine, others don't work at all. The error I was first receiving was about missing ORACLE_HOME dir as environmental variable.
"Error 6 initializing SQL*Plus SP2-0667: Message file sp1.msb
not found SP2-0750: You may need to set ORACLE_HOME to your Oracle
software directory"
So I added the ORACLE_HOME directory for the Zabbix user and when I ask Zabbix agent to execute "zabbix_agentd -t userparameter-name" I am receiving the desired result.
Unfortunately, when I test the item (alert) in Zabbix server UI, it still returns me the old error for ORACLE_HOME.
I tried to clear the configuration cache on both - Zabbix server and Proxy but there wasn't positive result. The restart of Zabbix server, proxy or agent didn't worked as well.
Here is how the user parameter looks like:
echo -e "set feed off\n set pages 0\n set head off\n set space 0\n set heading off\n SELECT count(uuid) FROM prodlive.task WHERE tasktypeid = 'SWU_EMAIL_PROCESSING' AND status = 'PENDING' AND NEXTSCANTIME <= (SYS_EXTRACT_UTC(SYSTIMESTAMP) - (5/(24*60)));"|sudo -i -u zabbix /opt/oracle/product/11.2/client/bin/sqlplus -s <USERNAME>/<PASSWORD>'(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = <HOSTNAME>)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = <SERVICE-NAME>)))'| awk '{print $1}'
The structure of the user parameter works fine on other alerts running on this server, but for some unknown reason, for some of the alerts, its not working. All SQL queries were tested and validated before adding them in Zabbix monitoring.
Here is the structure of the user parameter used for running SQL queries against Oracle SQL DB.
echo -e "set feed off\n set pages 0\n set head off\n set space 0\n set heading off\n <SELECT STATEMENT GOES HERE>"|sudo -i -u zabbix /opt/oracle/product/11.2/client/bin/sqlplus -s <USERNAME>/<PASSWORD>'(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = <name-of-the-host>)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = <SERVICE-NAME>)))'| awk '{print $1}'
If someone could give me advice how to fix this issue, will be very grateful.

Related

ping external host from zabbix agent

We are running a typical zabbix server setup. A zabbix server and a couple linux servers that has zabbix agent installed and monitored by the zabbix server. However, my problem is there a way to check ping (icmppingsec maybe? :confused:) in between linux_host A to linux_host B and output the result to the zabbix server coming from linux_host A??
I have tried simple check icmppingsec[<target>,<packets>,<interval>,<size>,<timeout>,<mode>] but I found out that the ping is executed by the zabbix server itself and not the host A.
Thanks for the help!
Found solution to add this user parameter:
UserParameter=chk.fping[*],sudo /usr/bin/fping -c 3 $1 2>&1 | tail -n 1 | awk '{print $NF}' | cut -d '/' -f2
Add permition in /etc/sudoers because of error in creating SOCKET.
zabbix ALL=(ALL) NOPASSWD:/usr/bin/fping
In template you can add items you'd like to ping
chk.fping[8.8.8.8]
Currently, the ability to ping a host by Zabbix agent is not supported out of the box, but there is a feature request for that: ZBXNEXT-739. Meanwhile, you should add a user parameter on the agent that would do the pinging.
I have found a way to get the ping latency from the zabbix agent in order to ping an external host. I declared this parameter to the zabbix_agentd.conf
UserParameter=key_name[*],fping -e x.x.x.x | awk '{ print $4 }' | tr -d '('
It outputs the response time, numeric value only. My next problem is how to make this command readable by zabbix server so that it will be viewable thru graph. On zabbix server the output is "no data" but under Hosts > Items, it is green and enabled.
Thanks for the help!

mysql-proxy not running lua script

I know there are many mysql-proxy questions on SO, however I have read through many of them and none seem to solve my problem. I am simply trying to get mysql-proxy up and running, with the eventual purpose of rewriting some queries that go through the proxy. I am using ubuntu 14.04, I have mysql-proxy version 0.8.1, and mysql version 5.5.37. To start mysql-proxy I run the following line on the command line
sudo mysql-proxy --defaults-file=mysql-proxy.cnf
where the file mysql-proxy.cnf looks like the following:
[mysql-proxy]
log-file= /var/log/mysql/proxy-error.log
log-level= debug
admin-lua-script= /usr/lib/mysql-proxy/lua/admin.lua
proxy-lua-script= /path/to/lua/script/example.lua
admin-username = myusername
admin-password = mypassword
proxy-skip-profiling = true
proxy-address = localhost:4040
proxy-backend-addresses = localhost:3306
plugins = proxy,admin
My example.lua script is very simple, and meant only to verify that the mysql-proxy query is being altered. example.lua is pasted below
-- first_example.lua
function read_query(packet)
if string.byte(packet) == proxy.COM_QUERY then
print("Hello world! Seen the query: " .. string.sub(packet, 2))
end
end
Since I don't run this with the --daemon flag, when I run that line above in the command line it just loops indefinitely, which is expected.
Finally, in separate terminal session, I run the following on the command line and enter my password in order to connect with the proxy
mysql -u myusername -p -h localhost -P 4040
I then select a database to use, and run a simple SELECT query on one of the tables. Based on multiple articles/tutorials I've read on mysql-proxy, my first console session, the one that ran mysql-proxy, should print out some data based on the example.lua file. However this does not happen, in fact nothing happens.
I'm not sure if the following bit of information makes any difference, but in my "my.cnf" mysql configuration file, I have these couple of lines
bind-address = 255.255.255.255
#bind-address = 127.0.0.1
where I have replaced my actual ip address with 255.255.255.255 because I do not want to display my ip address publicly.
Please, I have been trying to figure this out for several days, and no amount of new lua scripts, or changing the host:port parameters in the mysql-proxy.cnf file have solved anything. I

mySQL Script Error

I've been trying to get an OpenVPN server running Debian-7-Wheezy to authenticate via mySQL all day. I have mySQL hosted on another server running WHM and cPanel. I added the OpenVPN server's IP to the whitelist for database connections, checked all my credentials and double checked the config file. When I run: /etc/openvpn/script/test_connect_db.sh test 1234 I recieve this error:
/etc/openvpn/script/test_connect_db.sh: line 6: mysql: command not found
authentication failed.
The file located at: /etc/openvpn/script/test_connect_db.sh looks exactly like this:
#!/bin/bash
. /etc/openvpn/script/config.sh
##Test Authentication
username=$1
password=$2
user_id=$(mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -sN -e "select user_id from user where user_id = '$username' AND user_pass = '$password' AND user_enable=1 AND user_start_date != user_end_date AND TO_DAYS(now()) >= TO_DAYS(user_start_date) AND (TO_DAYS(now()) <= TO_DAYS(user_end_date) OR user_end_date='0000-00-00')")
##Check user
[ "$user_id" != '' ] && [ "$user_id" = "$username" ] && echo "user : $username" && echo 'authentication ok.' && exit 0 || echo 'authentication failed.'; exit 1
Any idea what's wrong?
It sounds like you aren't event getting far enough to attempt a mysql connection to begin with.
The error you specified indicated it can't even find the mysql client.
Can you successfully just run "mysql" from the command line outside the script?
If so that would indicate your $PATH variable isn't set properly in scope of the script.
You didn't say what config.sh is doing. Maybe that's over writing the PATH variable?
Either way if you can run mysql from the command line then run
which mysql
That should give you the fully qualified path to the client binary and you could use that in your script.

Powershell MySQL

Two servers, one on Windows server + WAMP, one on Linux Debian + MySQL
I would like to understand why I don't get the same result from these two following ways:
From a phpmyadmin (MySQL on linux) I import a sql file
From MySQL (on windows server) I launch this powershell
Script file content:
$mysqlpath = "C:\wamp\bin\mysql\mysql5.6.12\bin\"
$username = xxx
$password = xxx
$backuppath = "C:\"
$backupfile = $backuppath + "file.sql"
CD $mysqlpath
&cmd /c "mysql -u $username -p$password -h 0.0.0.0 < $backupfile"
CD C:\
NOTE: (0.0.0.0 is Linux server IP address)
Why i don t get the same result from these two ways?
How can I set up the powershell file with the right parameters to get the same results that the first solution ?
In using WinRM and ssh, can I lauch my powershell file on windows to execute via ssh the mysql command on linux server ?

Ruby: How do I return a MySQL query up an SSH tunnel?

//update: when feeding mysql passwords, -ppassword works. -p password does -not- work. Problem solved.//
We have hundreds of databases on our work servers, and I'd like to write a ruby script that automates the process of creating duplicate versions of them on my local machine for development purposes.
I've been trying to use net-ssh to create the tunnel, but (host, user, pass, etc. are censored for obvious reasons):
require 'net/ssh'
HOST = 'xxx'
USER = 'yyy'
PASS = 'ppp'
Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
puts "inside ssh tunnel"
puts ssh.exec!('ruby -v')
puts ssh.exec!('mysql -u zzz -p pswrd -h c3 will_il_raw -e "select * from deeds limit 1"')
end
results in the output:
inside ssh tunnel
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
followed by an indefinite hang. Interestingly, if I ssh into the same computer via the console, 'ruby -v' returns 1.9.3. If I enter that mysql query there, it successfully returns one line of the named table.
I assume the solution has something to do with port forwarding, but here my limited knowledge begins to fail me utterly.
The machine running the mysql server is not the same machine as I am accessing it from, which is not, in turn, the machine I am actually sitting at. I need to connect the dots and apparently have no idea how to go about this properly.
Any protips would be much appreciated.
In MySQL syntax, when feeding a password using -p[password], there is no space between -p and the password.
Because the script's version of the syntax had a space, the result of the query was a prompt requesting the password, which caused the hang on the far end of the SSH tunnel.