user | String | **Optional.** PostgreSQL database user with read/write permission to the icinga database. Defaults to `icinga`.
password | String | **Optional.** PostgreSQL database user's password. Defaults to `icinga`.
database | String | **Optional.** PostgreSQL database name. Defaults to `icinga`.
+ ssl\_mode | String | **Optional.** Enable SSL connection mode. Value must be set according to the [sslmode setting](https://www.postgresql.org/docs/9.3/static/libpq-connect.html#LIBPQ-CONNSTRING): `prefer`, `require`, `verify-ca`, `verify-full`, `allow`, `disable`.
+ ssl\_key | String | **Optional.** PostgreSQL SSL client key file path.
+ ssl\_cert | String | **Optional.** PostgreSQL SSL certificate file path.
+ ssl\_ca | String | **Optional.** PostgreSQL SSL certificate authority certificate file path.
table\_prefix | String | **Optional.** PostgreSQL database table prefix. Defaults to `icinga_`.
instance\_name | String | **Optional.** Unique identifier for the local Icinga 2 instance. Defaults to `default`.
instance\_description | String | **Optional.** Description for the Icinga 2 instance.
ClearIDCache();
- String ihost, iport, iuser, ipasswd, idb;
- const char *host, *port, *user , *passwd, *db;
-
- ihost = GetHost();
- iport = GetPort();
- iuser = GetUser();
- ipasswd = GetPassword();
- idb = GetDatabase();
-
- host = (!ihost.IsEmpty()) ? ihost.CStr() : nullptr;
- port = (!iport.IsEmpty()) ? iport.CStr() : nullptr;
- user = (!iuser.IsEmpty()) ? iuser.CStr() : nullptr;
- passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : nullptr;
- db = (!idb.IsEmpty()) ? idb.CStr() : nullptr;
-
- m_Connection = m_Pgsql->setdbLogin(host, port, nullptr, nullptr, db, user, passwd);
+ String host = GetHost();
+ String port = GetPort();
+ String user = GetUser();
+ String password = GetPassword();
+ String database = GetDatabase();
+
+ String sslMode = GetSslMode();
+ String sslKey = GetSslKey();
+ String sslCert = GetSslCert();
+ String sslCa = GetSslCa();
+
+ String conninfo;
+
+ if (!host.IsEmpty())
+ conninfo += " host=" + host;
+ if (!port.IsEmpty())
+ conninfo += " port=" + port;
+ if (!user.IsEmpty())
+ conninfo += " user=" + user;
+ if (!password.IsEmpty())
+ conninfo += " password=" + password;
+ if (!database.IsEmpty())
+ conninfo += " dbname=" + database;
+
+ if (!sslMode.IsEmpty())
+ conninfo += " sslmode=" + sslMode;
+ if (!sslKey.IsEmpty())
+ conninfo += " sslkey=" + sslKey;
+ if (!sslCert.IsEmpty())
+ conninfo += " sslcert=" + sslCert;
+ if (!sslCa.IsEmpty())
+ conninfo += " sslrootcert=" + sslCa;
+
+ /* connection */
+ m_Connection = m_Pgsql->connectdb(conninfo.CStr());
if (!m_Connection)
return;
SetConnected(false);
Log(LogCritical, "IdoPgsqlConnection")
- << "Connection to database '" << db << "' with user '" << user << "' on '" << host << ":" << port
+ << "Connection to database '" << database << "' with user '" << user << "' on '" << host << ":" << port
<< "' failed: \"" << message << "\"";
BOOST_THROW_EXCEPTION(std::runtime_error(message));
}
Log(LogInformation, "IdoPgsqlConnection")
- << "pgSQL IDO instance id: " << static_cast<long>(m_InstanceID) << " (schema version: '" + version + "')";
+ << "PGSQL IDO instance id: " << static_cast<long>(m_InstanceID) << " (schema version: '" + version + "')"
+ << (!sslMode.IsEmpty() ? ", sslmode='" + sslMode + "'" : "");
Query("BEGIN");