Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync rule fails if host already exists with different capitalisation #2419

Closed
Linuxfabrik opened this issue Oct 28, 2021 · 1 comment
Closed

Comments

@Linuxfabrik
Copy link

Expected Behavior

We have a sync rule with update policy ignore. The corresponding import source provides a server with name test-server.
However, a server called Test-Server already exists in the director. Therefore, the new host test-server should be ignored.

Current Behavior

The following error occurs:

This Sync Rule failed when last checked at 2021-10-27 16:35:40: Exception while syncing Icinga\Module\Director\Objects\IcingaHost test-server: Trying to recreate icinga_host ("test-server")

This is because during the preparation for the import (as seen during "check for changes"), the matching is done with case sensitivity, therefore 'test-server' != 'Test-Server' (see

if (array_key_exists($key, $this->objects)) {
).

So the director tries to create a new host with name test-server, however this fails here:

$this->db->select()->from($this->table)->where($this->createWhere())

This checks against the db with a SQL statement, which is case insensitive (assuming utf8_general_ci, according to the installation guide).

Possible Solution

The check during the preparation phase should be the same as the check during the creation phase.

Steps to Reproduce (for bugs)

cd /usr/share/icingaweb2/modules
git clone https://github.com/Icinga/icingaweb2-module-fileshipper.git fileshipper
icingacli module enable fileshipper

mkdir /etc/icingaweb2/modules/fileshipper/
cat > /etc/icingaweb2/modules/fileshipper/imports.ini << 'EOF'
[fileshipper-test]
basedir = "/var/lib/icingaweb2/fileshipper-test/"
EOF
chown -R apache:icingaweb2 /etc/icingaweb2/modules/fileshipper/

mkdir /var/lib/icingaweb2/fileshipper-test
cat > /var/lib/icingaweb2/fileshipper-test/hosts.json << 'EOF'
{
  "json1.example.com": {
    "host": "json1.example.com",
    "address": "127.0.0.1",
    "location": "HQ",
    "groups": [ "Linux Servers" ]
  },
  "json2.example.com": {
    "host": "json2.example.com",
    "address": "127.0.0.2",
    "location": "HQ",
    "groups": [ "Windows Servers", "Lab" ]
  },
  "test-server": {
    "host": "test-server",
    "address": "127.0.0.3",
    "location": "HQ",
    "groups": [ "Windows Servers", "Lab" ]
  }
}
EOF

In the director:

  • add a dummy host with hostname Test-Server.

  • add import source:

    • source type: import from files
    • key column name: host
    • file format: json
    • base directory: fileshipper-test
    • file name: hosts.json
  • trigger import run

  • add sync rule:

    • object type: host

    • update policy: ignore

    • purge: no

    • properties:

      • host -> object_name
      • address -> address
  • trigger this sync

Your Environment

  • Director version (System - About): 1.8.1
  • Icinga Web 2 version and modules (System - About): 2.9.3
  • Icinga 2 version (icinga2 --version): 2.13.1-1
  • Operating System and version: CentOS Linux release 7.9.2009 (Core)
  • Webserver, PHP versions: Apache/2.4.6, PHP 7.3.29
  • MariaDB: Ver 10.5.12
SELECT @@character_set_database, @@collation_database;
'utf8', 'utf8_general_ci'
@Thomas-Gelf
Copy link
Contributor

Will finally be fixed with #2598

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant