Monitor Oracle DB with Zabbix - zabbix

I install and configure Oracle instant client and unixODBC. When login with root, can connect to db by sqlplus or isql.
root#zabbix:~# sqlplus ***/***#***
SQL*Plus: Release 12.1.0.2.0 Production on Tue Mar 7 13:56:42 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Last Successful login time: Tue Mar 07 2017 13:19:45 +03:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
root#zabbix:~# isql ***
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
But in Zabbix admin panel I got error Cannot connect to ODBC DSN:[SQL_ERROR]:[08004][12154][[unixODBC][Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve the connect identifier specified]|.
I think this is trouble with no exists env for zabbix user, because sudo -u zabbix env output not contain ORACLE_HOME, TNS_ADMIN, NLS_LANG etc.
Where I can set it or what a problem?

I solved my problem.
Create file /etc/default/zabbix-server with necessary variables:
ORACLE_HOME=/usr/lib/oracle/12.1/client64
LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
NLS_LANG=AMERICAN_CIS.CL8MSWIN1251
TNS_ADMIN=/usr/lib/oracle/12.1/client64/network/admin
Restart Zabbix server
Get main PID of Zabbix server process and check process env with strings -a /proc/18253/environ (replace 18253 with your PID):
LANG=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CONFFILE=/etc/zabbix/zabbix_server.conf
ORACLE_HOME=/usr/lib/oracle/12.1/client64
LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
NLS_LANG=AMERICAN_CIS.CL8MSWIN1251
TNS_ADMIN=/usr/lib/oracle/12.1/client64/network/admin

Related

Could not link driver rlm_sql_mysql

I have a problem with MySQL:
freeradius -X gives the following command:
Could not link driver rlm_sql_mysql: /usr/lib/freeradius/rlm_sql_mysql.so: cannot open shared object file: No such file or directory
Make sure it (and all its dependent libraries!) are in the search path of your system's ld
/etc/freeradius/3.0/mods-enabled/sql[18]: Instantiation failed for module "sql
"
admin#ubuntu-de-01:/etc/freeradius/3.0/mods-available$ freeradius -v
radiusd: FreeRADIUS Version 3.0.16, for host x86_64-pc-linux-gnu, built on Apr 17 2019 at 12:59:55
FreeRADIUS Version 3.0.16
Copyright (C) 1999-2017 The FreeRADIUS server project and contributors
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE
You may redistribute copies of FreeRADIUS under the terms of the
GNU General Public License
For more information about these matters, see the file named COPYRIGHT
The MySQL database is working:
Database changed
mysql> show tables;
+------------------+
| Tables_in_radius |
+------------------+
| nas |
| radacct |
| radcheck |
| radgroupcheck |
| radgroupreply |
| radpostauth |
| radreply |
| radusergroup |
+------------------+
8 rows in set (0.00 sec)
mysql>
I haven't tried installing libmysqlclient or yum or anything.
This problem started occurring after I've reinstalled the freeradius.
Is there a requirment to reinstall the mysql DB somehow as well?
Thank you
in my case, after downgrading the MySQL version, the libmysqlclient-dev library was missed, all that was needed was just to install it.
apt install libmysqlclient-dev
Hope, this helps someone.

xquery error from BaseX: [sql:init] Could not find driver: com.mysql.jdbc.Driver

Which specific JDBC driver am I missing below?
nicholas $
nicholas $ basex mysql.xq
Stopped at /home/nicholas/flwor/mysql.xq, 3/9:
[sql:init] Could not find driver: com.mysql.jdbc.Driver
nicholas $
nicholas $ cat mysql.xq
xquery version "3.0";
sql:init("com.mysql.jdbc.Driver"),
let $con := sql:connect("jdbc:mysql://localhost:3306/northwind")
return sql:execute($con, "SELECT first_name FROM customers LIMIT 3;")
nicholas $
nicholas $ mysql -h localhost -P 3306 --protocol=tcp -u user -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2901
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> SELECT first_name FROM northwind.customers LIMIT 3;
+------------+
| first_name |
+------------+
| Alexander |
| Amritansh |
| Andre |
+------------+
3 rows in set (0.00 sec)
mysql>
I've tried installing a few JDBC results from looking through apt on Ubuntu, but it looks like I probably need to connect those up with BaseX so that they're picked up.
And, incidentally, I would presumably need to send a user and password to run the above query, specific to MySQL?
You need to install the appropriate JAR, and add it to your classpath.
Using packaged drivers:
sudo apt install libmariadb-java
Edit your mysql.xq file to load org.mariadb.jdbc.Driver instead of com.mysql.jdbc.Driver, and run basex with the following command:
JAVA_CLASSPATH=/usr/share/java/mariadb-java-client.jar basex
Authentication information can be provided in various ways, e.g. using parameters in the connection string, and/or information in the MariaDB/MySQL client configuration file.

How do you monitor MariaDB SSL expiration for both replication and client certificates?

There are a number of tools for monitoring SSL expiration for services available via HTTPS, e.g. we use https://github.com/prometheus/blackbox_exporter to receive alerts when SSL certificates expire in <14 days on both internal and external services.
We use Percona's XtraDB cluster (i.e. MariaDB) with SSL for both front-end and replication traffic. The relevant configuration is shown below:
$ less /etc/mysql/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]
pxc_encrypt_cluster_traffic=ON
ssl-ca=/etc/ssl/xtradb_server_ca.pem
ssl-cert=/etc/ssl/xtradb_server_cert.pem
ssl-key=/etc/ssl/xtradb_server_key.pem
[client]
ssl-ca=/etc/ssl/xtradb_server_ca.pem
ssl-cert=/etc/ssl/xtradb_server_cert.pem
ssl-key=/etc/ssl/xtradb_server_key.pem
What we have yet to figure out: How do you monitor the SSL expiration for certificates loaded by mysqld.service?
We use Ansible to deploy new certificates and perform rolling-restarts of mysqld.service on each host, however it would be great to monitor and confirm that these certificates are being properly updated.
Is there a common solution for this?
Currently there is no server variable or API function available to determine the validation period of a server certificate.
A simple workaround would be (assuming secure_file_priv is not set) :
$ mysql -e "SHOW VARIABLES LIKE 'ssl_cert'"
+---------------+----------------------------+
| Variable_name | Value |
+---------------+----------------------------+
| ssl_cert | /etc/mysql/server-cert.pem |
+---------------+----------------------------+
$ mysql -e "SELECT LOAD_FILE('/etc/mysql/server-cert.pem')\G" > server-cert.pem
$ openssl x509 -enddate -noout -in ./server-cert.pem
notAfter=Jan 22 10:11:10 2021 GMT
A solution was shared with me offline, see https://mariadb.com/kb/en/ssltls-status-variables/!
MariaDB has variables which display SSL expiration information:
mysql> show status like 'ssl_server_not%';
+-----------------------+--------------------------+
| Variable_name | Value |
+-----------------------+--------------------------+
| Ssl_server_not_after | May 24 11:46:23 2020 GMT |
| Ssl_server_not_before | Feb 24 11:46:23 2020 GMT |
+-----------------------+--------------------------+
2 rows in set (0.00 sec)
I'll update this solution once I've figured out how to either
Expose these as metrics via https://github.com/prometheus/mysqld_exporter (opened mysqld_exporter/issues/457)
Query for the variables via https://github.com/free/sql_exporter

Apache Drill Embedded installed, but not able to run query on windows

I've installed the latest version of Apache drill (embedded mode) on my own desktop Windows 7, following the instructions on their website : //drill.apache.org/docs/drill-in-10-minutes/. Launched the command line and typed sqlline.bat -u "jdbc:drill:zk=local" and looked like I've had drill up and running. Below are the results of the command prompt.
c:\apache-drill\bin>sqlline.bat -u "jdbc:drill:zk=local"
DRILL_ARGS - " -u jdbc:drill:zk=local"
HADOOP_HOME not detected...
HBASE_HOME not detected...
Calculating Drill classpath...
Oct 03, 2018 6:06:44 PM org.glassfish.jersey.server.ApplicationHandler
initialize
INFO: Initiating Jersey application, version Jersey: 2.8 2014-04-29
01:25:26...
apache drill 1.14.0
"got drill?"
0: jdbc:drill:zk=local>
But when I tried a simple query showing databases, it just returned dots. Tried some other simple queries like SELECT * FROM dfs.C:/drill/apache-drill-1.14.0/sample-data/region.parquet,also returned a line of dots.
c:\apache-drill\bin>sqlline.bat -u "jdbc:drill:zk=local"
DRILL_ARGS - " -u jdbc:drill:zk=local"
HADOOP_HOME not detected...
HBASE_HOME not detected...
Calculating Drill classpath...
Oct 03, 2018 6:06:44 PM org.glassfish.jersey.server.ApplicationHandler
initialize
INFO: Initiating Jersey application, version Jersey: 2.8 2014-04-29
01:25:26...
apache drill 1.14.0
"got drill?"
0: jdbc:drill:zk=local> show databases
. . . . . . . . . . . >
Also it didn't work when I tried to launch the web console. Can someone help me troubleshooting this? Many thanks!
Just specify semicolon in the end of line ;)
0: jdbc:drill:zk=local> show databases;
+---------------------+
| SCHEMA_NAME |
+---------------------+
| cp.default |
| dfs.default |
| dfs.root |
| dfs.tmp |
| information_schema |
| sys |
+---------------------+
6 rows selected (0.099 seconds)

Play Framework 2.3 - Can't connect to remote database Linux (Play) -> Win 7 (MySQL)

I have a Linux machine (on 10.0.0.10) which I deployed my Play app to using:
activator dist
I have a Windows machine (on 10.0.0.51) running MySQL.
The database has 3 user accounts set up root#localhost, db_user#localhost, db_user#% all users have all permissions (it's just for testing).
I can access the db from the Linux machine using the mysql shell:
[neil#localhost ~]$ mysql -u db_user -p -h 10.0.0.51
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test_db |
| mysql |
| performance_schema |
| sakila |
| test |
| world |
+--------------------+
8 rows in set (0.04 sec)
mysql>
Where test_db is the test database I set up on the Windows machine.
However when I try to run the Play application I get the following:
[neil#localhost ~]$ ~/TEST_APP-1.0-SNAPSHOT/bin/test_app
Play server process ID is 5908
[error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial
connection Sleeping for 0ms and trying again. Attempts left: 0.
Exception: java.net.ConnectException: Connection
refused.Message:Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database
[db_user]]
at play.api.Configuration$.play$api$Configuration$$configError
(Configuration.scala:94)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
...
Here is the db config in my application.conf:
db.db_user.driver=com.mysql.jdbc.Driver
db.db_user.url="jdbc:mysql://10.0.0.51:3306/test_db?allowMultiQueries=true"
db.db_user.user=db_user
db.db_user.pass="password"
db.db_user.partitionCount=3
db.db_user.maxConnectionsPerPartition=20
db.db_user.minConnectionsPerPartition=5
db.db_user.acquireIncrement=5
It is worth noting that this configuration works when I am running the app in dev mode on Windows. But I do not know what's wrong on the Linux box and I have run out of things to try. (note I tried this with all firewalls turned off and got the same issue).
UPDATE
Within the play application I use:
public static final String DB_USER = "db_user";
...
JdbcTemplate jt = new JdbcTemplate(DB.getDataSource(DB_USER));
So I shouldn't have to use db.default.etc... in the conf? Is this not correct?
UPDATE 2
I don't know how I missed this but there was something else further down in the stack trace that is indicative of the problem (the stack trace is quite long so I didn't want to list the whole thing, maybe I should have):
Caused by: java.net.ConnectException: Connection refused
So... the server is listening on port 3306, on the windows server running netstat -an yields:
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP [::]:3306 [::]:0 LISTENING
The firewall is turned off (I know... just for testing).
And MySQL is accepting connections from the CLI.
I've just had a brain wave though.... The application.conf was generated on windows... I wonder if I need to run dos2unix on the config file which would be why it cannot find "db_user".
UPDATE 3
No :(
You need to use db.default in conf.
from JavaDatabase
I think the correct key to specify the password is not pass, but password:
db.db_user.password="password"
Also you can try to use db.default.* and DB.getDataSource(), but I guess that will not make much difference...