Zabbix 3.4が本当にphp-mysqlに依存していない事を確認してみた

CentOS上においてはphp-mysqlに依存してしまうzabbix-web-mysqlですが、実際の所は利用していないので何らかの方法で無視をする(※1)事で導入が出来ます。ただ、本当に依存していないのだろうか、という事を念のため確認してみました。

Zabbix WebフロントエンドはPHPで書かれているOSS(※2)なので、既に導入済みの環境であれば適当なエディタで開いて中身を確認する事が出来ます。公式サイトからソースをDLする事も出来ます。

まずはどこでDB関連の判断をしているのか。ファイル名の雰囲気から以下で設定ファイルを読み込んでいるものと思わます。

/usr/share/zabbix/include/classes/core/CConfigFile.php

         if (!isset($DB['TYPE'])) {
             self::exception('DB type is not set.');
         }

         if (!array_key_exists($DB['TYPE'], self::$supported_db_types)) {
             self::exception(
                 'Incorrect value "'.$DB['TYPE'].'" for DB type. Possible values '.
                 implode(', ', array_keys(self::$supported_db_types)).'.'
             );
         }

         $php_supported_db = array_keys(CFrontendSetup::getSupportedDatabases());

         if (!in_array($DB['TYPE'], $php_supported_db)) {
             self::exception('DB type "'.$DB['TYPE'].'" is not supported by current setup.'.
                 ($php_supported_db ? ' Possible values '.implode(', ', $php_supported_db).'.' : '')
             );
         }

設定ファイルで定義したDBのTYPEがCFrontendSetup::getSupportedDatabases()に含まれているかをチェックしていますね。ではそのCFrontendSetup::getSupportedDatabases()を確認します。

/usr/share/zabbix/include/classes/setup/CFrontendSetup.php

     /**
      * Get list of supported databases.
      *
      * @return array
      */
     public static function getSupportedDatabases() {
         $allowed_db = [];

         if (zbx_is_callable(['mysqli_close', 'mysqli_connect', 'mysqli_connect_error', 'mysqli_error',
                 'mysqli_fetch_assoc', 'mysqli_free_result', 'mysqli_query', 'mysqli_real_escape_string'])) {
             $allowed_db[ZBX_DB_MYSQL] = 'MySQL';
         }

         if (zbx_is_callable(['pg_close', 'pg_connect', 'pg_escape_bytea', 'pg_escape_string', 'pg_fetch_assoc',
                 'pg_free_result', 'pg_last_error', 'pg_parameter_status', 'pg_query', 'pg_unescape_bytea'])) {
             $allowed_db[ZBX_DB_POSTGRESQL] = 'PostgreSQL';
         }

         if (zbx_is_callable(['oci_bind_by_name', 'oci_close', 'oci_commit', 'oci_connect', 'oci_error', 'oci_execute',
                 'oci_fetch_assoc', 'oci_field_type', 'oci_free_statement', 'oci_new_descriptor', 'oci_parse',
                 'oci_rollback'])) {
             $allowed_db[ZBX_DB_ORACLE] = 'Oracle';
         }

         if (zbx_is_callable(['db2_autocommit', 'db2_bind_param', 'db2_close', 'db2_commit', 'db2_conn_errormsg',
                 'db2_connect', 'db2_escape_string', 'db2_execute', 'db2_fetch_assoc', 'db2_free_result', 'db2_prepare',
                 'db2_rollback', 'db2_set_option', 'db2_stmt_errormsg'])) {
            $allowed_db[ZBX_DB_DB2] = 'IBM DB2';
         }

         return $allowed_db;
     }

/usr/share/zabbix/include/func.inc.php

function zbx_is_callable(array $names) {
	foreach ($names as $name) {
		if (!is_callable($name)) {
			return false;
		}
	}

	return true;
}

mysqli_*コマンドが存在するかで確認しています。この事からZabbix 3.4ではMySQL = mysqli_* の利用となっており、旧来のmysql_*は利用していない事が分かります。ちなみにPDOは利用してないようです。

以下はもっとシンプルに接続関数 mysqli_connect と mysql_connect をgrepで探してみた結果です。

# find /usr/share/zabbix/ -type f -print | xargs grep mysql_co
→結果無し

# find /usr/share/zabbix/ -type f -print | xargs grep mysqli_co
/usr/share/zabbix/include/classes/setup/CFrontendSetup.php:             if (zbx_is_callable(['mysqli_close', 'mysqli_connect', 'mysqli_connect_error', 'mysqli_error',
/usr/share/zabbix/include/db.inc.php:                           $DB['DB'] = @mysqli_connect($DB['SERVER'], $DB['USER'], $DB['PASSWORD'], $DB['DATABASE'], $DB['PORT']);
/usr/share/zabbix/include/db.inc.php:                                   $error = 'Error connecting to database: '.trim(mysqli_connect_error());

mysql_connectの呼び出しが物理的に存在しない事が分かります。心置きなくphp-mysqlを葬り去れますね。

※1: 既に運用中のCentOS 7.x上のZabbix(Webフロントエンド)のPHPを5系から7系に入れ替える

※2:

/*
** Zabbix
** Copyright (C) 2001-2018 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/

Share this…