Skip to content

New custom property support#2972

Draft
raviks789 wants to merge 14 commits intomasterfrom
dictionary-support
Draft

New custom property support#2972
raviks789 wants to merge 14 commits intomasterfrom
dictionary-support

Conversation

@raviks789
Copy link
Copy Markdown
Collaborator

@raviks789 raviks789 commented Apr 1, 2025

Requires:
Icinga/ipl-web#355

@cla-bot cla-bot Bot added the cla/signed label Apr 1, 2025
@raviks789 raviks789 force-pushed the dictionary-support branch 9 times, most recently from dd916d4 to f19501d Compare April 2, 2025 10:43
@raviks789 raviks789 force-pushed the dictionary-support branch 2 times, most recently from 2ddc75b to 3583514 Compare April 11, 2025 15:55
@raviks789 raviks789 force-pushed the dictionary-support branch 10 times, most recently from e818e3e to 3260c35 Compare May 14, 2025 15:29
@raviks789 raviks789 force-pushed the dictionary-support branch 8 times, most recently from 01bbc41 to e1fac6d Compare May 27, 2025 11:27
@raviks789 raviks789 force-pushed the dictionary-support branch 4 times, most recently from 6493a77 to 0807528 Compare September 26, 2025 08:53
@raviks789 raviks789 force-pushed the dictionary-support branch 5 times, most recently from afa36bc to 57bf362 Compare October 10, 2025 12:14
@raviks789 raviks789 force-pushed the dictionary-support branch 2 times, most recently from 4c6962e to 7aba001 Compare March 11, 2026 15:11
@nilmerg
Copy link
Copy Markdown
Member

nilmerg commented Apr 16, 2026

Unfortunately, I had to revert automatic form element escaping in ipl-html: Icinga/ipl-html#196

So you have to protect against invalid form element names here on your own. A viable and easy alternative might be hashing the names using md5.

@raviks789
Copy link
Copy Markdown
Collaborator Author

raviks789 commented Apr 17, 2026

Unfortunately, I had to revert automatic form element escaping in ipl-html: Icinga/ipl-html#196

So you have to protect against invalid form element names here on your own. A viable and easy alternative might be hashing the names using md5.

Thanks for the info! However, the implementation has changed since then and custom variable names are no longer used as form element names. Hence, reverting those changes will not affect this PR.

raviks789 and others added 13 commits April 27, 2026 11:33
Introduce a first-class DirectorProperty concept that extends the existing
data-fields model with rich, structured variable types. Custom variables can
now be defined globally under a new "Custom Variables" section and assigned
to Icinga objects (hosts, services, commands, etc.).

Supported types: string, number, boolean, fixed-array, dynamic-array,
datalist-strict, datalist-non-strict, fixed-dictionary, and
dynamic-dictionary (one level of nesting allowed).

Key changes:
  - DirectorProperty object with CRUD, inheritance, and apply-for rule support
  - New form elements: Dictionary, DictionaryItem, NestedDictionary,
    NestedDictionaryItem, ArrayElement, IplBoolean
  - CustomvarController for managing global property definitions
  - VariablesController for per-object variable assignment
  - BasketSnapshotCustomVariableResolver for basket import/export of properties
  - REST API: IcingaObjectHandler extended to expose and accept structured vars
  - IcingaConfigHelper: renders dictionaries/arrays to valid Icinga 2 DSL
  - CustomVarRenderer updated for icingadb hook display
  - DB migration upgrade_192.sql: new director_property and related tables
  - CLI: MigrateCommand for migrating legacy vars to properties;
    HostsCommand for bulk host custom variable management
Constraints follow the pattern `<table>_<column>`.
Copy link
Copy Markdown
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test

Director with autodiscovery

(I guess this is my next blogpost topic...)

  1. Install Fedora 42
  2. Apply https://github.com/Al2Klimov/ansible-icinga-fedora
  3. dnf install nmap
  4. git clone https://github.com/Thomas-Gelf/icingaweb2-module-nmap.git /usr/share/icingaweb2/modules/nmap
  5. icingacli mod en nmap
  6. Add nmap import source and a job for it to run regularly
  7. Add sync rule and a job for it to run regularly
  8. Add service apply rule
  9. Deploy once you got new hosts

nmap import source

  • Key column: host
  • Subnet: 10.27.0.0/16

Modifier

  • Property: host
  • Modifier: Skip row if...

Sync rule

  • Type: Host
  • Update: merge
  • Purge: no

Sync property

  • Source: nmap
  • Field: address
  • Source: ip

Sync property

  • Source: nmap
  • Field: check_command
  • Source: custom
  • Expression: ping

Jobs

  • Run import: yes
  • Apply changes: yes

Service apply rule

You must add a service template first. #3068

  • Check command: ssh
  • Assign where: host.address is set

Add existing data fields

https://github.com/Thomas-Gelf/icingaweb2-module-nmap doesn't import open ports, so latter are the perfect use case.

  1. Start nmap -T5 10.27.0.0/16
  2. Add array data field
  3. Add host template
  4. Add data field to host template as optional
  5. Add property to your sync rule
  6. Add service apply rule
  7. Once nmap(1) is done, add open ports to individual hosts
  8. Deploy

Sync property

  • Source: nmap
  • Field: import
  • Source: your template

Service apply rule

You must add a service template first. #3068

That template must also provide a data field tcp_port.
See also https://icinga.com/docs/icinga-director/latest/doc/15-Service-apply-for-example/

  • Apply for: your data field (Edit: #3072 🙈)
  • Check command: tcp
  • Assign where: your data field is set (#3069)
  • Custom property "TCP port": $config$

Migrate

=> #2972

  1. mysqldump director > director.sql Just to be sure. :-)
  2. Downgrade to https://git.icinga.com/packages/icinga-director/-/jobs/887605
  3. Apply DB migration (Director overview page)
  4. icingacli director migrate datafields --dry-run --verbose

Result:

ERROR: Zend_Db_Statement_Exception in /usr/share/icinga-php/vendor/vendor/icinga/zf1/library/Zend/Db/Statement/Pdo.php:235 with message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ) GROUP BY varname' at line 1, query was: SELECT dd.id, dd.varname, dd.caption, dd.description, dd.datatype, dd.category_id, COUNT(varname) AS count FROM director_datafield AS dd WHERE ( NOT (()) ) GROUP BY varname

This is bad.

@raviks789
Copy link
Copy Markdown
Collaborator Author

raviks789 commented May 5, 2026

Result:

ERROR: Zend_Db_Statement_Exception in /usr/share/icinga-php/vendor/vendor/icinga/zf1/library/Zend/Db/Statement/Pdo.php:235 with message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) ) GROUP BY varname' at line 1, query was: SELECT dd.id, dd.varname, dd.caption, dd.description, dd.datatype, dd.category_id, COUNT(varname) AS count FROM director_datafield AS dd WHERE ( NOT (()) ) GROUP BY varname

This is bad.

Good catch. Should be resolved now :)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants